The branch main has been updated by cperciva:

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

commit 8ce291a335bc751e7a89691eebfb9f9da65b82ac
Author:     Colin Percival <cperc...@freebsd.org>
AuthorDate: 2024-09-18 11:02:05 +0000
Commit:     Colin Percival <cperc...@freebsd.org>
CommitDate: 2024-09-22 07:35:47 +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
---
 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 546f1d64af83..c4cecf4782ab 100644
--- a/sys/geom/eli/pkcs5v2.c
+++ b/sys/geom/eli/pkcs5v2.c
@@ -51,13 +51,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

Reply via email to