diff options
author | miod <> | 2014-06-01 11:11:46 +0000 |
---|---|---|
committer | miod <> | 2014-06-01 11:11:46 +0000 |
commit | 8feed9c0b8cf35589d2442426a7f5c022f055e9d (patch) | |
tree | 764f224e0d43a606966be44aaee32715ee508747 /src/regress/lib/libcrypto/cts128/cts128test.c | |
parent | e356b447e74b757810a71e2bf8e431b22fd6e328 (diff) | |
download | openbsd-8feed9c0b8cf35589d2442426a7f5c022f055e9d.tar.gz openbsd-8feed9c0b8cf35589d2442426a7f5c022f055e9d.tar.bz2 openbsd-8feed9c0b8cf35589d2442426a7f5c022f055e9d.zip |
Build these tests with WARNINGS=Yes and -Werror, and do the necessary
fixes to keep building.
Diffstat (limited to 'src/regress/lib/libcrypto/cts128/cts128test.c')
-rw-r--r-- | src/regress/lib/libcrypto/cts128/cts128test.c | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/src/regress/lib/libcrypto/cts128/cts128test.c b/src/regress/lib/libcrypto/cts128/cts128test.c index 84a3e0d46b..d910f3d4b8 100644 --- a/src/regress/lib/libcrypto/cts128/cts128test.c +++ b/src/regress/lib/libcrypto/cts128/cts128test.c | |||
@@ -12,6 +12,9 @@ | |||
12 | #include <openssl/aes.h> | 12 | #include <openssl/aes.h> |
13 | #include <openssl/modes.h> | 13 | #include <openssl/modes.h> |
14 | 14 | ||
15 | void test_vector(const unsigned char *vector,size_t len); | ||
16 | void test_nistvector(const unsigned char *vector,size_t len); | ||
17 | |||
15 | /* test vectors from RFC 3962 */ | 18 | /* test vectors from RFC 3962 */ |
16 | static const unsigned char test_key[16] = "chicken teriyaki"; | 19 | static const unsigned char test_key[16] = "chicken teriyaki"; |
17 | static const unsigned char test_input[64] = | 20 | static const unsigned char test_input[64] = |
@@ -44,12 +47,15 @@ static const unsigned char vector_64[64] = | |||
44 | 47 | ||
45 | static AES_KEY encks, decks; | 48 | static AES_KEY encks, decks; |
46 | 49 | ||
47 | void test_vector(const unsigned char *vector,size_t len) | 50 | void |
48 | { unsigned char iv[sizeof(test_iv)]; | 51 | test_vector(const unsigned char *vector,size_t len) |
52 | { | ||
53 | unsigned char iv[sizeof(test_iv)]; | ||
49 | unsigned char cleartext[64],ciphertext[64]; | 54 | unsigned char cleartext[64],ciphertext[64]; |
50 | size_t tail; | 55 | size_t tail; |
51 | 56 | ||
52 | printf("vector_%d\n",len); fflush(stdout); | 57 | printf("vector_%zu\n",len); |
58 | fflush(stdout); | ||
53 | 59 | ||
54 | if ((tail=len%16) == 0) tail = 16; | 60 | if ((tail=len%16) == 0) tail = 16; |
55 | tail += 16; | 61 | tail += 16; |
@@ -58,41 +64,43 @@ void test_vector(const unsigned char *vector,size_t len) | |||
58 | memcpy(iv,test_iv,sizeof(test_iv)); | 64 | memcpy(iv,test_iv,sizeof(test_iv)); |
59 | CRYPTO_cts128_encrypt_block(test_input,ciphertext,len,&encks,iv,(block128_f)AES_encrypt); | 65 | CRYPTO_cts128_encrypt_block(test_input,ciphertext,len,&encks,iv,(block128_f)AES_encrypt); |
60 | if (memcmp(ciphertext,vector,len)) | 66 | if (memcmp(ciphertext,vector,len)) |
61 | fprintf(stderr,"output_%d mismatch\n",len), exit(1); | 67 | fprintf(stderr,"output_%zu mismatch\n",len), exit(1); |
62 | if (memcmp(iv,vector+len-tail,sizeof(iv))) | 68 | if (memcmp(iv,vector+len-tail,sizeof(iv))) |
63 | fprintf(stderr,"iv_%d mismatch\n",len), exit(1); | 69 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(1); |
64 | 70 | ||
65 | /* test block-based decryption */ | 71 | /* test block-based decryption */ |
66 | memcpy(iv,test_iv,sizeof(test_iv)); | 72 | memcpy(iv,test_iv,sizeof(test_iv)); |
67 | CRYPTO_cts128_decrypt_block(ciphertext,cleartext,len,&decks,iv,(block128_f)AES_decrypt); | 73 | CRYPTO_cts128_decrypt_block(ciphertext,cleartext,len,&decks,iv,(block128_f)AES_decrypt); |
68 | if (memcmp(cleartext,test_input,len)) | 74 | if (memcmp(cleartext,test_input,len)) |
69 | fprintf(stderr,"input_%d mismatch\n",len), exit(2); | 75 | fprintf(stderr,"input_%zu mismatch\n",len), exit(2); |
70 | if (memcmp(iv,vector+len-tail,sizeof(iv))) | 76 | if (memcmp(iv,vector+len-tail,sizeof(iv))) |
71 | fprintf(stderr,"iv_%d mismatch\n",len), exit(2); | 77 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(2); |
72 | 78 | ||
73 | /* test streamed encryption */ | 79 | /* test streamed encryption */ |
74 | memcpy(iv,test_iv,sizeof(test_iv)); | 80 | memcpy(iv,test_iv,sizeof(test_iv)); |
75 | CRYPTO_cts128_encrypt(test_input,ciphertext,len,&encks,iv,(cbc128_f)AES_cbc_encrypt); | 81 | CRYPTO_cts128_encrypt(test_input,ciphertext,len,&encks,iv,(cbc128_f)AES_cbc_encrypt); |
76 | if (memcmp(ciphertext,vector,len)) | 82 | if (memcmp(ciphertext,vector,len)) |
77 | fprintf(stderr,"output_%d mismatch\n",len), exit(3); | 83 | fprintf(stderr,"output_%zu mismatch\n",len), exit(3); |
78 | if (memcmp(iv,vector+len-tail,sizeof(iv))) | 84 | if (memcmp(iv,vector+len-tail,sizeof(iv))) |
79 | fprintf(stderr,"iv_%d mismatch\n",len), exit(3); | 85 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(3); |
80 | 86 | ||
81 | /* test streamed decryption */ | 87 | /* test streamed decryption */ |
82 | memcpy(iv,test_iv,sizeof(test_iv)); | 88 | memcpy(iv,test_iv,sizeof(test_iv)); |
83 | CRYPTO_cts128_decrypt(ciphertext,cleartext,len,&decks,iv,(cbc128_f)AES_cbc_encrypt); | 89 | CRYPTO_cts128_decrypt(ciphertext,cleartext,len,&decks,iv,(cbc128_f)AES_cbc_encrypt); |
84 | if (memcmp(cleartext,test_input,len)) | 90 | if (memcmp(cleartext,test_input,len)) |
85 | fprintf(stderr,"input_%d mismatch\n",len), exit(4); | 91 | fprintf(stderr,"input_%zu mismatch\n",len), exit(4); |
86 | if (memcmp(iv,vector+len-tail,sizeof(iv))) | 92 | if (memcmp(iv,vector+len-tail,sizeof(iv))) |
87 | fprintf(stderr,"iv_%d mismatch\n",len), exit(4); | 93 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(4); |
88 | } | 94 | } |
89 | 95 | ||
90 | void test_nistvector(const unsigned char *vector,size_t len) | 96 | void |
91 | { unsigned char iv[sizeof(test_iv)]; | 97 | test_nistvector(const unsigned char *vector,size_t len) |
98 | { | ||
99 | unsigned char iv[sizeof(test_iv)]; | ||
92 | unsigned char cleartext[64],ciphertext[64],nistvector[64]; | 100 | unsigned char cleartext[64],ciphertext[64],nistvector[64]; |
93 | size_t tail; | 101 | size_t tail; |
94 | 102 | ||
95 | printf("nistvector_%d\n",len); fflush(stdout); | 103 | printf("nistvector_%zu\n",len); fflush(stdout); |
96 | 104 | ||
97 | if ((tail=len%16) == 0) tail = 16; | 105 | if ((tail=len%16) == 0) tail = 16; |
98 | 106 | ||
@@ -108,36 +116,37 @@ void test_nistvector(const unsigned char *vector,size_t len) | |||
108 | memcpy(iv,test_iv,sizeof(test_iv)); | 116 | memcpy(iv,test_iv,sizeof(test_iv)); |
109 | CRYPTO_nistcts128_encrypt_block(test_input,ciphertext,len,&encks,iv,(block128_f)AES_encrypt); | 117 | CRYPTO_nistcts128_encrypt_block(test_input,ciphertext,len,&encks,iv,(block128_f)AES_encrypt); |
110 | if (memcmp(ciphertext,nistvector,len)) | 118 | if (memcmp(ciphertext,nistvector,len)) |
111 | fprintf(stderr,"output_%d mismatch\n",len), exit(1); | 119 | fprintf(stderr,"output_%zu mismatch\n",len), exit(1); |
112 | if (memcmp(iv,nistvector+len-tail,sizeof(iv))) | 120 | if (memcmp(iv,nistvector+len-tail,sizeof(iv))) |
113 | fprintf(stderr,"iv_%d mismatch\n",len), exit(1); | 121 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(1); |
114 | 122 | ||
115 | /* test block-based decryption */ | 123 | /* test block-based decryption */ |
116 | memcpy(iv,test_iv,sizeof(test_iv)); | 124 | memcpy(iv,test_iv,sizeof(test_iv)); |
117 | CRYPTO_nistcts128_decrypt_block(ciphertext,cleartext,len,&decks,iv,(block128_f)AES_decrypt); | 125 | CRYPTO_nistcts128_decrypt_block(ciphertext,cleartext,len,&decks,iv,(block128_f)AES_decrypt); |
118 | if (memcmp(cleartext,test_input,len)) | 126 | if (memcmp(cleartext,test_input,len)) |
119 | fprintf(stderr,"input_%d mismatch\n",len), exit(2); | 127 | fprintf(stderr,"input_%zu mismatch\n",len), exit(2); |
120 | if (memcmp(iv,nistvector+len-tail,sizeof(iv))) | 128 | if (memcmp(iv,nistvector+len-tail,sizeof(iv))) |
121 | fprintf(stderr,"iv_%d mismatch\n",len), exit(2); | 129 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(2); |
122 | 130 | ||
123 | /* test streamed encryption */ | 131 | /* test streamed encryption */ |
124 | memcpy(iv,test_iv,sizeof(test_iv)); | 132 | memcpy(iv,test_iv,sizeof(test_iv)); |
125 | CRYPTO_nistcts128_encrypt(test_input,ciphertext,len,&encks,iv,(cbc128_f)AES_cbc_encrypt); | 133 | CRYPTO_nistcts128_encrypt(test_input,ciphertext,len,&encks,iv,(cbc128_f)AES_cbc_encrypt); |
126 | if (memcmp(ciphertext,nistvector,len)) | 134 | if (memcmp(ciphertext,nistvector,len)) |
127 | fprintf(stderr,"output_%d mismatch\n",len), exit(3); | 135 | fprintf(stderr,"output_%zu mismatch\n",len), exit(3); |
128 | if (memcmp(iv,nistvector+len-tail,sizeof(iv))) | 136 | if (memcmp(iv,nistvector+len-tail,sizeof(iv))) |
129 | fprintf(stderr,"iv_%d mismatch\n",len), exit(3); | 137 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(3); |
130 | 138 | ||
131 | /* test streamed decryption */ | 139 | /* test streamed decryption */ |
132 | memcpy(iv,test_iv,sizeof(test_iv)); | 140 | memcpy(iv,test_iv,sizeof(test_iv)); |
133 | CRYPTO_nistcts128_decrypt(ciphertext,cleartext,len,&decks,iv,(cbc128_f)AES_cbc_encrypt); | 141 | CRYPTO_nistcts128_decrypt(ciphertext,cleartext,len,&decks,iv,(cbc128_f)AES_cbc_encrypt); |
134 | if (memcmp(cleartext,test_input,len)) | 142 | if (memcmp(cleartext,test_input,len)) |
135 | fprintf(stderr,"input_%d mismatch\n",len), exit(4); | 143 | fprintf(stderr,"input_%zu mismatch\n",len), exit(4); |
136 | if (memcmp(iv,nistvector+len-tail,sizeof(iv))) | 144 | if (memcmp(iv,nistvector+len-tail,sizeof(iv))) |
137 | fprintf(stderr,"iv_%d mismatch\n",len), exit(4); | 145 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(4); |
138 | } | 146 | } |
139 | 147 | ||
140 | int main() | 148 | int |
149 | main(int argc, char *argv[]) | ||
141 | { | 150 | { |
142 | AES_set_encrypt_key(test_key,128,&encks); | 151 | AES_set_encrypt_key(test_key,128,&encks); |
143 | AES_set_decrypt_key(test_key,128,&decks); | 152 | AES_set_decrypt_key(test_key,128,&decks); |