summaryrefslogtreecommitdiff
path: root/utils/tomcrypt/src/misc
diff options
context:
space:
mode:
Diffstat (limited to 'utils/tomcrypt/src/misc')
-rw-r--r--utils/tomcrypt/src/misc/compare_testvector.c87
-rw-r--r--utils/tomcrypt/src/misc/crypt/crypt_argchk.c27
-rw-r--r--utils/tomcrypt/src/misc/crypt/crypt_cipher_descriptor.c25
-rw-r--r--utils/tomcrypt/src/misc/crypt/crypt_cipher_is_valid.c34
-rw-r--r--utils/tomcrypt/src/misc/crypt/crypt_register_cipher.c52
-rw-r--r--utils/tomcrypt/src/misc/zeromem.c32
6 files changed, 257 insertions, 0 deletions
diff --git a/utils/tomcrypt/src/misc/compare_testvector.c b/utils/tomcrypt/src/misc/compare_testvector.c
new file mode 100644
index 0000000000..67fe1c1f9a
--- /dev/null
+++ b/utils/tomcrypt/src/misc/compare_testvector.c
@@ -0,0 +1,87 @@
1/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 */
9
10#include "tomcrypt.h"
11
12/**
13 @file compare_testvector.c
14 Function to compare two testvectors and print a (detailed) error-message if required, Steffen Jaeckel
15*/
16
17#if defined(LTC_TEST) && defined(LTC_TEST_DBG)
18static void _print_hex(const char* what, const void* v, const unsigned long l)
19{
20 const unsigned char* p = v;
21 unsigned long x, y = 0, z;
22 fprintf(stderr, "%s contents: \n", what);
23 for (x = 0; x < l; ) {
24 fprintf(stderr, "%02X ", p[x]);
25 if (!(++x % 16) || x == l) {
26 if((x % 16) != 0) {
27 z = 16 - (x % 16);
28 if(z >= 8)
29 fprintf(stderr, " ");
30 for (; z != 0; --z) {
31 fprintf(stderr, " ");
32 }
33 }
34 fprintf(stderr, " | ");
35 for(; y < x; y++) {
36 if((y % 8) == 0)
37 fprintf(stderr, " ");
38 if(isgraph(p[y]))
39 fprintf(stderr, "%c", p[y]);
40 else
41 fprintf(stderr, ".");
42 }
43 fprintf(stderr, "\n");
44 }
45 else if((x % 8) == 0) {
46 fprintf(stderr, " ");
47 }
48 }
49}
50#endif
51
52/**
53 Compare two test-vectors
54
55 @param is The data as it is
56 @param is_len The length of is
57 @param should The data as it should
58 @param should_len The length of should
59 @param what The type of the data
60 @param which The iteration count
61 @return 0 on equality, -1 or 1 on difference
62*/
63int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which)
64{
65 int res = 0;
66 if(is_len != should_len)
67 res = is_len > should_len ? -1 : 1;
68 else
69 res = XMEMCMP(is, should, is_len);
70
71#if defined(LTC_TEST) && defined(LTC_TEST_DBG)
72 if (res != 0) {
73 fprintf(stderr, "Testvector #%i of %s failed:\n", which, what);
74 _print_hex("SHOULD", should, should_len);
75 _print_hex("IS ", is, is_len);
76 }
77#else
78 LTC_UNUSED_PARAM(which);
79 LTC_UNUSED_PARAM(what);
80#endif
81
82 return res;
83}
84
85/* ref: HEAD -> master, tag: v1.18.2 */
86/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
87/* commit time: 2018-07-01 22:49:01 +0200 */
diff --git a/utils/tomcrypt/src/misc/crypt/crypt_argchk.c b/utils/tomcrypt/src/misc/crypt/crypt_argchk.c
new file mode 100644
index 0000000000..a93962420e
--- /dev/null
+++ b/utils/tomcrypt/src/misc/crypt/crypt_argchk.c
@@ -0,0 +1,27 @@
1/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 */
9#include "tomcrypt.h"
10
11/**
12 @file crypt_argchk.c
13 Perform argument checking, Tom St Denis
14*/
15
16#if (ARGTYPE == 0)
17void crypt_argchk(const char *v, const char *s, int d)
18{
19 fprintf(stderr, "LTC_ARGCHK '%s' failure on line %d of file %s\n",
20 v, d, s);
21 abort();
22}
23#endif
24
25/* ref: HEAD -> master, tag: v1.18.2 */
26/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
27/* commit time: 2018-07-01 22:49:01 +0200 */
diff --git a/utils/tomcrypt/src/misc/crypt/crypt_cipher_descriptor.c b/utils/tomcrypt/src/misc/crypt/crypt_cipher_descriptor.c
new file mode 100644
index 0000000000..a9de9d6785
--- /dev/null
+++ b/utils/tomcrypt/src/misc/crypt/crypt_cipher_descriptor.c
@@ -0,0 +1,25 @@
1/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 */
9#include "tomcrypt.h"
10
11/**
12 @file crypt_cipher_descriptor.c
13 Stores the cipher descriptor table, Tom St Denis
14*/
15
16struct ltc_cipher_descriptor cipher_descriptor[TAB_SIZE] = {
17{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
18 };
19
20LTC_MUTEX_GLOBAL(ltc_cipher_mutex)
21
22
23/* ref: HEAD -> master, tag: v1.18.2 */
24/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
25/* commit time: 2018-07-01 22:49:01 +0200 */
diff --git a/utils/tomcrypt/src/misc/crypt/crypt_cipher_is_valid.c b/utils/tomcrypt/src/misc/crypt/crypt_cipher_is_valid.c
new file mode 100644
index 0000000000..2ba32bf5e8
--- /dev/null
+++ b/utils/tomcrypt/src/misc/crypt/crypt_cipher_is_valid.c
@@ -0,0 +1,34 @@
1/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 */
9#include "tomcrypt.h"
10
11/**
12 @file crypt_cipher_is_valid.c
13 Determine if cipher is valid, Tom St Denis
14*/
15
16/*
17 Test if a cipher index is valid
18 @param idx The index of the cipher to search for
19 @return CRYPT_OK if valid
20*/
21int cipher_is_valid(int idx)
22{
23 LTC_MUTEX_LOCK(&ltc_cipher_mutex);
24 if (idx < 0 || idx >= TAB_SIZE || cipher_descriptor[idx].name == NULL) {
25 LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
26 return CRYPT_INVALID_CIPHER;
27 }
28 LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
29 return CRYPT_OK;
30}
31
32/* ref: HEAD -> master, tag: v1.18.2 */
33/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
34/* commit time: 2018-07-01 22:49:01 +0200 */
diff --git a/utils/tomcrypt/src/misc/crypt/crypt_register_cipher.c b/utils/tomcrypt/src/misc/crypt/crypt_register_cipher.c
new file mode 100644
index 0000000000..59fc042d89
--- /dev/null
+++ b/utils/tomcrypt/src/misc/crypt/crypt_register_cipher.c
@@ -0,0 +1,52 @@
1/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 */
9#include "tomcrypt.h"
10
11/**
12 @file crypt_register_cipher.c
13 Register a cipher, Tom St Denis
14*/
15
16/**
17 Register a cipher with the descriptor table
18 @param cipher The cipher you wish to register
19 @return value >= 0 if successfully added (or already present), -1 if unsuccessful
20*/
21int register_cipher(const struct ltc_cipher_descriptor *cipher)
22{
23 int x;
24
25 LTC_ARGCHK(cipher != NULL);
26
27 /* is it already registered? */
28 LTC_MUTEX_LOCK(&ltc_cipher_mutex);
29 for (x = 0; x < TAB_SIZE; x++) {
30 if (cipher_descriptor[x].name != NULL && cipher_descriptor[x].ID == cipher->ID) {
31 LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
32 return x;
33 }
34 }
35
36 /* find a blank spot */
37 for (x = 0; x < TAB_SIZE; x++) {
38 if (cipher_descriptor[x].name == NULL) {
39 XMEMCPY(&cipher_descriptor[x], cipher, sizeof(struct ltc_cipher_descriptor));
40 LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
41 return x;
42 }
43 }
44
45 /* no spot */
46 LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
47 return -1;
48}
49
50/* ref: HEAD -> master, tag: v1.18.2 */
51/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
52/* commit time: 2018-07-01 22:49:01 +0200 */
diff --git a/utils/tomcrypt/src/misc/zeromem.c b/utils/tomcrypt/src/misc/zeromem.c
new file mode 100644
index 0000000000..dc81d9b1e2
--- /dev/null
+++ b/utils/tomcrypt/src/misc/zeromem.c
@@ -0,0 +1,32 @@
1/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 */
9#include "tomcrypt.h"
10
11/**
12 @file zeromem.c
13 Zero a block of memory, Tom St Denis
14*/
15
16/**
17 Zero a block of memory
18 @param out The destination of the area to zero
19 @param outlen The length of the area to zero (octets)
20*/
21void zeromem(volatile void *out, size_t outlen)
22{
23 volatile char *mem = out;
24 LTC_ARGCHKVD(out != NULL);
25 while (outlen-- > 0) {
26 *mem++ = '\0';
27 }
28}
29
30/* ref: HEAD -> master, tag: v1.18.2 */
31/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
32/* commit time: 2018-07-01 22:49:01 +0200 */