mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-27 13:21:11 +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:
@@ -213,4 +213,6 @@ int sshkdf_derive_key(struct ssh_crypto_struct *crypto,
|
|||||||
int key_type, unsigned char *output,
|
int key_type, unsigned char *output,
|
||||||
size_t requested_len);
|
size_t requested_len);
|
||||||
|
|
||||||
|
int secure_memcmp(const void *s1, const void *s2, size_t n);
|
||||||
|
|
||||||
#endif /* _CRYPTO_H_ */
|
#endif /* _CRYPTO_H_ */
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ set(libssh_SRCS
|
|||||||
config.c
|
config.c
|
||||||
connect.c
|
connect.c
|
||||||
connector.c
|
connector.c
|
||||||
|
crypto_common.c
|
||||||
curve25519.c
|
curve25519.c
|
||||||
dh.c
|
dh.c
|
||||||
ecdh.c
|
ecdh.c
|
||||||
|
|||||||
34
src/crypto_common.c
Normal file
34
src/crypto_common.c
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -216,17 +216,6 @@ unsigned char *ssh_packet_encrypt(ssh_session session, void *data, uint32_t len)
|
|||||||
return crypto->hmacbuf;
|
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
|
* @internal
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user