diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 07:43:00 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 07:43:00 +0000 |
commit | f74e883352a52dd3ed454627dc159aa65f98d7f3 (patch) | |
tree | ef77b7637e7135f0f61cad9ae9923215ed60066b /ssh-pkcs11.c | |
parent | Adding debian version 1:9.7p1-7. (diff) | |
download | openssh-f74e883352a52dd3ed454627dc159aa65f98d7f3.tar.xz openssh-f74e883352a52dd3ed454627dc159aa65f98d7f3.zip |
Merging upstream version 1:9.8p1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ssh-pkcs11.c')
-rw-r--r-- | ssh-pkcs11.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/ssh-pkcs11.c b/ssh-pkcs11.c index 35e98be..1e76e8b 100644 --- a/ssh-pkcs11.c +++ b/ssh-pkcs11.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-pkcs11.c,v 1.59 2023/07/27 22:26:49 djm Exp $ */ +/* $OpenBSD: ssh-pkcs11.c,v 1.62 2024/04/02 12:22:38 deraadt Exp $ */ /* * Copyright (c) 2010 Markus Friedl. All rights reserved. * Copyright (c) 2014 Pedro Martelletto. All rights reserved. @@ -1386,10 +1386,22 @@ pkcs11_rsa_generate_private_key(struct pkcs11_provider *p, CK_ULONG slotidx, } static int +h2i(char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + else if (c >= 'a' && c <= 'f') + return c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + return c - 'A' + 10; + else + return -1; +} + +static int pkcs11_decode_hex(const char *hex, unsigned char **dest, size_t *rlen) { size_t i, len; - char ptr[3]; if (dest) *dest = NULL; @@ -1402,13 +1414,14 @@ pkcs11_decode_hex(const char *hex, unsigned char **dest, size_t *rlen) *dest = xmalloc(len); - ptr[2] = '\0'; for (i = 0; i < len; i++) { - ptr[0] = hex[2 * i]; - ptr[1] = hex[(2 * i) + 1]; - if (!isxdigit(ptr[0]) || !isxdigit(ptr[1])) + int hi, low; + + hi = h2i(hex[2 * i]); + lo = h2i(hex[(2 * i) + 1]); + if (hi == -1 || lo == -1) return -1; - (*dest)[i] = (unsigned char)strtoul(ptr, NULL, 16); + (*dest)[i] = (hi << 4) | lo; } if (rlen) |