10 #include "libserpent/serpent_cbc.h"
14 #define SERPENT_CBC_BLOCK_SIZE (128/BITS_PER_BYTE)
15 #define SERPENT_KEY_MIN_LEN 128
16 #define SERPENT_KEY_DEF_LEN 128
17 #define SERPENT_KEY_MAX_LEN 256
20 do_serpent(u_int8_t
*buf
, size_t buf_size
, u_int8_t
*key
, size_t key_size
, u_int8_t
*iv
, bool enc
)
22 serpent_context serpent_ctx
;
23 char iv_bak
[SERPENT_CBC_BLOCK_SIZE
];
24 char *new_iv
= NULL
; /* logic will avoid copy to NULL */
27 serpent_set_key(&serpent_ctx
, key
, key_size
);
29 * my SERPENT cbc does not touch passed IV (optimization for
30 * ESP handling), so I must "emulate" des-like IV
35 (char*) buf
+ buf_size
-SERPENT_CBC_BLOCK_SIZE
,
36 SERPENT_CBC_BLOCK_SIZE
);
38 serpent_cbc_encrypt(&serpent_ctx
, buf
, buf
, buf_size
, iv
, enc
);
41 new_iv
= (char*) buf
+ buf_size
-SERPENT_CBC_BLOCK_SIZE
;
43 memcpy(iv
, new_iv
, SERPENT_CBC_BLOCK_SIZE
);
46 struct encrypt_desc encrypt_desc_serpent
=
48 algo_type
: IKE_ALG_ENCRYPT
,
49 algo_id
: OAKLEY_SERPENT_CBC
,
51 enc_ctxsize
: sizeof(struct serpent_context
),
52 enc_blocksize
: SERPENT_CBC_BLOCK_SIZE
,
53 keyminlen
: SERPENT_KEY_MIN_LEN
,
54 keydeflen
: SERPENT_KEY_DEF_LEN
,
55 keymaxlen
: SERPENT_KEY_MAX_LEN
,
59 int ike_alg_serpent_init(void);
62 ike_alg_serpent_init(void)
64 int ret
= ike_alg_register_enc(&encrypt_desc_serpent
);
69 IKE_ALG_INIT_NAME: ike_alg_serpent_init