Mercurial > dropbear
comparison libtomcrypt/src/ciphers/anubis.c @ 1511:5916af64acd4 fuzz
merge from main
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 17 Feb 2018 19:29:51 +0800 |
parents | 6dba84798cd5 |
children |
comparison
equal
deleted
inserted
replaced
1457:32f990cc96b1 | 1511:5916af64acd4 |
---|---|
3 * LibTomCrypt is a library that provides various cryptographic | 3 * LibTomCrypt is a library that provides various cryptographic |
4 * algorithms in a highly modular and flexible manner. | 4 * algorithms in a highly modular and flexible manner. |
5 * | 5 * |
6 * The library is free for all purposes without any express | 6 * The library is free for all purposes without any express |
7 * guarantee it works. | 7 * guarantee it works. |
8 * | |
9 * Tom St Denis, [email protected], http://libtom.org | |
10 */ | 8 */ |
11 | 9 |
12 /** | 10 /** |
13 @file anubis.c | 11 @file anubis.c |
14 Anubis implementation derived from public domain source | 12 Anubis implementation derived from public domain source |
27 &anubis_ecb_encrypt, | 25 &anubis_ecb_encrypt, |
28 &anubis_ecb_decrypt, | 26 &anubis_ecb_decrypt, |
29 &anubis_test, | 27 &anubis_test, |
30 &anubis_done, | 28 &anubis_done, |
31 &anubis_keysize, | 29 &anubis_keysize, |
32 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL | 30 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL |
33 }; | 31 }; |
34 | 32 |
35 #define MIN_N 4 | 33 #define MIN_N 4 |
36 #define MAX_N 10 | 34 #define MAX_N 10 |
37 #define MIN_ROUNDS (8 + MIN_N) | 35 #define MIN_ROUNDS (8 + MIN_N) |
38 #define MAX_ROUNDS (8 + MAX_N) | 36 #define MAX_ROUNDS (8 + MAX_N) |
39 #define MIN_KEYSIZEB (4*MIN_N) | 37 #define MIN_KEYSIZEB (4*MIN_N) |
40 #define MAX_KEYSIZEB (4*MAX_N) | 38 #define MAX_KEYSIZEB (4*MAX_N) |
41 #define BLOCKSIZE 128 | 39 #define BLOCKSIZE 128 |
42 #define BLOCKSIZEB (BLOCKSIZE/8) | 40 #define BLOCKSIZEB (BLOCKSIZE/8) |
43 | 41 |
44 | 42 |
45 /* | 43 /* |
46 * Though Anubis is endianness-neutral, the encryption tables are listed | 44 * Though Anubis is endianness-neutral, the encryption tables are listed |
47 * in BIG-ENDIAN format, which is adopted throughout this implementation | 45 * in BIG-ENDIAN format, which is adopted throughout this implementation |
897 int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey) | 895 int anubis_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey) |
898 #endif | 896 #endif |
899 { | 897 { |
900 int N, R, i, pos, r; | 898 int N, R, i, pos, r; |
901 ulong32 kappa[MAX_N]; | 899 ulong32 kappa[MAX_N]; |
902 ulong32 inter[MAX_N]; | 900 ulong32 inter[MAX_N] = { 0 }; /* initialize as all zeroes */ |
903 ulong32 v, K0, K1, K2, K3; | 901 ulong32 v, K0, K1, K2, K3; |
904 | 902 |
905 LTC_ARGCHK(key != NULL); | 903 LTC_ARGCHK(key != NULL); |
906 LTC_ARGCHK(skey != NULL); | 904 LTC_ARGCHK(skey != NULL); |
907 | 905 |
924 | 922 |
925 if (num_rounds != 0 && num_rounds != skey->anubis.R) { | 923 if (num_rounds != 0 && num_rounds != skey->anubis.R) { |
926 return CRYPT_INVALID_ROUNDS; | 924 return CRYPT_INVALID_ROUNDS; |
927 } | 925 } |
928 | 926 |
929 /* | 927 /* |
930 * map cipher key to initial key state (mu): | 928 * map cipher key to initial key state (mu): |
931 */ | 929 */ |
932 for (i = 0, pos = 0; i < N; i++, pos += 4) { | 930 for (i = 0, pos = 0; i < N; i++, pos += 4) { |
933 kappa[i] = | 931 kappa[i] = |
934 (key[pos ] << 24) ^ | 932 (((ulong32)key[pos ]) << 24) ^ |
935 (key[pos + 1] << 16) ^ | 933 (((ulong32)key[pos + 1]) << 16) ^ |
936 (key[pos + 2] << 8) ^ | 934 (((ulong32)key[pos + 2]) << 8) ^ |
937 (key[pos + 3] ); | 935 (((ulong32)key[pos + 3]) ); |
938 } | 936 } |
939 | 937 |
940 /* | 938 /* |
941 * generate R + 1 round keys: | 939 * generate R + 1 round keys: |
942 */ | 940 */ |
943 for (r = 0; r <= R; r++) { | 941 for (r = 0; r <= R; r++) { |
1032 err = _anubis_setup(key, keylen, num_rounds, skey); | 1030 err = _anubis_setup(key, keylen, num_rounds, skey); |
1033 burn_stack(sizeof(int) * 5 + sizeof(ulong32) * (MAX_N + MAX_N + 5)); | 1031 burn_stack(sizeof(int) * 5 + sizeof(ulong32) * (MAX_N + MAX_N + 5)); |
1034 return err; | 1032 return err; |
1035 } | 1033 } |
1036 #endif | 1034 #endif |
1037 | 1035 |
1038 | 1036 |
1039 static void anubis_crypt(const unsigned char *plaintext, unsigned char *ciphertext, | 1037 static void anubis_crypt(const unsigned char *plaintext, unsigned char *ciphertext, |
1040 ulong32 roundKey[18 + 1][4], int R) { | 1038 ulong32 roundKey[18 + 1][4], int R) { |
1041 int i, pos, r; | 1039 int i, pos, r; |
1042 ulong32 state[4]; | 1040 ulong32 state[4]; |
1046 * map plaintext block to cipher state (mu) | 1044 * map plaintext block to cipher state (mu) |
1047 * and add initial round key (sigma[K^0]): | 1045 * and add initial round key (sigma[K^0]): |
1048 */ | 1046 */ |
1049 for (i = 0, pos = 0; i < 4; i++, pos += 4) { | 1047 for (i = 0, pos = 0; i < 4; i++, pos += 4) { |
1050 state[i] = | 1048 state[i] = |
1051 (plaintext[pos ] << 24) ^ | 1049 (((ulong32)plaintext[pos ]) << 24) ^ |
1052 (plaintext[pos + 1] << 16) ^ | 1050 (((ulong32)plaintext[pos + 1]) << 16) ^ |
1053 (plaintext[pos + 2] << 8) ^ | 1051 (((ulong32)plaintext[pos + 2]) << 8) ^ |
1054 (plaintext[pos + 3] ) ^ | 1052 (((ulong32)plaintext[pos + 3]) ) ^ |
1055 roundKey[0][i]; | 1053 roundKey[0][i]; |
1056 } | 1054 } |
1057 | 1055 |
1058 /* | 1056 /* |
1059 * R - 1 full rounds: | 1057 * R - 1 full rounds: |
1147 | 1145 |
1148 /** | 1146 /** |
1149 Decrypts a block of text with Anubis | 1147 Decrypts a block of text with Anubis |
1150 @param ct The input ciphertext (16 bytes) | 1148 @param ct The input ciphertext (16 bytes) |
1151 @param pt The output plaintext (16 bytes) | 1149 @param pt The output plaintext (16 bytes) |
1152 @param skey The key as scheduled | 1150 @param skey The key as scheduled |
1153 @return CRYPT_OK if successful | 1151 @return CRYPT_OK if successful |
1154 */ | 1152 */ |
1155 int anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) | 1153 int anubis_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) |
1156 { | 1154 { |
1157 LTC_ARGCHK(pt != NULL); | 1155 LTC_ARGCHK(pt != NULL); |
1179 /* 128 bit keys */ | 1177 /* 128 bit keys */ |
1180 { | 1178 { |
1181 16, | 1179 16, |
1182 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1180 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1183 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1181 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1184 { 0xF0, 0x68, 0x60, 0xFC, 0x67, 0x30, 0xE8, 0x18, | 1182 { 0xF0, 0x68, 0x60, 0xFC, 0x67, 0x30, 0xE8, 0x18, |
1185 0xF1, 0x32, 0xC7, 0x8A, 0xF4, 0x13, 0x2A, 0xFE }, | 1183 0xF1, 0x32, 0xC7, 0x8A, 0xF4, 0x13, 0x2A, 0xFE }, |
1186 { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1184 { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } | 1185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } |
1188 }, { | 1186 }, { |
1189 16, | 1187 16, |
1190 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1188 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1189 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1192 { 0xA8, 0x66, 0x84, 0x80, 0x07, 0x74, 0x5C, 0x89, | 1190 { 0xA8, 0x66, 0x84, 0x80, 0x07, 0x74, 0x5C, 0x89, |
1193 0xFC, 0x5E, 0xB5, 0xBA, 0xD4, 0xFE, 0x32, 0x6D }, | 1191 0xFC, 0x5E, 0xB5, 0xBA, 0xD4, 0xFE, 0x32, 0x6D }, |
1194 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1192 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } | 1193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } |
1196 }, | 1194 }, |
1197 | 1195 |
1219 /* 192-bit keys */ | 1217 /* 192-bit keys */ |
1220 { | 1218 { |
1221 24, | 1219 24, |
1222 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1220 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1224 { 0x17, 0xAC, 0x57, 0x44, 0x9D, 0x59, 0x61, 0x66, | 1222 { 0x17, 0xAC, 0x57, 0x44, 0x9D, 0x59, 0x61, 0x66, |
1225 0xD0, 0xC7, 0x9E, 0x04, 0x7C, 0xC7, 0x58, 0xF0 }, | 1223 0xD0, 0xC7, 0x9E, 0x04, 0x7C, 0xC7, 0x58, 0xF0 }, |
1226 { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1224 { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } | 1226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } |
1229 }, { | 1227 }, { |
1230 24, | 1228 24, |
1231 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1229 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1233 { 0x71, 0x52, 0xB4, 0xEB, 0x1D, 0xAA, 0x36, 0xFD, | 1231 { 0x71, 0x52, 0xB4, 0xEB, 0x1D, 0xAA, 0x36, 0xFD, |
1234 0x57, 0x14, 0x5F, 0x57, 0x04, 0x9F, 0x70, 0x74 }, | 1232 0x57, 0x14, 0x5F, 0x57, 0x04, 0x9F, 0x70, 0x74 }, |
1235 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1233 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } | 1235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } |
1238 }, | 1236 }, |
1240 /* 224-bit keys */ | 1238 /* 224-bit keys */ |
1241 { | 1239 { |
1242 28, | 1240 28, |
1243 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1241 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1245 { 0xA2, 0xF0, 0xA6, 0xB9, 0x17, 0x93, 0x2A, 0x3B, | 1243 { 0xA2, 0xF0, 0xA6, 0xB9, 0x17, 0x93, 0x2A, 0x3B, |
1246 0xEF, 0x08, 0xE8, 0x7A, 0x58, 0xD6, 0xF8, 0x53 }, | 1244 0xEF, 0x08, 0xE8, 0x7A, 0x58, 0xD6, 0xF8, 0x53 }, |
1247 { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1245 { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1250 0x00, 0x00, 0x00, 0x00 } | 1248 0x00, 0x00, 0x00, 0x00 } |
1251 }, { | 1249 }, { |
1252 28, | 1250 28, |
1253 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1251 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1255 { 0xF0, 0xCA, 0xFC, 0x78, 0x8B, 0x4B, 0x4E, 0x53, | 1253 { 0xF0, 0xCA, 0xFC, 0x78, 0x8B, 0x4B, 0x4E, 0x53, |
1256 0x8B, 0xC4, 0x32, 0x6A, 0xF5, 0xB9, 0x1B, 0x5F }, | 1254 0x8B, 0xC4, 0x32, 0x6A, 0xF5, 0xB9, 0x1B, 0x5F }, |
1257 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1255 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1260 0x00, 0x00, 0x00, 0x01 } | 1258 0x00, 0x00, 0x00, 0x01 } |
1263 /* 256-bit keys */ | 1261 /* 256-bit keys */ |
1264 { | 1262 { |
1265 32, | 1263 32, |
1266 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1264 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1268 { 0xE0, 0x86, 0xAC, 0x45, 0x6B, 0x3C, 0xE5, 0x13, | 1266 { 0xE0, 0x86, 0xAC, 0x45, 0x6B, 0x3C, 0xE5, 0x13, |
1269 0xED, 0xF5, 0xDF, 0xDD, 0xD6, 0x3B, 0x71, 0x93 }, | 1267 0xED, 0xF5, 0xDF, 0xDD, 0xD6, 0x3B, 0x71, 0x93 }, |
1270 { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1268 { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1273 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } | 1271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } |
1274 }, { | 1272 }, { |
1275 32, | 1273 32, |
1276 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1274 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1275 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1278 { 0x50, 0x01, 0xB9, 0xF5, 0x21, 0xC1, 0xC1, 0x29, | 1276 { 0x50, 0x01, 0xB9, 0xF5, 0x21, 0xC1, 0xC1, 0x29, |
1279 0x00, 0xD5, 0xEC, 0x98, 0x2B, 0x9E, 0xE8, 0x21 }, | 1277 0x00, 0xD5, 0xEC, 0x98, 0x2B, 0x9E, 0xE8, 0x21 }, |
1280 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1278 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1282 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1280 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } | 1281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } |
1286 /* 288-bit keys */ | 1284 /* 288-bit keys */ |
1287 { | 1285 { |
1288 36, | 1286 36, |
1289 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1287 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1291 { 0xE8, 0xF4, 0xAF, 0x2B, 0x21, 0xA0, 0x87, 0x9B, | 1289 { 0xE8, 0xF4, 0xAF, 0x2B, 0x21, 0xA0, 0x87, 0x9B, |
1292 0x41, 0x95, 0xB9, 0x71, 0x75, 0x79, 0x04, 0x7C }, | 1290 0x41, 0x95, 0xB9, 0x71, 0x75, 0x79, 0x04, 0x7C }, |
1293 { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1291 { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1297 0x00, 0x00, 0x00, 0x00 } | 1295 0x00, 0x00, 0x00, 0x00 } |
1298 }, { | 1296 }, { |
1299 36, | 1297 36, |
1300 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1298 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1302 { 0xE6, 0xA6, 0xA5, 0xBC, 0x8B, 0x63, 0x6F, 0xE2, | 1300 { 0xE6, 0xA6, 0xA5, 0xBC, 0x8B, 0x63, 0x6F, 0xE2, |
1303 0xBD, 0xA7, 0xA7, 0x53, 0xAB, 0x40, 0x22, 0xE0 }, | 1301 0xBD, 0xA7, 0xA7, 0x53, 0xAB, 0x40, 0x22, 0xE0 }, |
1304 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1302 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1311 /* 320-bit keys */ | 1309 /* 320-bit keys */ |
1312 { | 1310 { |
1313 40, | 1311 40, |
1314 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1312 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1315 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1316 { 0x17, 0x04, 0xD7, 0x2C, 0xC6, 0x85, 0x76, 0x02, | 1314 { 0x17, 0x04, 0xD7, 0x2C, 0xC6, 0x85, 0x76, 0x02, |
1317 0x4B, 0xCC, 0x39, 0x80, 0xD8, 0x22, 0xEA, 0xA4 }, | 1315 0x4B, 0xCC, 0x39, 0x80, 0xD8, 0x22, 0xEA, 0xA4 }, |
1318 { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1316 { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } | 1320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } |
1323 }, { | 1321 }, { |
1324 40, | 1322 40, |
1325 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1323 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1327 { 0x7A, 0x41, 0xE6, 0x7D, 0x4F, 0xD8, 0x64, 0xF0, | 1325 { 0x7A, 0x41, 0xE6, 0x7D, 0x4F, 0xD8, 0x64, 0xF0, |
1328 0x44, 0xA8, 0x3C, 0x73, 0x81, 0x7E, 0x53, 0xD8 }, | 1326 0x44, 0xA8, 0x3C, 0x73, 0x81, 0x7E, 0x53, 0xD8 }, |
1329 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1327 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1329 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1498 | 1496 |
1499 for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { | 1497 for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { |
1500 anubis_setup(tests[x].key, tests[x].keylen, 0, &skey); | 1498 anubis_setup(tests[x].key, tests[x].keylen, 0, &skey); |
1501 anubis_ecb_encrypt(tests[x].pt, buf[0], &skey); | 1499 anubis_ecb_encrypt(tests[x].pt, buf[0], &skey); |
1502 anubis_ecb_decrypt(buf[0], buf[1], &skey); | 1500 anubis_ecb_decrypt(buf[0], buf[1], &skey); |
1503 if (XMEMCMP(buf[0], tests[x].ct, 16) || XMEMCMP(buf[1], tests[x].pt, 16)) { | 1501 if (compare_testvector(buf[0], 16, tests[x].ct, 16, "Anubis Encrypt", x) || |
1502 compare_testvector(buf[1], 16, tests[x].pt, 16, "Anubis Decrypt", x)) { | |
1504 return CRYPT_FAIL_TESTVECTOR; | 1503 return CRYPT_FAIL_TESTVECTOR; |
1505 } | 1504 } |
1506 | 1505 |
1507 for (y = 0; y < 1000; y++) anubis_ecb_encrypt(buf[0], buf[0], &skey); | 1506 for (y = 0; y < 1000; y++) anubis_ecb_encrypt(buf[0], buf[0], &skey); |
1508 for (y = 0; y < 1000; y++) anubis_ecb_decrypt(buf[0], buf[0], &skey); | 1507 for (y = 0; y < 1000; y++) anubis_ecb_decrypt(buf[0], buf[0], &skey); |
1509 if (XMEMCMP(buf[0], tests[x].ct, 16)) { | 1508 if (compare_testvector(buf[0], 16, tests[x].ct, 16, "Anubis 1000", 1000)) { |
1510 return CRYPT_FAIL_TESTVECTOR; | 1509 return CRYPT_FAIL_TESTVECTOR; |
1511 } | 1510 } |
1512 | 1511 |
1513 } | 1512 } |
1514 return CRYPT_OK; | 1513 return CRYPT_OK; |
1515 #endif | 1514 #endif |
1516 } | 1515 } |
1517 | 1516 |
1518 /** Terminate the context | 1517 /** Terminate the context |
1519 @param skey The scheduled key | 1518 @param skey The scheduled key |
1520 */ | 1519 */ |
1521 void anubis_done(symmetric_key *skey) | 1520 void anubis_done(symmetric_key *skey) |
1522 { | 1521 { |
1522 LTC_UNUSED_PARAM(skey); | |
1523 } | 1523 } |
1524 | 1524 |
1525 /** | 1525 /** |
1526 Gets suitable key size | 1526 Gets suitable key size |
1527 @param keysize [in/out] The length of the recommended key (in bytes). This function will store the suitable size back in this variable. | 1527 @param keysize [in/out] The length of the recommended key (in bytes). This function will store the suitable size back in this variable. |
1551 } | 1551 } |
1552 | 1552 |
1553 #endif | 1553 #endif |
1554 | 1554 |
1555 | 1555 |
1556 /* $Source$ */ | 1556 /* ref: $Format:%D$ */ |
1557 /* $Revision$ */ | 1557 /* git commit: $Format:%H$ */ |
1558 /* $Date$ */ | 1558 /* commit time: $Format:%ai$ */ |