crypt: Remove read_ssh_u32().
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 15 Jul 2017 13:24:07 +0000 (15:24 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 23 Jul 2017 16:01:10 +0000 (18:01 +0200)
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
crypt_backend.h
crypt_common.c

diff --git a/crypt.c b/crypt.c
index f1e42d4a228f7c0c498ac505575b6a0f3667bf27..d4ffdf864234e393b6ae1971a7714f763394780b 100644 (file)
--- a/crypt.c
+++ b/crypt.c
@@ -23,6 +23,7 @@
 #include "fd.h"
 #include "crypt_backend.h"
 #include "base64.h"
 #include "fd.h"
 #include "crypt_backend.h"
 #include "base64.h"
+#include "portable_io.h"
 
 struct asymmetric_key {
        RSA *rsa;
 
 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;
                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)
        PARA_DEBUG_LOG("bnsize: %u\n", bnsize);
        p += 4;
        if (p + bnsize < p)
index fccdd2efbda6da1f8dac7a3a4731885e4e8f7290..85008979d4b56a38c26c520bb8868da5cacc48ef 100644 (file)
@@ -12,6 +12,5 @@
 #define AES_CRT128_BLOCK_SIZE 16
 
 size_t is_ssh_rsa_key(char *data, size_t size);
 #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);
 int check_ssh_key_header(const unsigned char *blob, int blen);
 int check_private_key_file(const char *file);
index 1fd8189ca3c5a201bd2d227bb366bd800757a5a5..ac8564ebafbede53415866446ecfc78549a987de 100644 (file)
@@ -13,6 +13,7 @@
 #include "string.h"
 #include "crypt.h"
 #include "crypt_backend.h"
 #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"
 
 /** 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;
 }
 
        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.
  *
 /**
  * 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;
 
        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;
        p += 4;
        if (p + rlen < p)
                return -E_SSH_KEY_HEADER;