add aes256 test vectors from Ken Raeburn
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@12381 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -229,9 +229,11 @@ string_to_key_test(krb5_context context)
|
|||||||
opaque.length = sizeof(iter);
|
opaque.length = sizeof(iter);
|
||||||
_krb5_put_int(iter, keys[i].iterations, 4);
|
_krb5_put_int(iter, keys[i].iterations, 4);
|
||||||
|
|
||||||
|
#if 0
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("%d: password: %s salt: %s\n",
|
printf("%d: password: %s salt: %s\n",
|
||||||
i, keys[i].password, keys[i].salt);
|
i, keys[i].password, keys[i].salt);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (keys[i].keylen > sizeof(keyout))
|
if (keys[i].keylen > sizeof(keyout))
|
||||||
abort();
|
abort();
|
||||||
@@ -317,11 +319,13 @@ string_to_key_test(krb5_context context)
|
|||||||
|
|
||||||
#ifdef ENABLE_AES
|
#ifdef ENABLE_AES
|
||||||
|
|
||||||
struct {
|
struct enc_test {
|
||||||
size_t len;
|
size_t len;
|
||||||
char *input;
|
char *input;
|
||||||
char *output;
|
char *output;
|
||||||
} encs[] = {
|
};
|
||||||
|
|
||||||
|
struct enc_test encs1[] = {
|
||||||
{
|
{
|
||||||
17,
|
17,
|
||||||
"\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
|
"\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
|
||||||
@@ -365,9 +369,128 @@ struct {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
char *enc_key =
|
|
||||||
|
struct enc_test encs2[] = {
|
||||||
|
{
|
||||||
|
17,
|
||||||
|
"\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
|
||||||
|
"\x20",
|
||||||
|
"\x5c\x13\x26\x27\xc4\xcb\xca\x04\x14\x43\x8a\xb5\x97\x97\x7c\x10"
|
||||||
|
"\x16"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
31,
|
||||||
|
"\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
|
||||||
|
"\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20",
|
||||||
|
"\x16\xb3\xd8\xe5\xcd\x93\xe6\x2c\x28\x70\xa0\x36\x6e\x9a\xb9\x74"
|
||||||
|
"\x16\xc1\xee\xdf\x39\xc8\x3f\xfb\xc5\xf6\x72\xe9\xc1\x6e\x53"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
32,
|
||||||
|
"\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
|
||||||
|
"\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43",
|
||||||
|
"\x69\xde\xce\x59\x83\x6a\x82\xe1\xcd\x21\x93\xd0\x9e\x2a\xff\xc8"
|
||||||
|
"\x16\xc1\xee\xdf\x39\xc8\x3f\xfb\xc5\xf6\x72\xe9\xc1\x6e\x53\x0c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
47,
|
||||||
|
"\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
|
||||||
|
"\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
|
||||||
|
"\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c",
|
||||||
|
"\x16\xc1\xee\xdf\x39\xc8\x3f\xfb\xc5\xf6\x72\xe9\xc1\x6e\x53\x0c"
|
||||||
|
"\xe5\x56\xb4\x88\x41\xb9\xde\x27\xf0\x07\xa1\x6e\x89\x94\x47\xf1"
|
||||||
|
"\x69\xde\xce\x59\x83\x6a\x82\xe1\xcd\x21\x93\xd0\x9e\x2a\xff"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
48,
|
||||||
|
"\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
|
||||||
|
"\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
|
||||||
|
"\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20",
|
||||||
|
"\x16\xc1\xee\xdf\x39\xc8\x3f\xfb\xc5\xf6\x72\xe9\xc1\x6e\x53\x0c"
|
||||||
|
"\xfd\x68\xd1\x56\x32\x23\x7b\xfa\xb0\x09\x86\x3b\x17\x53\xfa\x30"
|
||||||
|
"\x69\xde\xce\x59\x83\x6a\x82\xe1\xcd\x21\x93\xd0\x9e\x2a\xff\xc8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
64,
|
||||||
|
"\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
|
||||||
|
"\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
|
||||||
|
"\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20"
|
||||||
|
"\x61\x6e\x64\x20\x77\x6f\x6e\x74\x6f\x6e\x20\x73\x6f\x75\x70\x2e",
|
||||||
|
"\x16\xc1\xee\xdf\x39\xc8\x3f\xfb\xc5\xf6\x72\xe9\xc1\x6e\x53\x0c"
|
||||||
|
"\x69\xde\xce\x59\x83\x6a\x82\xe1\xcd\x21\x93\xd0\x9e\x2a\xff\xc8"
|
||||||
|
"\x70\x29\xf2\x6f\x7c\x79\xc1\x77\x91\xad\x94\xb0\x78\x62\x27\x67"
|
||||||
|
"\xfd\x68\xd1\x56\x32\x23\x7b\xfa\xb0\x09\x86\x3b\x17\x53\xfa\x30"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
78,
|
||||||
|
"\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
|
||||||
|
"\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
|
||||||
|
"\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20"
|
||||||
|
"\x61\x6e\x64\x20\x77\x6f\x6e\x74\x6f\x6e\x20\x73\x6f\x75\x70\x2e"
|
||||||
|
"\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41",
|
||||||
|
"\x16\xc1\xee\xdf\x39\xc8\x3f\xfb\xc5\xf6\x72\xe9\xc1\x6e\x53\x0c"
|
||||||
|
"\x69\xde\xce\x59\x83\x6a\x82\xe1\xcd\x21\x93\xd0\x9e\x2a\xff\xc8"
|
||||||
|
"\xfd\x68\xd1\x56\x32\x23\x7b\xfa\xb0\x09\x86\x3b\x17\x53\xfa\x30"
|
||||||
|
"\x73\xfb\x2c\x36\x76\xaf\xcf\x31\xff\xe3\x8a\x89\x0c\x7e\x99\x3f"
|
||||||
|
"\x70\x29\xf2\x6f\x7c\x79\xc1\x77\x91\xad\x94\xb0\x78\x62"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
83,
|
||||||
|
"\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
|
||||||
|
"\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
|
||||||
|
"\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20"
|
||||||
|
"\x61\x6e\x64\x20\x77\x6f\x6e\x74\x6f\x6e\x20\x73\x6f\x75\x70\x2e"
|
||||||
|
"\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41"
|
||||||
|
"\x41\x41\x41",
|
||||||
|
"\x16\xc1\xee\xdf\x39\xc8\x3f\xfb\xc5\xf6\x72\xe9\xc1\x6e\x53\x0c"
|
||||||
|
"\x69\xde\xce\x59\x83\x6a\x82\xe1\xcd\x21\x93\xd0\x9e\x2a\xff\xc8"
|
||||||
|
"\xfd\x68\xd1\x56\x32\x23\x7b\xfa\xb0\x09\x86\x3b\x17\x53\xfa\x30"
|
||||||
|
"\x70\x29\xf2\x6f\x7c\x79\xc1\x77\x91\xad\x94\xb0\x78\x62\x27\x67"
|
||||||
|
"\x65\x39\x3a\xdb\x92\x05\x4d\x4f\x08\xa1\xfa\x59\xda\x56\x58\x0e"
|
||||||
|
"\x3b\xac\x12"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
92,
|
||||||
|
"\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
|
||||||
|
"\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
|
||||||
|
"\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20"
|
||||||
|
"\x61\x6e\x64\x20\x77\x6f\x6e\x74\x6f\x6e\x20\x73\x6f\x75\x70\x2e"
|
||||||
|
"\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41"
|
||||||
|
"\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41",
|
||||||
|
"\x16\xc1\xee\xdf\x39\xc8\x3f\xfb\xc5\xf6\x72\xe9\xc1\x6e\x53\x0c"
|
||||||
|
"\x69\xde\xce\x59\x83\x6a\x82\xe1\xcd\x21\x93\xd0\x9e\x2a\xff\xc8"
|
||||||
|
"\xfd\x68\xd1\x56\x32\x23\x7b\xfa\xb0\x09\x86\x3b\x17\x53\xfa\x30"
|
||||||
|
"\x70\x29\xf2\x6f\x7c\x79\xc1\x77\x91\xad\x94\xb0\x78\x62\x27\x67"
|
||||||
|
"\x0c\xff\xd7\x63\x50\xf8\x4e\xf9\xec\x56\x1c\x79\xc5\xc8\xfe\x50"
|
||||||
|
"\x3b\xac\x12\x6e\xd3\x2d\x02\xc4\xe5\x06\x43\x5f"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
96,
|
||||||
|
"\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
|
||||||
|
"\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
|
||||||
|
"\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20"
|
||||||
|
"\x61\x6e\x64\x20\x77\x6f\x6e\x74\x6f\x6e\x20\x73\x6f\x75\x70\x2e"
|
||||||
|
"\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41"
|
||||||
|
"\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41",
|
||||||
|
"\x16\xc1\xee\xdf\x39\xc8\x3f\xfb\xc5\xf6\x72\xe9\xc1\x6e\x53\x0c"
|
||||||
|
"\x69\xde\xce\x59\x83\x6a\x82\xe1\xcd\x21\x93\xd0\x9e\x2a\xff\xc8"
|
||||||
|
"\xfd\x68\xd1\x56\x32\x23\x7b\xfa\xb0\x09\x86\x3b\x17\x53\xfa\x30"
|
||||||
|
"\x70\x29\xf2\x6f\x7c\x79\xc1\x77\x91\xad\x94\xb0\x78\x62\x27\x67"
|
||||||
|
"\x08\x28\x49\xad\xfc\x2d\x8e\x86\xae\x69\xa5\xa8\xd9\x29\x9e\xe4"
|
||||||
|
"\x3b\xac\x12\x6e\xd3\x2d\x02\xc4\xe5\x06\x43\x5f\x4c\x41\xd1\xb8"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char *aes_key1 =
|
||||||
"\x63\x68\x69\x63\x6b\x65\x6e\x20\x74\x65\x72\x69\x79\x61\x6b\x69";
|
"\x63\x68\x69\x63\x6b\x65\x6e\x20\x74\x65\x72\x69\x79\x61\x6b\x69";
|
||||||
|
|
||||||
|
char *aes_key2 =
|
||||||
|
"\x63\x68\x69\x63\x6b\x65\x6e\x20\x74\x65\x72\x69\x79\x61\x6b\x69"
|
||||||
|
"\x2c\x20\x79\x75\x6d\x6d\x79\x20\x79\x75\x6d\x6d\x79\x21\x21\x21";
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
samep(int testn, char *type, const char *p1, const char *p2, size_t len)
|
samep(int testn, char *type, const char *p1, const char *p2, size_t len)
|
||||||
{
|
{
|
||||||
@@ -390,56 +513,65 @@ samep(int testn, char *type, const char *p1, const char *p2, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
encryption_test(krb5_context context)
|
encryption_test(krb5_context context, char *key, int keylen,
|
||||||
|
struct enc_test *enc, int numenc)
|
||||||
{
|
{
|
||||||
char iv[AES_BLOCK_SIZE];
|
char iv[AES_BLOCK_SIZE];
|
||||||
int i, val = 0;
|
int i, val, failed = 0;
|
||||||
AES_KEY ekey, dkey;
|
AES_KEY ekey, dkey;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
AES_set_encrypt_key(enc_key, 128, &ekey);
|
AES_set_encrypt_key(key, keylen, &ekey);
|
||||||
AES_set_decrypt_key(enc_key, 128, &dkey);
|
AES_set_decrypt_key(key, keylen, &dkey);
|
||||||
|
|
||||||
|
for (i = 0; i < numenc; i++) {
|
||||||
|
val = 0;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(encs)/sizeof(encs[0]); i++) {
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("test: %d\n", i);
|
printf("test: %d\n", i);
|
||||||
memset(iv, 0, sizeof(iv));
|
memset(iv, 0, sizeof(iv));
|
||||||
|
|
||||||
p = malloc(encs[i].len + 1);
|
p = malloc(enc[i].len + 1);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
krb5_errx(context, 1, "malloc");
|
krb5_errx(context, 1, "malloc");
|
||||||
|
|
||||||
p[encs[i].len] = '\0';
|
p[enc[i].len] = '\0';
|
||||||
|
|
||||||
memcpy(p, encs[i].input, encs[i].len);
|
memcpy(p, enc[i].input, enc[i].len);
|
||||||
|
|
||||||
_krb5_aes_cts_encrypt(p, p, encs[i].len,
|
_krb5_aes_cts_encrypt(p, p, enc[i].len,
|
||||||
&ekey, iv, AES_ENCRYPT);
|
&ekey, iv, AES_ENCRYPT);
|
||||||
|
|
||||||
if (p[encs[i].len] != '\0') {
|
if (p[enc[i].len] != '\0') {
|
||||||
krb5_warnx(context, "%d: encrypt modified off end", i);
|
krb5_warnx(context, "%d: encrypt modified off end", i);
|
||||||
val = 1;
|
val = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!samep(i, "cipher", p, encs[i].output, encs[i].len))
|
if (!samep(i, "cipher", p, enc[i].output, enc[i].len))
|
||||||
val = 1;
|
val = 1;
|
||||||
|
|
||||||
memset(iv, 0, sizeof(iv));
|
memset(iv, 0, sizeof(iv));
|
||||||
|
|
||||||
_krb5_aes_cts_encrypt(p, p, encs[i].len,
|
_krb5_aes_cts_encrypt(p, p, enc[i].len,
|
||||||
&dkey, iv, AES_DECRYPT);
|
&dkey, iv, AES_DECRYPT);
|
||||||
|
|
||||||
if (p[encs[i].len] != '\0') {
|
if (p[enc[i].len] != '\0') {
|
||||||
krb5_warnx(context, "%d: decrypt modified off end", i);
|
krb5_warnx(context, "%d: decrypt modified off end", i);
|
||||||
val = 1;
|
val = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!samep(i, "clear", p, encs[i].input, encs[i].len))
|
if (!samep(i, "clear", p, enc[i].input, enc[i].len))
|
||||||
val = 1;
|
val = 1;
|
||||||
|
|
||||||
free(p);
|
free(p);
|
||||||
|
|
||||||
|
if (val) {
|
||||||
|
printf("test %d failed\n", i);
|
||||||
|
failed = 1;
|
||||||
|
}
|
||||||
|
val = 0;
|
||||||
}
|
}
|
||||||
return val;
|
return failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* ENABLE_AES */
|
#endif /* ENABLE_AES */
|
||||||
@@ -458,7 +590,10 @@ main(int argc, char **argv)
|
|||||||
val |= string_to_key_test(context);
|
val |= string_to_key_test(context);
|
||||||
|
|
||||||
#ifdef ENABLE_AES
|
#ifdef ENABLE_AES
|
||||||
val |= encryption_test(context);
|
val |= encryption_test(context, aes_key1, 128,
|
||||||
|
encs1, sizeof(encs1)/sizeof(encs1[0]));
|
||||||
|
val |= encryption_test(context, aes_key2, 256,
|
||||||
|
encs2, sizeof(encs2)/sizeof(encs2[0]));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (verbose && val == 0)
|
if (verbose && val == 0)
|
||||||
|
Reference in New Issue
Block a user