aboutsummaryrefslogtreecommitdiffstats
path: root/src/pluto/crypto.c
diff options
context:
space:
mode:
authorAndreas Steffen <andreas.steffen@strongswan.org>2009-05-06 22:46:51 +0200
committerAndreas Steffen <andreas.steffen@strongswan.org>2009-05-06 22:46:51 +0200
commit38a7792d8a7797abe945f4ff938afefa1af5bc5e (patch)
tree7752dabf477f0a9a286c96507ca6955dfa75b424 /src/pluto/crypto.c
parentab87051f235f580761d6a6dc21ca014a0a1f9261 (diff)
downloadstrongswan-38a7792d8a7797abe945f4ff938afefa1af5bc5e.tar.bz2
strongswan-38a7792d8a7797abe945f4ff938afefa1af5bc5e.tar.xz
removed all hash function code from pluto
Diffstat (limited to 'src/pluto/crypto.c')
-rw-r--r--src/pluto/crypto.c80
1 files changed, 5 insertions, 75 deletions
diff --git a/src/pluto/crypto.c b/src/pluto/crypto.c
index 6a885b885..579e257f2 100644
--- a/src/pluto/crypto.c
+++ b/src/pluto/crypto.c
@@ -24,6 +24,8 @@
#include <errno.h>
+#include <crypto/hashers/hasher.h>
+
#include "constants.h"
#include "defs.h"
#include "state.h"
@@ -298,14 +300,9 @@ static struct hash_desc crypto_hasher_md5 =
algo_type: IKE_ALG_HASH,
algo_id: OAKLEY_MD5,
algo_next: NULL,
- hash_ctx_size: sizeof(MD5_CTX),
- hash_block_size: MD5_BLOCK_SIZE,
- hash_digest_size: MD5_DIGEST_SIZE,
+ hash_digest_size: HASH_SIZE_MD5,
hash_testvectors: md5_hash_testvectors,
hmac_testvectors: md5_hmac_testvectors,
- hash_init: (void (*)(void *)) MD5Init,
- hash_update: (void (*)(void *, const u_int8_t *, size_t)) MD5Update,
- hash_final: (void (*)(u_char *, void *)) MD5Final
};
/* SHA-1 test vectors
@@ -439,14 +436,9 @@ static struct hash_desc crypto_hasher_sha1 =
algo_type: IKE_ALG_HASH,
algo_id: OAKLEY_SHA,
algo_next: NULL,
- hash_ctx_size: sizeof(SHA1_CTX),
- hash_block_size: SHA1_BLOCK_SIZE,
- hash_digest_size: SHA1_DIGEST_SIZE,
+ hash_digest_size: HASH_SIZE_SHA1,
hash_testvectors: sha1_hash_testvectors,
- hmac_testvectors: sha1_hmac_testvectors,
- hash_init: (void (*)(void *)) SHA1Init,
- hash_update: (void (*)(void *, const u_int8_t *, size_t)) SHA1Update,
- hash_final: (void (*)(u_char *, void *)) SHA1Final
+ hmac_testvectors: sha1_hmac_testvectors
};
void init_crypto(void)
@@ -565,68 +557,6 @@ void crypto_cbc_encrypt(const struct encrypt_desc *e, bool enc, u_int8_t *buf,
*/
}
-/* HMAC package
- * rfc2104.txt specifies how HMAC works.
- */
-
-void hmac_init(struct hmac_ctx *ctx, const struct hash_desc *h,
- const u_char *key, size_t key_len)
-{
- int k;
-
- ctx->h = h;
- ctx->hmac_digest_size = h->hash_digest_size;
-
- /* Prepare the two pads for the HMAC */
-
- memset(ctx->buf1, '\0', h->hash_block_size);
-
- if (key_len <= h->hash_block_size)
- {
- memcpy(ctx->buf1, key, key_len);
- }
- else
- {
- h->hash_init(&ctx->hash_ctx);
- h->hash_update(&ctx->hash_ctx, key, key_len);
- h->hash_final(ctx->buf1, &ctx->hash_ctx);
- }
-
- memcpy(ctx->buf2, ctx->buf1, h->hash_block_size);
-
- for (k = 0; k < h->hash_block_size; k++)
- {
- ctx->buf1[k] ^= HMAC_IPAD;
- ctx->buf2[k] ^= HMAC_OPAD;
- }
-
- hmac_reinit(ctx);
-}
-
-void hmac_reinit(struct hmac_ctx *ctx)
-{
- ctx->h->hash_init(&ctx->hash_ctx);
- ctx->h->hash_update(&ctx->hash_ctx, ctx->buf1, ctx->h->hash_block_size);
-}
-
-void hmac_update(struct hmac_ctx *ctx,
- const u_char *data, size_t data_len)
-{
- ctx->h->hash_update(&ctx->hash_ctx, data, data_len);
-}
-
-void hmac_final(u_char *output, struct hmac_ctx *ctx)
-{
- const struct hash_desc *h = ctx->h;
-
- h->hash_final(output, &ctx->hash_ctx);
-
- h->hash_init(&ctx->hash_ctx);
- h->hash_update(&ctx->hash_ctx, ctx->buf2, h->hash_block_size);
- h->hash_update(&ctx->hash_ctx, output, h->hash_digest_size);
- h->hash_final(output, &ctx->hash_ctx);
-}
-
hash_algorithm_t oakley_to_hash_algorithm(int alg)
{
switch (alg)