diff options
author | Sam Hartman <hartmans@mit.edu> | 2008-12-01 16:45:10 +0000 |
---|---|---|
committer | Sam Hartman <hartmans@mit.edu> | 2008-12-01 16:45:10 +0000 |
commit | c8bf91579c10d22c46bce7849dbe63d7998a5545 (patch) | |
tree | aa3403ec4295dfd5344f3e1d0e39cf5ad4dc3a98 | |
parent | 4af46b5577611e312ee70644d4a235dbd5b8c57f (diff) | |
download | krb5-c8bf91579c10d22c46bce7849dbe63d7998a5545.zip krb5-c8bf91579c10d22c46bce7849dbe63d7998a5545.tar.gz krb5-c8bf91579c10d22c46bce7849dbe63d7998a5545.tar.bz2 |
Update t_encrypt to do some black-box testing of the iov API
git-svn-id: svn://anonsvn.mit.edu/krb5/branches/mskrb-integ-crypto-iov@21256 dc483132-0cff-0310-8789-dd5450dbe970
-rw-r--r-- | src/lib/crypto/t_encrypt.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/lib/crypto/t_encrypt.c b/src/lib/crypto/t_encrypt.c index eb2378b..ded1d8d 100644 --- a/src/lib/crypto/t_encrypt.c +++ b/src/lib/crypto/t_encrypt.c @@ -1,7 +1,7 @@ /* main * lib/crypto/t_encrypt.c * - * Copyright2001 by the Massachusetts Institute of Technology. + * Copyright 2001, 2008by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -76,12 +76,15 @@ main () { krb5_context context = 0; krb5_data in, in2, out, out2, check, check2, state; + krb5_crypto_iov iov[5]; int i; size_t len; krb5_enc_data enc_out, enc_out2; krb5_error_code retval; krb5_keyblock *key; + memset(iov, 0, sizeof(iov)); + in.data = "This is a test.\n"; in.length = strlen (in.data); in2.data = "This is another test.\n"; @@ -118,6 +121,46 @@ main () test ("Decrypting", krb5_c_decrypt (context, key, 7, 0, &enc_out, &check)); test ("Comparing", compare_results (&in, &check)); + if ( krb5_c_crypto_length(context, key->enctype, KRB5_CRYPTO_TYPE_HEADER, &len) == 0 ){ + /* We support iov/aead*/ + int j, pos; + krb5_data signdata; + signdata.data = (char *) "This should be signed"; + signdata.length = strlen(signdata.data); + iov[0].flags= KRB5_CRYPTO_TYPE_STREAM; + iov[1].flags = KRB5_CRYPTO_TYPE_DATA; + iov[0].data = enc_out.ciphertext; + iov[1].data = out; + test("IOV stream decrypting", + krb5_c_decrypt_iov( context, key, 7, 0, iov, 2)); + test("Comparing results", + compare_results(&in, &iov[1].data)); + iov[0].flags = KRB5_CRYPTO_TYPE_HEADER; + iov[1].flags = KRB5_CRYPTO_TYPE_DATA; + iov[1].data = in; /*We'll need to copy memory before encrypt*/ + iov[2].flags = KRB5_CRYPTO_TYPE_SIGN_ONLY; + iov[2].data = signdata; + iov[3].flags = KRB5_CRYPTO_TYPE_PADDING; + iov[4].flags = KRB5_CRYPTO_TYPE_TRAILER; + test("Setting up iov lengths", + krb5_c_crypto_length_iov(context, key->enctype, iov, 5)); + for (j=0,pos=0; j <= 4; j++ ){ + if (iov[j].flags == KRB5_CRYPTO_TYPE_SIGN_ONLY) + continue; + iov[j].data.data = &out.data[pos]; + pos += iov[j].data.length; + } + assert (iov[1].data.length == in.length); + memcpy(iov[1].data.data, in.data, in.length); + test("iov encrypting", + krb5_c_encrypt_iov(context, key, 7, 0, iov, 5)); + assert(iov[1].data.length == in.length); + test("iov decrypting", + krb5_c_decrypt_iov(context, key, 7, 0, iov, 5)); + test("Comparing results", + compare_results(&in, &iov[1].data)); + + } enc_out.ciphertext.length = out.length; check.length = 2048; test ("init_state", |