static void test_cts() { static const char input[4*16] = "I would like the General Gau's Chicken, please, and wonton soup."; static const unsigned char aeskey[16] = "chicken teriyaki"; static const int lengths[] = { 17, 31, 32, 47, 48, 64 }; extern krb5_error_code krb5int_aes_encrypt(const krb5_keyblock *, const krb5_data *, const krb5_data *, krb5_data *); int i; char outbuf[64], encivbuf[16], decivbuf[16], outbuf2[64]; krb5_data in, out, enciv, deciv, out2; krb5_keyblock key; krb5_error_code err; in.data = input; out.data = outbuf; out2.data = outbuf2; enciv.length = deciv.length = 16; enciv.data = encivbuf; deciv.data = decivbuf; key.contents = aeskey; key.length = 16; memset(enciv.data, 0, 16); printk("AES 128-bit key", &key); for (i = 0; i < sizeof(lengths)/sizeof(lengths[0]); i++) { memset(enciv.data, 0, 16); memset(deciv.data, 0, 16); printf("\n"); in.length = out.length = lengths[i]; printd("IV", &enciv); err = krb5int_aes_encrypt(&key, &enciv, &in, &out); if (err) { printf("error %ld from krb5int_aes_encrypt\n", (long)err); exit(1); } printd("Input", &in); printd("Output", &out); printd("Next IV", &enciv); out2.length = out.length; err = krb5int_aes_decrypt(&key, &deciv, &out, &out2); if (err) { printf("error %ld from krb5int_aes_decrypt\n", (long)err); exit(1); } if (out2.length != in.length || memcmp(in.data, out2.data, in.length)) { printd("Decryption result DOESN'T MATCH", &out2); exit(1); } if (memcmp(enciv.data, deciv.data, 16)) { printd("Decryption IV result DOESN'T MATCH", &deciv); exit(1); } } }
static void test_cts() { static const char input[4*16] = "I would like the General Gau's Chicken, please, and wonton soup."; static const unsigned char aeskey[16] = "chicken teriyaki"; static const int lengths[] = { 17, 31, 32, 47, 48, 64 }; unsigned int i; char outbuf[64], encivbuf[16], decivbuf[16]; krb5_crypto_iov iov; krb5_data in, enciv, deciv; krb5_keyblock keyblock; krb5_key key; krb5_error_code err; iov.flags = KRB5_CRYPTO_TYPE_DATA; iov.data.data = outbuf; in.data = (char *)input; enciv.length = deciv.length = 16; enciv.data = encivbuf; deciv.data = decivbuf; keyblock.contents = (krb5_octet *)aeskey; keyblock.length = 16; keyblock.enctype = ENCTYPE_AES128_CTS_HMAC_SHA1_96; err = krb5_k_create_key(NULL, &keyblock, &key); if (err) { printf("error %ld from krb5_k_create_key\n", (long)err); exit(1); } memset(enciv.data, 0, 16); printk("AES 128-bit key", &keyblock); for (i = 0; i < sizeof(lengths)/sizeof(lengths[0]); i++) { memset(enciv.data, 0, 16); memset(deciv.data, 0, 16); printf("\n"); iov.data.length = in.length = lengths[i]; memcpy(outbuf, input, lengths[i]); printd("IV", &enciv); err = krb5int_aes_encrypt(key, &enciv, &iov, 1); if (err) { printf("error %ld from krb5int_aes_encrypt\n", (long)err); exit(1); } printd("Input", &in); printd("Output", &iov.data); printd("Next IV", &enciv); err = krb5int_aes_decrypt(key, &deciv, &iov, 1); if (err) { printf("error %ld from krb5int_aes_decrypt\n", (long)err); exit(1); } if (memcmp(outbuf, input, lengths[i]) != 0) { printd("Decryption result DOESN'T MATCH", &iov.data); exit(1); } if (memcmp(enciv.data, deciv.data, 16)) { printd("Decryption IV result DOESN'T MATCH", &deciv); exit(1); } } krb5_k_free_key(NULL, key); }