1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-06-06 13:00:58 +03:00

packet_crypt: Move secure_memcmp() to a shared source

Move the secure_memcmp() function to a shared source to make it
available internally for other crypto implementations.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Anderson Toshiyuki Sasaki 2020-12-11 12:21:48 +01:00
parent 95a4651d86
commit c3ae1336fb
4 changed files with 37 additions and 11 deletions

View File

@ -213,4 +213,6 @@ int sshkdf_derive_key(struct ssh_crypto_struct *crypto,
int key_type, unsigned char *output,
size_t requested_len);
int secure_memcmp(const void *s1, const void *s2, size_t n);
#endif /* _CRYPTO_H_ */

View File

@ -112,6 +112,7 @@ set(libssh_SRCS
config.c
connect.c
connector.c
crypto_common.c
curve25519.c
dh.c
ecdh.c

34
src/crypto_common.c Normal file
View File

@ -0,0 +1,34 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2020 by Anderson Toshiyuki Sasaki - Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include "libssh/crypto.h"
int secure_memcmp(const void *s1, const void *s2, size_t n)
{
int rc = 0;
const unsigned char *p1 = s1;
const unsigned char *p2 = s2;
for (; n > 0; --n) {
rc |= *p1++ ^ *p2++;
}
return (rc != 0);
}

View File

@ -216,17 +216,6 @@ unsigned char *ssh_packet_encrypt(ssh_session session, void *data, uint32_t len)
return crypto->hmacbuf;
}
static int secure_memcmp(const void *s1, const void *s2, size_t n)
{
int rc = 0;
const unsigned char *p1 = s1;
const unsigned char *p2 = s2;
for (; n > 0; --n) {
rc |= *p1++ ^ *p2++;
}
return (rc != 0);
}
/**
* @internal
*