(no commit message)
[strongswan.git] / src / pluto / alg / ike_alg_sha2.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stddef.h>
4 #include <sys/types.h>
5 #include <freeswan.h>
6
7 #include "constants.h"
8 #include "defs.h"
9 #include "log.h"
10 #include "libsha2/sha2.h"
11 #include "alg_info.h"
12 #include "ike_alg.h"
13
14 #define SHA2_256_DIGEST_SIZE (256/BITS_PER_BYTE)
15 #define SHA2_512_DIGEST_SIZE (512/BITS_PER_BYTE)
16
17 static void sha256_hash_final(u_char *hash, sha256_context *ctx)
18 {
19 sha256_final(ctx);
20 memcpy(hash, &ctx->sha_out[0], SHA2_256_DIGEST_SIZE);
21 }
22 static void sha512_hash_final(u_char *hash, sha512_context *ctx)
23 {
24 sha512_final(ctx);
25 memcpy(hash, &ctx->sha_out[0], SHA2_512_DIGEST_SIZE);
26 }
27 struct hash_desc hash_desc_sha2_256 = {
28 algo_type: IKE_ALG_HASH,
29 algo_id: OAKLEY_SHA2_256,
30 algo_next: NULL,
31 hash_ctx_size: sizeof(sha256_context),
32 hash_init: (void (*)(void *))sha256_init,
33 hash_update: (void (*)(void *, const u_char *, size_t ))sha256_write,
34 hash_final:(void (*)(u_char *, void *))sha256_hash_final,
35 hash_digest_size: SHA2_256_DIGEST_SIZE,
36 };
37 struct hash_desc hash_desc_sha2_512 = {
38 algo_type: IKE_ALG_HASH,
39 algo_id: OAKLEY_SHA2_512,
40 algo_next: NULL,
41 hash_ctx_size: sizeof(sha512_context),
42 hash_init: (void (*)(void *))sha512_init,
43 hash_update: (void (*)(void *, const u_char *, size_t ))sha512_write,
44 hash_final:(void (*)(u_char *, void *))sha512_hash_final,
45 hash_digest_size: SHA2_512_DIGEST_SIZE,
46 };
47 int ike_alg_sha2_init(void);
48 int
49 ike_alg_sha2_init(void)
50 {
51 int ret;
52 ret = ike_alg_register_hash(&hash_desc_sha2_256);
53 if (ret)
54 goto out;
55 ret = ike_alg_register_hash(&hash_desc_sha2_512);
56 out:
57 return ret;
58 }
59 /*
60 IKE_ALG_INIT_NAME: ike_alg_sha2_init
61 */