diff options
author | jsing <> | 2014-05-15 14:14:56 +0000 |
---|---|---|
committer | jsing <> | 2014-05-15 14:14:56 +0000 |
commit | b115738274236129c97a787d577da5cbff4c828e (patch) | |
tree | d1545fae6b44d7a9d7d6aa80a89b700911a313f3 /src/regress | |
parent | 331e9a2412038c63b968d43c57141df1425f9d43 (diff) | |
download | openbsd-b115738274236129c97a787d577da5cbff4c828e.tar.gz openbsd-b115738274236129c97a787d577da5cbff4c828e.tar.bz2 openbsd-b115738274236129c97a787d577da5cbff4c828e.zip |
KNF.
Diffstat (limited to 'src/regress')
-rw-r--r-- | src/regress/lib/libcrypto/aead/aeadtest.c | 13 | ||||
-rw-r--r-- | src/regress/lib/libcrypto/poly1305/poly1305test.c | 84 |
2 files changed, 50 insertions, 47 deletions
diff --git a/src/regress/lib/libcrypto/aead/aeadtest.c b/src/regress/lib/libcrypto/aead/aeadtest.c index e74b9fca97..4d96ed6de4 100644 --- a/src/regress/lib/libcrypto/aead/aeadtest.c +++ b/src/regress/lib/libcrypto/aead/aeadtest.c | |||
@@ -99,7 +99,8 @@ static const char NAMES[NUM_TYPES][6] = { | |||
99 | }; | 99 | }; |
100 | 100 | ||
101 | static unsigned char | 101 | static unsigned char |
102 | hex_digit(char h) { | 102 | hex_digit(char h) |
103 | { | ||
103 | if (h >= '0' && h <= '9') | 104 | if (h >= '0' && h <= '9') |
104 | return h - '0'; | 105 | return h - '0'; |
105 | else if (h >= 'a' && h <= 'f') | 106 | else if (h >= 'a' && h <= 'f') |
@@ -144,7 +145,7 @@ run_test_case(const EVP_AEAD* aead, unsigned char bufs[NUM_TYPES][BUF_MAX], | |||
144 | EVP_AEAD_CTX ctx; | 145 | EVP_AEAD_CTX ctx; |
145 | ssize_t n; | 146 | ssize_t n; |
146 | size_t un; | 147 | size_t un; |
147 | unsigned char out[BUF_MAX+EVP_AEAD_MAX_TAG_LENGTH], out2[BUF_MAX]; | 148 | unsigned char out[BUF_MAX + EVP_AEAD_MAX_TAG_LENGTH], out2[BUF_MAX]; |
148 | 149 | ||
149 | if (!EVP_AEAD_CTX_init(&ctx, aead, bufs[KEY], lengths[KEY], | 150 | if (!EVP_AEAD_CTX_init(&ctx, aead, bufs[KEY], lengths[KEY], |
150 | lengths[TAG], NULL)) { | 151 | lengths[TAG], NULL)) { |
@@ -164,8 +165,8 @@ run_test_case(const EVP_AEAD* aead, unsigned char bufs[NUM_TYPES][BUF_MAX], | |||
164 | 165 | ||
165 | if (un != lengths[CT] + lengths[TAG]) { | 166 | if (un != lengths[CT] + lengths[TAG]) { |
166 | fprintf(stderr, "Bad output length on line %u: %u vs %u\n", | 167 | fprintf(stderr, "Bad output length on line %u: %u vs %u\n", |
167 | line_no, (unsigned) un, | 168 | line_no, (unsigned) un, |
168 | (unsigned)(lengths[CT] + lengths[TAG])); | 169 | (unsigned)(lengths[CT] + lengths[TAG])); |
169 | return 0; | 170 | return 0; |
170 | } | 171 | } |
171 | 172 | ||
@@ -188,7 +189,7 @@ run_test_case(const EVP_AEAD* aead, unsigned char bufs[NUM_TYPES][BUF_MAX], | |||
188 | 189 | ||
189 | if ((size_t)n != lengths[IN]) { | 190 | if ((size_t)n != lengths[IN]) { |
190 | fprintf(stderr, "Bad decrypt on line %u: %u\n", line_no, | 191 | fprintf(stderr, "Bad decrypt on line %u: %u\n", line_no, |
191 | (unsigned) n); | 192 | (unsigned) n); |
192 | return 0; | 193 | return 0; |
193 | } | 194 | } |
194 | 195 | ||
@@ -263,7 +264,7 @@ main(int argc, char **argv) | |||
263 | fprintf(stderr, "Aborting...\n"); | 264 | fprintf(stderr, "Aborting...\n"); |
264 | return 4; | 265 | return 4; |
265 | } | 266 | } |
266 | 267 | ||
267 | if (!run_test_case(aead, bufs, lengths, line_no)) | 268 | if (!run_test_case(aead, bufs, lengths, line_no)) |
268 | return 4; | 269 | return 4; |
269 | 270 | ||
diff --git a/src/regress/lib/libcrypto/poly1305/poly1305test.c b/src/regress/lib/libcrypto/poly1305/poly1305test.c index 96b34c0218..91e296e39f 100644 --- a/src/regress/lib/libcrypto/poly1305/poly1305test.c +++ b/src/regress/lib/libcrypto/poly1305/poly1305test.c | |||
@@ -16,7 +16,7 @@ int poly1305_power_on_self_test(void); | |||
16 | 16 | ||
17 | void | 17 | void |
18 | poly1305_auth(unsigned char mac[16], const unsigned char *m, size_t bytes, | 18 | poly1305_auth(unsigned char mac[16], const unsigned char *m, size_t bytes, |
19 | const unsigned char key[32]) { | 19 | const unsigned char key[32]) { |
20 | poly1305_context ctx; | 20 | poly1305_context ctx; |
21 | CRYPTO_poly1305_init(&ctx, key); | 21 | CRYPTO_poly1305_init(&ctx, key); |
22 | CRYPTO_poly1305_update(&ctx, m, bytes); | 22 | CRYPTO_poly1305_update(&ctx, m, bytes); |
@@ -24,7 +24,8 @@ poly1305_auth(unsigned char mac[16], const unsigned char *m, size_t bytes, | |||
24 | } | 24 | } |
25 | 25 | ||
26 | int | 26 | int |
27 | poly1305_verify(const unsigned char mac1[16], const unsigned char mac2[16]) { | 27 | poly1305_verify(const unsigned char mac1[16], const unsigned char mac2[16]) |
28 | { | ||
28 | size_t i; | 29 | size_t i; |
29 | unsigned int dif = 0; | 30 | unsigned int dif = 0; |
30 | for (i = 0; i < 16; i++) | 31 | for (i = 0; i < 16; i++) |
@@ -35,56 +36,57 @@ poly1305_verify(const unsigned char mac1[16], const unsigned char mac2[16]) { | |||
35 | 36 | ||
36 | /* test a few basic operations */ | 37 | /* test a few basic operations */ |
37 | int | 38 | int |
38 | poly1305_power_on_self_test(void) { | 39 | poly1305_power_on_self_test(void) |
40 | { | ||
39 | /* example from nacl */ | 41 | /* example from nacl */ |
40 | static const unsigned char nacl_key[32] = { | 42 | static const unsigned char nacl_key[32] = { |
41 | 0xee,0xa6,0xa7,0x25,0x1c,0x1e,0x72,0x91, | 43 | 0xee, 0xa6, 0xa7, 0x25, 0x1c, 0x1e, 0x72, 0x91, |
42 | 0x6d,0x11,0xc2,0xcb,0x21,0x4d,0x3c,0x25, | 44 | 0x6d, 0x11, 0xc2, 0xcb, 0x21, 0x4d, 0x3c, 0x25, |
43 | 0x25,0x39,0x12,0x1d,0x8e,0x23,0x4e,0x65, | 45 | 0x25, 0x39, 0x12, 0x1d, 0x8e, 0x23, 0x4e, 0x65, |
44 | 0x2d,0x65,0x1f,0xa4,0xc8,0xcf,0xf8,0x80, | 46 | 0x2d, 0x65, 0x1f, 0xa4, 0xc8, 0xcf, 0xf8, 0x80, |
45 | }; | 47 | }; |
46 | 48 | ||
47 | static const unsigned char nacl_msg[131] = { | 49 | static const unsigned char nacl_msg[131] = { |
48 | 0x8e,0x99,0x3b,0x9f,0x48,0x68,0x12,0x73, | 50 | 0x8e, 0x99, 0x3b, 0x9f, 0x48, 0x68, 0x12, 0x73, |
49 | 0xc2,0x96,0x50,0xba,0x32,0xfc,0x76,0xce, | 51 | 0xc2, 0x96, 0x50, 0xba, 0x32, 0xfc, 0x76, 0xce, |
50 | 0x48,0x33,0x2e,0xa7,0x16,0x4d,0x96,0xa4, | 52 | 0x48, 0x33, 0x2e, 0xa7, 0x16, 0x4d, 0x96, 0xa4, |
51 | 0x47,0x6f,0xb8,0xc5,0x31,0xa1,0x18,0x6a, | 53 | 0x47, 0x6f, 0xb8, 0xc5, 0x31, 0xa1, 0x18, 0x6a, |
52 | 0xc0,0xdf,0xc1,0x7c,0x98,0xdc,0xe8,0x7b, | 54 | 0xc0, 0xdf, 0xc1, 0x7c, 0x98, 0xdc, 0xe8, 0x7b, |
53 | 0x4d,0xa7,0xf0,0x11,0xec,0x48,0xc9,0x72, | 55 | 0x4d, 0xa7, 0xf0, 0x11, 0xec, 0x48, 0xc9, 0x72, |
54 | 0x71,0xd2,0xc2,0x0f,0x9b,0x92,0x8f,0xe2, | 56 | 0x71, 0xd2, 0xc2, 0x0f, 0x9b, 0x92, 0x8f, 0xe2, |
55 | 0x27,0x0d,0x6f,0xb8,0x63,0xd5,0x17,0x38, | 57 | 0x27, 0x0d, 0x6f, 0xb8, 0x63, 0xd5, 0x17, 0x38, |
56 | 0xb4,0x8e,0xee,0xe3,0x14,0xa7,0xcc,0x8a, | 58 | 0xb4, 0x8e, 0xee, 0xe3, 0x14, 0xa7, 0xcc, 0x8a, |
57 | 0xb9,0x32,0x16,0x45,0x48,0xe5,0x26,0xae, | 59 | 0xb9, 0x32, 0x16, 0x45, 0x48, 0xe5, 0x26, 0xae, |
58 | 0x90,0x22,0x43,0x68,0x51,0x7a,0xcf,0xea, | 60 | 0x90, 0x22, 0x43, 0x68, 0x51, 0x7a, 0xcf, 0xea, |
59 | 0xbd,0x6b,0xb3,0x73,0x2b,0xc0,0xe9,0xda, | 61 | 0xbd, 0x6b, 0xb3, 0x73, 0x2b, 0xc0, 0xe9, 0xda, |
60 | 0x99,0x83,0x2b,0x61,0xca,0x01,0xb6,0xde, | 62 | 0x99, 0x83, 0x2b, 0x61, 0xca, 0x01, 0xb6, 0xde, |
61 | 0x56,0x24,0x4a,0x9e,0x88,0xd5,0xf9,0xb3, | 63 | 0x56, 0x24, 0x4a, 0x9e, 0x88, 0xd5, 0xf9, 0xb3, |
62 | 0x79,0x73,0xf6,0x22,0xa4,0x3d,0x14,0xa6, | 64 | 0x79, 0x73, 0xf6, 0x22, 0xa4, 0x3d, 0x14, 0xa6, |
63 | 0x59,0x9b,0x1f,0x65,0x4c,0xb4,0x5a,0x74, | 65 | 0x59, 0x9b, 0x1f, 0x65, 0x4c, 0xb4, 0x5a, 0x74, |
64 | 0xe3,0x55,0xa5 | 66 | 0xe3, 0x55, 0xa5 |
65 | }; | 67 | }; |
66 | 68 | ||
67 | static const unsigned char nacl_mac[16] = { | 69 | static const unsigned char nacl_mac[16] = { |
68 | 0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5, | 70 | 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5, |
69 | 0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9 | 71 | 0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9 |
70 | }; | 72 | }; |
71 | 73 | ||
72 | /* generates a final value of (2^130 - 2) == 3 */ | 74 | /* generates a final value of (2^130 - 2) == 3 */ |
73 | static const unsigned char wrap_key[32] = { | 75 | static const unsigned char wrap_key[32] = { |
74 | 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | 76 | 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
75 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | 77 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
76 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | 78 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
77 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | 79 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
78 | }; | 80 | }; |
79 | 81 | ||
80 | static const unsigned char wrap_msg[16] = { | 82 | static const unsigned char wrap_msg[16] = { |
81 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, | 83 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
82 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff | 84 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
83 | }; | 85 | }; |
84 | 86 | ||
85 | static const unsigned char wrap_mac[16] = { | 87 | static const unsigned char wrap_mac[16] = { |
86 | 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | 88 | 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
87 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | 89 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
88 | }; | 90 | }; |
89 | 91 | ||
90 | /* | 92 | /* |
@@ -92,15 +94,15 @@ poly1305_power_on_self_test(void) { | |||
92 | have all their values set to the length | 94 | have all their values set to the length |
93 | */ | 95 | */ |
94 | static const unsigned char total_key[32] = { | 96 | static const unsigned char total_key[32] = { |
95 | 0x01,0x02,0x03,0x04,0x05,0x06,0x07, | 97 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
96 | 0xff,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9, | 98 | 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, |
97 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff, | 99 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
98 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff | 100 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
99 | }; | 101 | }; |
100 | 102 | ||
101 | static const unsigned char total_mac[16] = { | 103 | static const unsigned char total_mac[16] = { |
102 | 0x64,0xaf,0xe2,0xe8,0xd6,0xad,0x7b,0xbd, | 104 | 0x64, 0xaf, 0xe2, 0xe8, 0xd6, 0xad, 0x7b, 0xbd, |
103 | 0xd2,0x87,0xf9,0x7c,0x44,0x62,0x3d,0x39 | 105 | 0xd2, 0x87, 0xf9, 0x7c, 0x44, 0x62, 0x3d, 0x39 |
104 | }; | 106 | }; |
105 | 107 | ||
106 | poly1305_context ctx; | 108 | poly1305_context ctx; |
@@ -161,6 +163,6 @@ main(int argc, char **argv) | |||
161 | fprintf(stderr, "One or more self tests failed!\n"); | 163 | fprintf(stderr, "One or more self tests failed!\n"); |
162 | return 1; | 164 | return 1; |
163 | } | 165 | } |
164 | 166 | ||
165 | return 0; | 167 | return 0; |
166 | } | 168 | } |