diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-04-01 03:08:35 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-04-01 03:08:35 +0000 |
commit | 35f531b94febe2a91447fefaed4ea6751d55a1cb (patch) | |
tree | 3d693f00ed8018fa263e872954744c17e01e99fe /src/or/test.c | |
parent | 36ff23209bcbb438234d8c4739f6fe769d9f4ba7 (diff) | |
download | tor-35f531b94febe2a91447fefaed4ea6751d55a1cb.tar.gz tor-35f531b94febe2a91447fefaed4ea6751d55a1cb.zip |
Add helpful hybrid encryption functions
svn:r1423
Diffstat (limited to 'src/or/test.c')
-rw-r--r-- | src/or/test.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/or/test.c b/src/or/test.c index f845b157ba..18b7541f28 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -242,7 +242,7 @@ test_crypto() crypto_pk_env_t *pk1, *pk2; char *data1, *data2, *data3, *cp; FILE *f; - int i, j; + int i, j, p, len; int str_ciphers[] = { CRYPTO_CIPHER_IDENTITY, CRYPTO_CIPHER_DES, CRYPTO_CIPHER_RC4, @@ -416,6 +416,23 @@ test_crypto() pk2 = crypto_pk_asn1_decode(data1, i); test_assert(crypto_pk_cmp_keys(pk1,pk2) == 0); + /* Try with hybrid encryption wrappers. */ + crypto_rand(1024, data1); + for (i = 0; i < 3; ++i) { + for (j = 85; j < 140; ++j) { + memset(data2,0,1024); + memset(data3,0,1024); + if (i == 0 && j < 129) + continue; + p = (i==0)?RSA_NO_PADDING: + (i==1)?RSA_PKCS1_PADDING:RSA_PKCS1_OAEP_PADDING; + len = crypto_pk_public_hybrid_encrypt(pk1,data1,j,data2,p); + test_assert(len>=0); + len = crypto_pk_private_hybrid_decrypt(pk1,data2,len,data3,p); + test_eq(len,j); + test_memeq(data1,data3,j); + } + } crypto_free_pk_env(pk1); crypto_free_pk_env(pk2); |