diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-11-05 14:04:25 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-11-05 14:04:25 +0000 |
commit | 0bd2fd8a1ee8db6dbdd71dbfa4aa772e7cca7dbc (patch) | |
tree | abb9fcd34e431b0b24e576f3b52ec7f1359fd582 /src/util/crypto_symmetric.c | |
parent | 93f8727807901fa03fef40f795a51842799e74ea (diff) | |
download | gnunet-0bd2fd8a1ee8db6dbdd71dbfa4aa772e7cca7dbc.tar.gz gnunet-0bd2fd8a1ee8db6dbdd71dbfa4aa772e7cca7dbc.zip |
- document, alpha renaming
Diffstat (limited to 'src/util/crypto_symmetric.c')
-rw-r--r-- | src/util/crypto_symmetric.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/util/crypto_symmetric.c b/src/util/crypto_symmetric.c index f6810ec5a..a7c633656 100644 --- a/src/util/crypto_symmetric.c +++ b/src/util/crypto_symmetric.c | |||
@@ -109,50 +109,53 @@ setup_cipher_twofish (gcry_cipher_hd_t *handle, | |||
109 | 109 | ||
110 | 110 | ||
111 | /** | 111 | /** |
112 | * Encrypt a block with the public key of another | 112 | * Encrypt a block with a symmetric session key. |
113 | * host that uses the same cyper. | ||
114 | * | 113 | * |
115 | * @param block the block to encrypt | 114 | * @param block the block to encrypt |
116 | * @param len the size of the @a block | 115 | * @param size the size of the @a block |
117 | * @param sessionkey the key used to encrypt | 116 | * @param sessionkey the key used to encrypt |
118 | * @param iv the initialization vector to use, use INITVALUE | 117 | * @param iv the initialization vector to use, use INITVALUE for streams |
119 | * for streams. | ||
120 | * @param result the output parameter in which to store the encrypted result | 118 | * @param result the output parameter in which to store the encrypted result |
121 | * @returns the size of the encrypted block, -1 for errors | 119 | * can be the same or overlap with @c block |
120 | * @returns the size of the encrypted block, -1 for errors. | ||
121 | * Due to the use of CFB and therefore an effective stream cipher, | ||
122 | * this size should be the same as @c len. | ||
122 | */ | 123 | */ |
123 | ssize_t | 124 | ssize_t |
124 | GNUNET_CRYPTO_symmetric_encrypt (const void *block, | 125 | GNUNET_CRYPTO_symmetric_encrypt (const void *block, |
125 | size_t len, | 126 | size_t size, |
126 | const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, | 127 | const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, |
127 | const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, | 128 | const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, |
128 | void *result) | 129 | void *result) |
129 | { | 130 | { |
130 | gcry_cipher_hd_t handle; | 131 | gcry_cipher_hd_t handle; |
131 | char tmp[len]; | 132 | char tmp[size]; |
132 | 133 | ||
133 | if (GNUNET_OK != setup_cipher_aes (&handle, sessionkey, iv)) | 134 | if (GNUNET_OK != setup_cipher_aes (&handle, sessionkey, iv)) |
134 | return -1; | 135 | return -1; |
135 | GNUNET_assert (0 == gcry_cipher_encrypt (handle, tmp, len, block, len)); | 136 | GNUNET_assert (0 == gcry_cipher_encrypt (handle, tmp, size, block, size)); |
136 | gcry_cipher_close (handle); | 137 | gcry_cipher_close (handle); |
137 | if (GNUNET_OK != setup_cipher_twofish (&handle, sessionkey, iv)) | 138 | if (GNUNET_OK != setup_cipher_twofish (&handle, sessionkey, iv)) |
138 | return -1; | 139 | return -1; |
139 | GNUNET_assert (0 == gcry_cipher_encrypt (handle, result, len, tmp, len)); | 140 | GNUNET_assert (0 == gcry_cipher_encrypt (handle, result, size, tmp, size)); |
140 | gcry_cipher_close (handle); | 141 | gcry_cipher_close (handle); |
141 | memset (tmp, 0, sizeof (tmp)); | 142 | memset (tmp, 0, sizeof (tmp)); |
142 | return len; | 143 | return size; |
143 | } | 144 | } |
144 | 145 | ||
145 | 146 | ||
146 | /** | 147 | /** |
147 | * Decrypt a given block with the sessionkey. | 148 | * Decrypt a given block with the session key. |
148 | * | 149 | * |
149 | * @param block the data to decrypt, encoded as returned by encrypt | 150 | * @param block the data to decrypt, encoded as returned by encrypt |
150 | * @param size the size of the @a block to decrypt | 151 | * @param size the size of the @a block to decrypt |
151 | * @param sessionkey the key used to decrypt | 152 | * @param sessionkey the key used to decrypt |
152 | * @param iv the initialization vector to use, use INITVALUE | 153 | * @param iv the initialization vector to use, use INITVALUE for streams |
153 | * for streams. | ||
154 | * @param result address to store the result at | 154 | * @param result address to store the result at |
155 | * @return -1 on failure, size of decrypted block on success | 155 | * can be the same or overlap with @c block |
156 | * @return -1 on failure, size of decrypted block on success. | ||
157 | * Due to the use of CFB and therefore an effective stream cipher, | ||
158 | * this size should be the same as @c size. | ||
156 | */ | 159 | */ |
157 | ssize_t | 160 | ssize_t |
158 | GNUNET_CRYPTO_symmetric_decrypt (const void *block, size_t size, | 161 | GNUNET_CRYPTO_symmetric_decrypt (const void *block, size_t size, |