summaryrefslogtreecommitdiff
path: root/sys/src/libauthsrv/passtokey.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2015-08-21 02:43:31 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2015-08-21 02:43:31 +0200
commit63b18e79252845d09abbad44672eabd9233a911b (patch)
treea71e5f93e01bf695bca43cc148ebf9a2c9a738c7 /sys/src/libauthsrv/passtokey.c
parente48a5832b26f817ab06db2d42f88288373b78fac (diff)
introduce AES key into nvram and keyfs
Diffstat (limited to 'sys/src/libauthsrv/passtokey.c')
-rw-r--r--sys/src/libauthsrv/passtokey.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/sys/src/libauthsrv/passtokey.c b/sys/src/libauthsrv/passtokey.c
index 44963cec6..c829b374e 100644
--- a/sys/src/libauthsrv/passtokey.c
+++ b/sys/src/libauthsrv/passtokey.c
@@ -1,9 +1,10 @@
#include <u.h>
#include <libc.h>
#include <authsrv.h>
+#include <libsec.h>
-int
-passtokey(Authkey *key, char *p)
+static void
+passtodeskey(char *key, char *p)
{
uchar buf[ANAMELEN], *t;
int i, n;
@@ -15,18 +16,33 @@ passtokey(Authkey *key, char *p)
t = buf;
strncpy((char*)t, p, n);
t[n] = 0;
- memset(key, 0, sizeof(Authkey));
+ memset(key, 0, DESKEYLEN);
for(;;){
for(i = 0; i < DESKEYLEN; i++)
- key->des[i] = (t[i] >> i) + (t[i+1] << (8 - (i+1)));
+ key[i] = (t[i] >> i) + (t[i+1] << (8 - (i+1)));
if(n <= 8)
- return 1;
+ return;
n -= 8;
t += 8;
if(n < 8){
t -= 8 - n;
n = 8;
}
- encrypt(key->des, t, 8);
+ encrypt(key, t, 8);
}
}
+
+static void
+passtoaeskey(uchar *key, char *p)
+{
+ static char salt[] = "Plan 9 key derivation";
+ pbkdf2_hmac_sha1((uchar*)p, strlen(p), (uchar*)salt, sizeof(salt)-1, 9001, key, AESKEYLEN);
+}
+
+void
+passtokey(Authkey *key, char *p)
+{
+ memset(key, 0, sizeof(Authkey));
+ passtodeskey(key->des, p);
+ passtoaeskey(key->aes, p);
+}