Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 29 Sep 2024 15:25:16 GMT
From:      Colin Percival <cperciva@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 8d2d49bdb5ce - stable/14 - pkcs5v2: Add pkcs5v2_genkey_raw function
Message-ID:  <202409291525.48TFPGEC030459@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by cperciva:

URL: https://cgit.FreeBSD.org/src/commit/?id=8d2d49bdb5ce070a5e954baa59ad6a7d0e3514cd

commit 8d2d49bdb5ce070a5e954baa59ad6a7d0e3514cd
Author:     Colin Percival <cperciva@FreeBSD.org>
AuthorDate: 2024-09-18 11:02:05 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2024-09-29 15:24:52 +0000

    pkcs5v2: Add pkcs5v2_genkey_raw function
    
    This is like pkcs5v2_genkey but takes a "passphrase" as a buffer and
    length rather than a NUL-terminated string.
    
    Reviwed by:     pjd
    MFC after:      1 week
    Sponsored by:   Amazon
    Differential Revision:  https://reviews.freebsd.org/D46633
    
    (cherry picked from commit 8ce291a335bc751e7a89691eebfb9f9da65b82ac)
---
 sys/geom/eli/pkcs5v2.c | 13 +++++++++++--
 sys/geom/eli/pkcs5v2.h |  3 +++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/sys/geom/eli/pkcs5v2.c b/sys/geom/eli/pkcs5v2.c
index ea3be36865b0..4ea5ea12634a 100644
--- a/sys/geom/eli/pkcs5v2.c
+++ b/sys/geom/eli/pkcs5v2.c
@@ -52,13 +52,22 @@ void
 pkcs5v2_genkey(uint8_t *key, unsigned keylen, const uint8_t *salt,
     size_t saltsize, const char *passphrase, u_int iterations)
 {
+
+	pkcs5v2_genkey_raw(key, keylen, salt, saltsize, passphrase,
+	    strlen(passphrase), iterations);
+}
+
+void
+pkcs5v2_genkey_raw(uint8_t *key, unsigned keylen, const uint8_t *salt,
+    size_t saltsize, const uint8_t *passphrase, size_t passlen,
+    u_int iterations)
+{
 	uint8_t md[SHA512_MDLEN], saltcount[saltsize + sizeof(uint32_t)];
 	uint8_t *counter, *keyp;
-	u_int i, bsize, passlen;
+	u_int i, bsize;
 	uint32_t count;
 	struct hmac_ctx startpoint, ctx;
 
-	passlen = strlen(passphrase);
 	bzero(key, keylen);
 	bcopy(salt, saltcount, saltsize);
 	counter = saltcount + saltsize;
diff --git a/sys/geom/eli/pkcs5v2.h b/sys/geom/eli/pkcs5v2.h
index f271f17a68c1..02e3fac02fe7 100644
--- a/sys/geom/eli/pkcs5v2.h
+++ b/sys/geom/eli/pkcs5v2.h
@@ -30,6 +30,9 @@
 #define	_PKCS5V2_H_
 void pkcs5v2_genkey(uint8_t *key, unsigned keylen, const uint8_t *salt,
     size_t saltsize, const char *passphrase, u_int iterations);
+void pkcs5v2_genkey_raw(uint8_t *key, unsigned keylen, const uint8_t *salt,
+    size_t saltsize, const uint8_t *passphrase, size_t passlen,
+    u_int iterations);
 #ifndef _KERNEL
 int pkcs5v2_calculate(int usecs);
 #endif



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202409291525.48TFPGEC030459>