summaryrefslogtreecommitdiff
path: root/src/key_derivation.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-01-06 01:30:00 +0000
committerChristian Pointner <equinox@anytun.org>2009-01-06 01:30:00 +0000
commit749c7bd9adc37d4e1cfc4d2a570fdcde0e20c3c8 (patch)
tree5790c95aa9320b9e5eed10bfa5cbe79d60ef4ce3 /src/key_derivation.c
parentadded libssl crypto based auth algo HMAC-Sha1 (diff)
some cleanup
added option for passphrase enabled option for kd-prf
Diffstat (limited to 'src/key_derivation.c')
-rw-r--r--src/key_derivation.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/key_derivation.c b/src/key_derivation.c
index af3228d..9f16467 100644
--- a/src/key_derivation.c
+++ b/src/key_derivation.c
@@ -41,16 +41,28 @@
#include <stdlib.h>
#include <string.h>
-int key_derivation_init(key_derivation_t* kd, const char* type, int8_t ld_kdr, u_int8_t* key, u_int32_t key_len, u_int8_t* salt, u_int32_t salt_len)
+int key_derivation_init(key_derivation_t* kd, const char* type, int8_t ld_kdr, const char* passphrase, u_int8_t* key, u_int32_t key_len, u_int8_t* salt, u_int32_t salt_len)
{
if(!kd)
return -1;
+ kd->key_length_ = 0;
+
kd->type_ = kd_unknown;
if(!strcmp(type, "null"))
kd->type_ = kd_null;
- else if(!strcmp(type, "aes-ctr"))
+ else if(!strncmp(type, "aes-ctr", 7)) {
kd->type_ = kd_aes_ctr;
+ if(type[7] == 0) {
+ kd->key_length_ = KD_AESCTR_DEFAULT_KEY_LENGTH;
+ }
+ else if(type[7] != '-')
+ return -1;
+ else {
+ const char* tmp = &type[8];
+ kd->key_length_ = atoi(tmp);
+ }
+ }
else {
log_printf(ERR, "unknown key derivation type");
return -1;
@@ -60,7 +72,6 @@ int key_derivation_init(key_derivation_t* kd, const char* type, int8_t ld_kdr, u
if(ld_kdr > (int8_t)(sizeof(seq_nr_t) * 8))
kd->ld_kdr_ = sizeof(seq_nr_t) * 8;
- kd->key_length_ = key_len * sizeof(key[0]) * 8;
kd->params_ = NULL;
int i;
@@ -99,7 +110,7 @@ int key_derivation_init(key_derivation_t* kd, const char* type, int8_t ld_kdr, u
int ret = 0;
if(kd->type_ == kd_aes_ctr)
- ret = key_derivation_aesctr_init(kd);
+ ret = key_derivation_aesctr_init(kd, passphrase);
if(ret)
key_derivation_close(kd);
@@ -107,6 +118,18 @@ int key_derivation_init(key_derivation_t* kd, const char* type, int8_t ld_kdr, u
return ret;
}
+int key_derivation_generate_master_key(key_derivation_t* kd, const char* passphrase, u_int16_t key_length)
+{
+
+ return 0;
+}
+
+int key_derivation_generate_master_salt(key_derivation_t* kd, const char* passphrase, u_int16_t salt_length)
+{
+
+ return 0;
+}
+
void key_derivation_close(key_derivation_t* kd)
{
if(!kd)
@@ -159,7 +182,7 @@ int key_derivation_null_generate(u_int8_t* key, u_int32_t len)
/* ---------------- AES-Ctr Key Derivation ---------------- */
-int key_derivation_aesctr_init(key_derivation_t* kd)
+int key_derivation_aesctr_init(key_derivation_t* kd, const char* passphrase)
{
if(!kd)
return -1;
@@ -173,6 +196,8 @@ int key_derivation_aesctr_init(key_derivation_t* kd)
key_derivation_aesctr_param_t* params = kd->params_;
#ifndef USE_SSL_CRYPTO
+ params->handle_ = 0;
+
int algo;
switch(kd->key_length_) {
case 128: algo = GCRY_CIPHER_AES128; break;