From d0586a4f9b2c81f87ec40e06edae843f2d61ea74 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 15 Jul 2017 15:24:07 +0200 Subject: [PATCH] crypt: Remove read_ssh_u32(). It was just another implementation of read_u32_be(). This commit makes the crypto code use the helper of portable_io.h instead. --- crypt.c | 3 ++- crypt_backend.h | 1 - crypt_common.c | 26 ++------------------------ 3 files changed, 4 insertions(+), 26 deletions(-) diff --git a/crypt.c b/crypt.c index f1e42d4a..d4ffdf86 100644 --- a/crypt.c +++ b/crypt.c @@ -23,6 +23,7 @@ #include "fd.h" #include "crypt_backend.h" #include "base64.h" +#include "portable_io.h" struct asymmetric_key { RSA *rsa; @@ -96,7 +97,7 @@ static int read_bignum(const unsigned char *buf, size_t len, BIGNUM **result) return -E_BIGNUM; if (p + 4 > end) return -E_BIGNUM; - bnsize = read_ssh_u32(p); + bnsize = read_u32_be(p); PARA_DEBUG_LOG("bnsize: %u\n", bnsize); p += 4; if (p + bnsize < p) diff --git a/crypt_backend.h b/crypt_backend.h index fccdd2ef..85008979 100644 --- a/crypt_backend.h +++ b/crypt_backend.h @@ -12,6 +12,5 @@ #define AES_CRT128_BLOCK_SIZE 16 size_t is_ssh_rsa_key(char *data, size_t size); -uint32_t read_ssh_u32(const void *vp); int check_ssh_key_header(const unsigned char *blob, int blen); int check_private_key_file(const char *file); diff --git a/crypt_common.c b/crypt_common.c index 1fd8189c..ac8564eb 100644 --- a/crypt_common.c +++ b/crypt_common.c @@ -13,6 +13,7 @@ #include "string.h" #include "crypt.h" #include "crypt_backend.h" +#include "portable_io.h" /** If the key begins with this text, we treat it as an ssh key. */ #define KEY_TYPE_TXT "ssh-rsa" @@ -45,29 +46,6 @@ size_t is_ssh_rsa_key(char *data, size_t size) return cp - data; } -/** - * Read a 4-byte number from a buffer in big-endian format. - * - * \param vp The buffer. - * - * The byte-order of the buffer is expected to be big-endian, unlike read_u32() - * of portable_io.h which expects little endian. - * - * \return The 32 bit number given by \a vp. - */ -uint32_t read_ssh_u32(const void *vp) -{ - const unsigned char *p = (const unsigned char *)vp; - uint32_t v; - - v = (uint32_t)p[0] << 24; - v |= (uint32_t)p[1] << 16; - v |= (uint32_t)p[2] << 8; - v |= (uint32_t)p[3]; - - return v; -} - /** * Sanity checks for the header of an ssh key. * @@ -88,7 +66,7 @@ int check_ssh_key_header(const unsigned char *blob, int blen) if (p + 4 > end) return -E_SSH_KEY_HEADER; - rlen = read_ssh_u32(p); + rlen = read_u32_be(p); p += 4; if (p + rlen < p) return -E_SSH_KEY_HEADER; -- 2.39.2