shithub: riscv

Download patch

ref: 4cf00ca6cb40918c8ca89aebf02e8ca41c857e94
parent: 69fab298beee33e4a6f91d9e1811dfa1898aa743
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Sep 13 22:26:26 EDT 2014

libsec: fix hmac for keys bigger then 64 byte block size

RFC2104 defines HMAC for keys bigger than the 64 byte block
size as follows:

Applications that use keys longer than B (64) bytes will
first hash the key using H (the hash function) and then
use the resultant L byte string as the actual key to HMAC.

--- a/sys/src/libsec/port/hmac.c
+++ b/sys/src/libsec/port/hmac.c
@@ -11,8 +11,13 @@
 
 	if(xlen > sizeof(innerdigest))
 		return nil;
-	if(klen > Hmacblksz)
-		return nil;
+	if(klen > Hmacblksz){
+		if(xlen > Hmacblksz)
+			return nil;
+		(*x)(key, klen, innerdigest, nil);
+		key = innerdigest;
+		klen = xlen;
+	}
 
 	/* first time through */
 	if(s == nil || s->seeded == 0){