From ba388145e2a982d25fb27af1ea80231625f56ded Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 5 Sep 2009 20:38:19 +0000 Subject: [PATCH] cleaner crypto api --- src/core/gnunet-service-core.c | 6 +++--- src/include/gnunet_crypto_lib.h | 9 ++++----- src/util/crypto_aes.c | 10 ++++++---- src/util/test_crypto_aes.c | 12 ++++++------ src/util/test_crypto_aes_weak.c | 2 +- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index ec2f08f65..4012ac3a8 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c @@ -1264,10 +1264,10 @@ do_decrypt (struct Neighbour *n, return GNUNET_SYSERR; } if (size != - GNUNET_CRYPTO_aes_decrypt (&n->decrypt_key, - in, + GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, - (const struct + &n->decrypt_key, + (const struct GNUNET_CRYPTO_AesInitializationVector *) iv, out)) { diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 168c79b2a..396f47355 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -273,17 +273,16 @@ int GNUNET_CRYPTO_aes_encrypt (const void *block, /** * Decrypt a given block with the sessionkey. * - * @param sessionkey the key used to decrypt * @param block the data to decrypt, encoded as returned by encrypt * @param size how big is the block? + * @param sessionkey the key used to decrypt * @param iv the initialization vector to use * @param result address to store the result at * @return -1 on failure, size of decrypted block on success */ -int GNUNET_CRYPTO_aes_decrypt (const struct GNUNET_CRYPTO_AesSessionKey - *sessionkey, const void *block, uint16_t size, - const struct - GNUNET_CRYPTO_AesInitializationVector *iv, +int GNUNET_CRYPTO_aes_decrypt (const void *block, uint16_t size, + const struct GNUNET_CRYPTO_AesSessionKey *sessionkey, + const struct GNUNET_CRYPTO_AesInitializationVector *iv, void *result); diff --git a/src/util/crypto_aes.c b/src/util/crypto_aes.c index 28a65dfca..8fa935d9f 100644 --- a/src/util/crypto_aes.c +++ b/src/util/crypto_aes.c @@ -106,18 +106,20 @@ GNUNET_CRYPTO_aes_encrypt (const void *block, /** * Decrypt a given block with the sessionkey. - * @param sessionkey the key used to decrypt + * * @param block the data to decrypt, encoded as returned by encrypt * @param size the size of the block to decrypt + * @param sessionkey the key used to decrypt * @param iv the initialization vector to use, use INITVALUE * for streams. * @param result address to store the result at * @return -1 on failure, size of decrypted block on success */ int -GNUNET_CRYPTO_aes_decrypt (const struct GNUNET_CRYPTO_AesSessionKey - *sessionkey, const void *block, uint16_t size, - const struct GNUNET_CRYPTO_AesInitializationVector +GNUNET_CRYPTO_aes_decrypt (const void *block, uint16_t size, + const struct GNUNET_CRYPTO_AesSessionKey + *sessionkey, + const struct GNUNET_CRYPTO_AesInitializationVector *iv, void *result) { gcry_cipher_hd_t handle; diff --git a/src/util/test_crypto_aes.c b/src/util/test_crypto_aes.c index cdae243e0..f876e4175 100644 --- a/src/util/test_crypto_aes.c +++ b/src/util/test_crypto_aes.c @@ -50,9 +50,9 @@ testSymcipher () printf ("symciphertest failed: encryptBlock returned %d\n", size); return 1; } - size = GNUNET_CRYPTO_aes_decrypt (&key, - result, size, - (const struct + size = GNUNET_CRYPTO_aes_decrypt (result, size, + &key, + (const struct GNUNET_CRYPTO_AesInitializationVector *) INITVALUE, res); if (strlen (TESTSTRING) + 1 != size) @@ -131,10 +131,10 @@ verifyCrypto () res = GNUNET_malloc (GNUNET_CRYPTO_AES_KEY_LENGTH); if (GNUNET_CRYPTO_AES_KEY_LENGTH != - GNUNET_CRYPTO_aes_decrypt (&key, - result, + GNUNET_CRYPTO_aes_decrypt (result, GNUNET_CRYPTO_AES_KEY_LENGTH, - (const struct + &key, + (const struct GNUNET_CRYPTO_AesInitializationVector *) "testtesttesttest", res)) { diff --git a/src/util/test_crypto_aes_weak.c b/src/util/test_crypto_aes_weak.c index 27ee57968..2ce553a21 100644 --- a/src/util/test_crypto_aes_weak.c +++ b/src/util/test_crypto_aes_weak.c @@ -103,7 +103,7 @@ testWeakKey () return 1; } - size = GNUNET_CRYPTO_aes_decrypt (&weak_key, result, size, &INITVALUE, res); + size = GNUNET_CRYPTO_aes_decrypt (result, size, &weak_key, &INITVALUE, res); if ((strlen (WEAK_KEY_TESTSTRING) + 1) != size) { -- 2.25.1