summaryrefslogtreecommitdiff
path: root/src/pluto/alg/ike_alg_blowfish.c
blob: 2bbef051b2f683511ea747cb126a21ef19efdd8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <sys/types.h>
#include <freeswan.h>

#include "constants.h"
#include "defs.h"
#include "log.h"
#include "libblowfish/blowfish.h"
#include "alg_info.h"
#include "ike_alg.h"

#define  BLOWFISH_CBC_BLOCK_SIZE	8  	/* block size */
#define  BLOWFISH_KEY_MIN_LEN	128
#define  BLOWFISH_KEY_MAX_LEN	448


static void
do_blowfish(u_int8_t *buf, size_t buf_len, u_int8_t *key, size_t key_size, u_int8_t *iv, bool enc)
{
    BF_KEY bf_ctx;

    BF_set_key(&bf_ctx, key_size , key);
    BF_cbc_encrypt(buf, buf, buf_len, &bf_ctx, iv, enc);
}

struct encrypt_desc algo_blowfish =
{
	algo_type: IKE_ALG_ENCRYPT,
	algo_id:   OAKLEY_BLOWFISH_CBC,
	algo_next: NULL, 
	enc_ctxsize: sizeof(BF_KEY),
	enc_blocksize: BLOWFISH_CBC_BLOCK_SIZE,
	keyminlen: BLOWFISH_KEY_MIN_LEN,
	keydeflen: BLOWFISH_KEY_MIN_LEN,
	keymaxlen: BLOWFISH_KEY_MAX_LEN,
	do_crypt: do_blowfish,
};

int ike_alg_blowfish_init(void);

int
ike_alg_blowfish_init(void)
{
    int ret = ike_alg_register_enc(&algo_blowfish);

    return ret;
}
/*
IKE_ALG_INIT_NAME: ike_alg_blowfish_init
*/