From 4426f95b08521cb2356a54ece0e4c803c8cab309 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 4 Jan 2009 22:13:06 +0000 Subject: added libgmp free ctr calc implementation to key derivation --- src/key_derivation.h | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'src/key_derivation.h') diff --git a/src/key_derivation.h b/src/key_derivation.h index 72037bf..1b8cd40 100644 --- a/src/key_derivation.h +++ b/src/key_derivation.h @@ -74,12 +74,51 @@ int key_derivation_generate(key_derivation_t* kd, satp_prf_label_t label, seq_nr int key_derivation_null_generate(u_int8_t* key, u_int32_t len); + +#define KD_AES_CTR_LENGTH 16 +#define KD_AES_CTR_ZERO_LENGTH 2 +#ifdef NO_LIBGMP +union __attribute__ ((__packed__)) key_derivation_aesctr_ctr_buf_union { + u_int8_t buf_[KD_AES_CTR_LENGTH]; + struct __attribute__ ((__packed__)) { + u_int8_t buf_[KD_AES_CTR_LENGTH - KD_AES_CTR_ZERO_LENGTH]; + u_int8_t zero_[KD_AES_CTR_ZERO_LENGTH]; + } salt_; +#ifndef ANYTUN_02_COMPAT + struct __attribute__ ((__packed__)) { + u_int8_t fill_[KD_AES_CTR_LENGTH - sizeof(u_int8_t) - sizeof(seq_nr_t) - KD_AES_CTR_ZERO_LENGTH]; + u_int8_t label_; + seq_nr_t r_; + u_int8_t zero_[KD_AES_CTR_ZERO_LENGTH]; + } params_; +#else + struct __attribute__ ((__packed__)) { + u_int8_t fill_[KD_AES_CTR_LENGTH - sizeof(u_int8_t) - 2 - sizeof(seq_nr_t) - KD_AES_CTR_ZERO_LENGTH]; + u_int8_t label_; + u_int8_t r_fill_[2]; + seq_nr_t r_; + u_int8_t zero_[KD_AES_CTR_ZERO_LENGTH]; + } params_; +#endif +}; +typedef union key_derivation_aesctr_ctr_buf_union key_derivation_aesctr_ctr_buf_t; + +struct key_derivation_aesctr_ctr_struct { + u_int32_t length_; + u_int8_t* buf_; + key_derivation_aesctr_ctr_buf_t ctr_; +}; +typedef struct key_derivation_aesctr_ctr_struct key_derivation_aesctr_ctr_t; +#endif + struct key_derivation_aesctr_param_struct { gcry_cipher_hd_t handle_; - buffer_t ctr_; #ifndef NO_LIBGMP + buffer_t ctr_; mpz_t mp_ctr; mpz_t mp_key_id; +#else + key_derivation_aesctr_ctr_t ctr_; #endif }; typedef struct key_derivation_aesctr_param_struct key_derivation_aesctr_param_t; -- cgit v1.2.3