mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-20 02:42:09 +03:00
src: fix checksrc warnings
Use checksrc.pl from the curl project, with (for now) suppressed long line warnings and indentation set to 4 spaces. Fixes are whitespace for the most part. Warning count went down from 2704 to 12. Also fix codespell typos, two non-ANSI C89 comments and a stray tab in include/libssh2.h. Ref: https://github.com/libssh2/libssh2/pull/235
This commit is contained in:
286
src/openssl.c
286
src/openssl.c
@@ -59,7 +59,7 @@ write_bn(unsigned char *buf, const BIGNUM *bn, int bn_bytes)
|
||||
|
||||
*p = 0;
|
||||
BN_bn2bin(bn, p + 1);
|
||||
if (!(*(p + 1) & 0x80)) {
|
||||
if(!(*(p + 1) & 0x80)) {
|
||||
memmove(p, p + 1, --bn_bytes);
|
||||
}
|
||||
_libssh2_htonu32(p - 4, bn_bytes); /* Post write bn size. */
|
||||
@@ -100,7 +100,7 @@ _libssh2_rsa_new(libssh2_rsa_ctx ** rsa,
|
||||
n = BN_new();
|
||||
BN_bin2bn(ndata, nlen, n);
|
||||
|
||||
if (ddata) {
|
||||
if(ddata) {
|
||||
d = BN_new();
|
||||
BN_bin2bn(ddata, dlen, d);
|
||||
|
||||
@@ -154,7 +154,7 @@ _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsactx,
|
||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
||||
int ret;
|
||||
|
||||
if (_libssh2_sha1(m, m_len, hash))
|
||||
if(_libssh2_sha1(m, m_len, hash))
|
||||
return -1; /* failure */
|
||||
ret = RSA_verify(NID_sha1, hash, SHA_DIGEST_LENGTH,
|
||||
(unsigned char *) sig, sig_len, rsactx);
|
||||
@@ -192,7 +192,7 @@ _libssh2_dsa_new(libssh2_dsa_ctx ** dsactx,
|
||||
pub_key = BN_new();
|
||||
BN_bin2bn(y, y_len, pub_key);
|
||||
|
||||
if (x_len) {
|
||||
if(x_len) {
|
||||
priv_key = BN_new();
|
||||
BN_bin2bn(x, x_len, priv_key);
|
||||
}
|
||||
@@ -239,7 +239,7 @@ _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx,
|
||||
dsasig->r = r;
|
||||
dsasig->s = s;
|
||||
#endif
|
||||
if (!_libssh2_sha1(m, m_len, hash))
|
||||
if(!_libssh2_sha1(m, m_len, hash))
|
||||
/* _libssh2_sha1() succeeded */
|
||||
ret = DSA_do_verify(hash, SHA_DIGEST_LENGTH, dsasig, dsactx);
|
||||
|
||||
@@ -276,20 +276,20 @@ _libssh2_ecdsa_curve_type_from_name(const char *name, libssh2_curve_type *out_ty
|
||||
int ret = 0;
|
||||
libssh2_curve_type type;
|
||||
|
||||
if ( name == NULL || strlen(name) != 19 )
|
||||
if(name == NULL || strlen(name) != 19)
|
||||
return -1;
|
||||
|
||||
if ( strcmp(name, "ecdsa-sha2-nistp256") == 0)
|
||||
if(strcmp(name, "ecdsa-sha2-nistp256") == 0)
|
||||
type = LIBSSH2_EC_CURVE_NISTP256;
|
||||
else if ( strcmp(name, "ecdsa-sha2-nistp384") == 0)
|
||||
else if(strcmp(name, "ecdsa-sha2-nistp384") == 0)
|
||||
type = LIBSSH2_EC_CURVE_NISTP384;
|
||||
else if ( strcmp(name, "ecdsa-sha2-nistp521") == 0)
|
||||
else if(strcmp(name, "ecdsa-sha2-nistp521") == 0)
|
||||
type = LIBSSH2_EC_CURVE_NISTP521;
|
||||
else {
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
if (ret == 0 && out_type) {
|
||||
if(ret == 0 && out_type) {
|
||||
*out_type = type;
|
||||
}
|
||||
|
||||
@@ -313,16 +313,16 @@ _libssh2_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx ** ec_ctx,
|
||||
EC_KEY *ec_key = EC_KEY_new_by_curve_name(curve);
|
||||
EC_POINT *point = NULL;
|
||||
|
||||
if ( ec_key ) {
|
||||
if(ec_key) {
|
||||
ec_group = EC_KEY_get0_group(ec_key);
|
||||
point = EC_POINT_new(ec_group);
|
||||
ret = EC_POINT_oct2point(ec_group, point, k, k_len, NULL);
|
||||
ret = EC_KEY_set_public_key(ec_key, point);
|
||||
|
||||
if (point != NULL)
|
||||
if(point != NULL)
|
||||
EC_POINT_free(point);
|
||||
|
||||
if ( ec_ctx != NULL )
|
||||
if(ec_ctx != NULL)
|
||||
*ec_ctx = ec_key;
|
||||
}
|
||||
|
||||
@@ -366,16 +366,18 @@ _libssh2_ecdsa_verify(libssh2_ecdsa_ctx * ctx,
|
||||
BN_bin2bn(s, s_len, ecdsa_sig_.s);
|
||||
#endif
|
||||
|
||||
if ( type == LIBSSH2_EC_CURVE_NISTP256 ) {
|
||||
if(type == LIBSSH2_EC_CURVE_NISTP256) {
|
||||
LIBSSH2_ECDSA_VERIFY(256);
|
||||
}else if ( type == LIBSSH2_EC_CURVE_NISTP384 ) {
|
||||
}
|
||||
else if(type == LIBSSH2_EC_CURVE_NISTP384) {
|
||||
LIBSSH2_ECDSA_VERIFY(384);
|
||||
}else if ( type == LIBSSH2_EC_CURVE_NISTP521 ) {
|
||||
}
|
||||
else if(type == LIBSSH2_EC_CURVE_NISTP521) {
|
||||
LIBSSH2_ECDSA_VERIFY(512);
|
||||
}
|
||||
|
||||
#if HAVE_OPAQUE_STRUCTS
|
||||
if ( ecdsa_sig )
|
||||
if(ecdsa_sig)
|
||||
ECDSA_SIG_free(ecdsa_sig);
|
||||
#else
|
||||
BN_clear_free(ecdsa_sig_.s);
|
||||
@@ -416,7 +418,7 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx,
|
||||
#else
|
||||
ret = EVP_Cipher(ctx, buf, block, blocksize);
|
||||
#endif
|
||||
if (ret == 1) {
|
||||
if(ret == 1) {
|
||||
memcpy(block, buf, blocksize);
|
||||
}
|
||||
return ret == 1 ? 0 : 1;
|
||||
@@ -446,7 +448,7 @@ aes_ctr_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
const EVP_CIPHER *aes_cipher;
|
||||
(void) enc;
|
||||
|
||||
switch (EVP_CIPHER_CTX_key_length(ctx)) {
|
||||
switch(EVP_CIPHER_CTX_key_length(ctx)) {
|
||||
case 16:
|
||||
aes_cipher = EVP_aes_128_ecb();
|
||||
break;
|
||||
@@ -461,7 +463,7 @@ aes_ctr_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
}
|
||||
|
||||
c = malloc(sizeof(*c));
|
||||
if (c == NULL)
|
||||
if(c == NULL)
|
||||
return 0;
|
||||
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
@@ -469,12 +471,12 @@ aes_ctr_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
#else
|
||||
c->aes_ctx = malloc(sizeof(EVP_CIPHER_CTX));
|
||||
#endif
|
||||
if (c->aes_ctx == NULL) {
|
||||
if(c->aes_ctx == NULL) {
|
||||
free(c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (EVP_EncryptInit(c->aes_ctx, aes_cipher, key, NULL) != 1) {
|
||||
if(EVP_EncryptInit(c->aes_ctx, aes_cipher, key, NULL) != 1) {
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
EVP_CIPHER_CTX_free(c->aes_ctx);
|
||||
#else
|
||||
@@ -502,10 +504,10 @@ aes_ctr_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
unsigned char b1[AES_BLOCK_SIZE];
|
||||
int outlen = 0;
|
||||
|
||||
if (inl != 16) /* libssh2 only ever encrypt one block */
|
||||
if(inl != 16) /* libssh2 only ever encrypt one block */
|
||||
return 0;
|
||||
|
||||
if (c == NULL) {
|
||||
if(c == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -516,7 +518,7 @@ aes_ctr_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
the ciphertext block C1. The counter X is then incremented
|
||||
*/
|
||||
|
||||
if (EVP_EncryptUpdate(c->aes_ctx, b1, &outlen, c->ctr, AES_BLOCK_SIZE) != 1) {
|
||||
if(EVP_EncryptUpdate(c->aes_ctx, b1, &outlen, c->ctr, AES_BLOCK_SIZE) != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -531,11 +533,11 @@ aes_ctr_cleanup(EVP_CIPHER_CTX *ctx) /* cleanup ctx */
|
||||
{
|
||||
aes_ctr_ctx *c = EVP_CIPHER_CTX_get_app_data(ctx);
|
||||
|
||||
if (c == NULL) {
|
||||
if(c == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (c->aes_ctx != NULL) {
|
||||
if(c->aes_ctx != NULL) {
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
EVP_CIPHER_CTX_free(c->aes_ctx);
|
||||
#else
|
||||
@@ -554,7 +556,7 @@ make_ctr_evp (size_t keylen, EVP_CIPHER *aes_ctr_cipher, int type)
|
||||
{
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
aes_ctr_cipher = EVP_CIPHER_meth_new(type, 16, keylen);
|
||||
if (aes_ctr_cipher) {
|
||||
if(aes_ctr_cipher) {
|
||||
EVP_CIPHER_meth_set_iv_length(aes_ctr_cipher, 16);
|
||||
EVP_CIPHER_meth_set_init(aes_ctr_cipher, aes_ctr_init);
|
||||
EVP_CIPHER_meth_set_do_cipher(aes_ctr_cipher, aes_ctr_do_cipher);
|
||||
@@ -578,12 +580,12 @@ _libssh2_EVP_aes_128_ctr(void)
|
||||
{
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
static EVP_CIPHER * aes_ctr_cipher;
|
||||
return !aes_ctr_cipher?
|
||||
make_ctr_evp (16, aes_ctr_cipher, NID_aes_128_ctr) : aes_ctr_cipher;
|
||||
return !aes_ctr_cipher ?
|
||||
make_ctr_evp(16, aes_ctr_cipher, NID_aes_128_ctr) : aes_ctr_cipher;
|
||||
#else
|
||||
static EVP_CIPHER aes_ctr_cipher;
|
||||
return !aes_ctr_cipher.key_len?
|
||||
make_ctr_evp (16, &aes_ctr_cipher, 0) : &aes_ctr_cipher;
|
||||
return !aes_ctr_cipher.key_len ?
|
||||
make_ctr_evp(16, &aes_ctr_cipher, 0) : &aes_ctr_cipher;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -592,12 +594,12 @@ _libssh2_EVP_aes_192_ctr(void)
|
||||
{
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
static EVP_CIPHER * aes_ctr_cipher;
|
||||
return !aes_ctr_cipher?
|
||||
make_ctr_evp (24, aes_ctr_cipher, NID_aes_192_ctr) : aes_ctr_cipher;
|
||||
return !aes_ctr_cipher ?
|
||||
make_ctr_evp(24, aes_ctr_cipher, NID_aes_192_ctr) : aes_ctr_cipher;
|
||||
#else
|
||||
static EVP_CIPHER aes_ctr_cipher;
|
||||
return !aes_ctr_cipher.key_len?
|
||||
make_ctr_evp (24, &aes_ctr_cipher, 0) : &aes_ctr_cipher;
|
||||
return !aes_ctr_cipher.key_len ?
|
||||
make_ctr_evp(24, &aes_ctr_cipher, 0) : &aes_ctr_cipher;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -606,12 +608,12 @@ _libssh2_EVP_aes_256_ctr(void)
|
||||
{
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
static EVP_CIPHER * aes_ctr_cipher;
|
||||
return !aes_ctr_cipher?
|
||||
make_ctr_evp (32, aes_ctr_cipher, NID_aes_256_ctr) : aes_ctr_cipher;
|
||||
return !aes_ctr_cipher ?
|
||||
make_ctr_evp(32, aes_ctr_cipher, NID_aes_256_ctr) : aes_ctr_cipher;
|
||||
#else
|
||||
static EVP_CIPHER aes_ctr_cipher;
|
||||
return !aes_ctr_cipher.key_len?
|
||||
make_ctr_evp (32, &aes_ctr_cipher, 0) : &aes_ctr_cipher;
|
||||
return !aes_ctr_cipher.key_len ?
|
||||
make_ctr_evp(32, &aes_ctr_cipher, 0) : &aes_ctr_cipher;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -635,7 +637,7 @@ passphrase_cb(char *buf, int size, int rwflag, char *passphrase)
|
||||
int passphrase_len = strlen(passphrase);
|
||||
(void) rwflag;
|
||||
|
||||
if (passphrase_len > (size - 1)) {
|
||||
if(passphrase_len > (size - 1)) {
|
||||
passphrase_len = size - 1;
|
||||
}
|
||||
memcpy(buf, passphrase, passphrase_len);
|
||||
@@ -645,12 +647,12 @@ passphrase_cb(char *buf, int size, int rwflag, char *passphrase)
|
||||
}
|
||||
|
||||
typedef void * (*pem_read_bio_func)(BIO *, void **, pem_password_cb *,
|
||||
void * u);
|
||||
void *u);
|
||||
|
||||
static int
|
||||
read_private_key_from_memory(void ** key_ctx,
|
||||
read_private_key_from_memory(void **key_ctx,
|
||||
pem_read_bio_func read_private_key,
|
||||
const char * filedata,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
unsigned const char *passphrase)
|
||||
{
|
||||
@@ -659,7 +661,7 @@ read_private_key_from_memory(void ** key_ctx,
|
||||
*key_ctx = NULL;
|
||||
|
||||
bp = BIO_new_mem_buf((char *)filedata, filedata_len);
|
||||
if (!bp) {
|
||||
if(!bp) {
|
||||
return -1;
|
||||
}
|
||||
*key_ctx = read_private_key(bp, NULL, (pem_password_cb *) passphrase_cb,
|
||||
@@ -670,9 +672,9 @@ read_private_key_from_memory(void ** key_ctx,
|
||||
}
|
||||
|
||||
static int
|
||||
read_private_key_from_file(void ** key_ctx,
|
||||
read_private_key_from_file(void **key_ctx,
|
||||
pem_read_bio_func read_private_key,
|
||||
const char * filename,
|
||||
const char *filename,
|
||||
unsigned const char *passphrase)
|
||||
{
|
||||
BIO * bp;
|
||||
@@ -680,7 +682,7 @@ read_private_key_from_file(void ** key_ctx,
|
||||
*key_ctx = NULL;
|
||||
|
||||
bp = BIO_new_file(filename, "r");
|
||||
if (!bp) {
|
||||
if(!bp) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -716,7 +718,7 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa,
|
||||
(pem_read_bio_func) &PEM_read_bio_RSAPrivateKey;
|
||||
(void) session;
|
||||
|
||||
_libssh2_init_if_needed ();
|
||||
_libssh2_init_if_needed();
|
||||
|
||||
return read_private_key_from_file((void **) rsa, read_rsa,
|
||||
filename, passphrase);
|
||||
@@ -748,7 +750,7 @@ _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa,
|
||||
(pem_read_bio_func) &PEM_read_bio_DSAPrivateKey;
|
||||
(void) session;
|
||||
|
||||
_libssh2_init_if_needed ();
|
||||
_libssh2_init_if_needed();
|
||||
|
||||
return read_private_key_from_file((void **) dsa, read_dsa,
|
||||
filename, passphrase);
|
||||
@@ -781,7 +783,7 @@ _libssh2_ecdsa_new_private(libssh2_ecdsa_ctx ** ec_ctx,
|
||||
pem_read_bio_func read_ec = (pem_read_bio_func) &PEM_read_bio_ECPrivateKey;
|
||||
(void) session;
|
||||
|
||||
_libssh2_init_if_needed ();
|
||||
_libssh2_init_if_needed();
|
||||
|
||||
return read_private_key_from_file((void **) ec_ctx, read_ec,
|
||||
filename, passphrase);
|
||||
@@ -804,13 +806,13 @@ _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session,
|
||||
sig_len = RSA_size(rsactx);
|
||||
sig = LIBSSH2_ALLOC(session, sig_len);
|
||||
|
||||
if (!sig) {
|
||||
if(!sig) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = RSA_sign(NID_sha1, hash, hash_len, sig, &sig_len, rsactx);
|
||||
|
||||
if (!ret) {
|
||||
if(!ret) {
|
||||
LIBSSH2_FREE(session, sig);
|
||||
return -1;
|
||||
}
|
||||
@@ -834,7 +836,7 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
|
||||
(void) hash_len;
|
||||
|
||||
sig = DSA_do_sign(hash, SHA_DIGEST_LENGTH, dsactx);
|
||||
if (!sig) {
|
||||
if(!sig) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -845,12 +847,12 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
|
||||
s = sig->s;
|
||||
#endif
|
||||
r_len = BN_num_bytes(r);
|
||||
if (r_len < 1 || r_len > 20) {
|
||||
if(r_len < 1 || r_len > 20) {
|
||||
DSA_SIG_free(sig);
|
||||
return -1;
|
||||
}
|
||||
s_len = BN_num_bytes(s);
|
||||
if (s_len < 1 || s_len > 20) {
|
||||
if(s_len < 1 || s_len > 20) {
|
||||
DSA_SIG_free(sig);
|
||||
return -1;
|
||||
}
|
||||
@@ -882,7 +884,7 @@ _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx,
|
||||
unsigned char *out_buffer = NULL;
|
||||
|
||||
ECDSA_SIG *sig = ECDSA_do_sign(hash, hash_len, ec_ctx);
|
||||
if ( sig == NULL )
|
||||
if(sig == NULL)
|
||||
return -1;
|
||||
#if HAVE_OPAQUE_STRUCTS
|
||||
ECDSA_SIG_get0(sig, &pr, &ps);
|
||||
@@ -895,7 +897,7 @@ _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx,
|
||||
s_len = BN_num_bytes(ps) + 1;
|
||||
|
||||
temp_buffer = malloc(r_len + s_len + 8);
|
||||
if ( temp_buffer == NULL ) {
|
||||
if(temp_buffer == NULL) {
|
||||
rc = -1;
|
||||
goto clean_exit;
|
||||
}
|
||||
@@ -907,7 +909,7 @@ _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx,
|
||||
out_buffer_len = (size_t)(sp - temp_buffer);
|
||||
|
||||
out_buffer = LIBSSH2_CALLOC(session, out_buffer_len);
|
||||
if ( out_buffer == NULL ) {
|
||||
if(out_buffer == NULL) {
|
||||
rc = -1;
|
||||
goto clean_exit;
|
||||
}
|
||||
@@ -919,10 +921,10 @@ _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx,
|
||||
|
||||
clean_exit:
|
||||
|
||||
if ( temp_buffer != NULL )
|
||||
if(temp_buffer != NULL)
|
||||
free(temp_buffer);
|
||||
|
||||
if ( sig )
|
||||
if(sig)
|
||||
ECDSA_SIG_free(sig);
|
||||
|
||||
return rc;
|
||||
@@ -935,10 +937,10 @@ _libssh2_sha1_init(libssh2_sha1_ctx *ctx)
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
*ctx = EVP_MD_CTX_new();
|
||||
|
||||
if (*ctx == NULL)
|
||||
if(*ctx == NULL)
|
||||
return 0;
|
||||
|
||||
if (EVP_DigestInit(*ctx, EVP_get_digestbyname("sha1")))
|
||||
if(EVP_DigestInit(*ctx, EVP_get_digestbyname("sha1")))
|
||||
return 1;
|
||||
|
||||
EVP_MD_CTX_free(*ctx);
|
||||
@@ -958,10 +960,10 @@ _libssh2_sha1(const unsigned char *message, unsigned long len,
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
EVP_MD_CTX * ctx = EVP_MD_CTX_new();
|
||||
|
||||
if (ctx == NULL)
|
||||
if(ctx == NULL)
|
||||
return 1; /* error */
|
||||
|
||||
if (EVP_DigestInit(ctx, EVP_get_digestbyname("sha1"))) {
|
||||
if(EVP_DigestInit(ctx, EVP_get_digestbyname("sha1"))) {
|
||||
EVP_DigestUpdate(ctx, message, len);
|
||||
EVP_DigestFinal(ctx, out, NULL);
|
||||
EVP_MD_CTX_free(ctx);
|
||||
@@ -972,7 +974,7 @@ _libssh2_sha1(const unsigned char *message, unsigned long len,
|
||||
EVP_MD_CTX ctx;
|
||||
|
||||
EVP_MD_CTX_init(&ctx);
|
||||
if (EVP_DigestInit(&ctx, EVP_get_digestbyname("sha1"))) {
|
||||
if(EVP_DigestInit(&ctx, EVP_get_digestbyname("sha1"))) {
|
||||
EVP_DigestUpdate(&ctx, message, len);
|
||||
EVP_DigestFinal(&ctx, out, NULL);
|
||||
return 0; /* success */
|
||||
@@ -987,10 +989,10 @@ _libssh2_sha256_init(libssh2_sha256_ctx *ctx)
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
*ctx = EVP_MD_CTX_new();
|
||||
|
||||
if (*ctx == NULL)
|
||||
if(*ctx == NULL)
|
||||
return 0;
|
||||
|
||||
if (EVP_DigestInit(*ctx, EVP_get_digestbyname("sha256")))
|
||||
if(EVP_DigestInit(*ctx, EVP_get_digestbyname("sha256")))
|
||||
return 1;
|
||||
|
||||
EVP_MD_CTX_free(*ctx);
|
||||
@@ -1010,7 +1012,7 @@ _libssh2_sha256(const unsigned char *message, unsigned long len,
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
EVP_MD_CTX * ctx = EVP_MD_CTX_new();
|
||||
|
||||
if (ctx == NULL)
|
||||
if(ctx == NULL)
|
||||
return 1; /* error */
|
||||
|
||||
if(EVP_DigestInit(ctx, EVP_get_digestbyname("sha256"))) {
|
||||
@@ -1039,10 +1041,10 @@ _libssh2_sha384_init(libssh2_sha384_ctx *ctx)
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
*ctx = EVP_MD_CTX_new();
|
||||
|
||||
if (*ctx == NULL)
|
||||
if(*ctx == NULL)
|
||||
return 0;
|
||||
|
||||
if (EVP_DigestInit(*ctx, EVP_get_digestbyname("sha384")))
|
||||
if(EVP_DigestInit(*ctx, EVP_get_digestbyname("sha384")))
|
||||
return 1;
|
||||
|
||||
EVP_MD_CTX_free(*ctx);
|
||||
@@ -1062,7 +1064,7 @@ _libssh2_sha384(const unsigned char *message, unsigned long len,
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
EVP_MD_CTX * ctx = EVP_MD_CTX_new();
|
||||
|
||||
if (ctx == NULL)
|
||||
if(ctx == NULL)
|
||||
return 1; /* error */
|
||||
|
||||
if(EVP_DigestInit(ctx, EVP_get_digestbyname("sha384"))) {
|
||||
@@ -1091,10 +1093,10 @@ _libssh2_sha512_init(libssh2_sha512_ctx *ctx)
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
*ctx = EVP_MD_CTX_new();
|
||||
|
||||
if (*ctx == NULL)
|
||||
if(*ctx == NULL)
|
||||
return 0;
|
||||
|
||||
if (EVP_DigestInit(*ctx, EVP_get_digestbyname("sha512")))
|
||||
if(EVP_DigestInit(*ctx, EVP_get_digestbyname("sha512")))
|
||||
return 1;
|
||||
|
||||
EVP_MD_CTX_free(*ctx);
|
||||
@@ -1114,7 +1116,7 @@ _libssh2_sha512(const unsigned char *message, unsigned long len,
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
EVP_MD_CTX * ctx = EVP_MD_CTX_new();
|
||||
|
||||
if (ctx == NULL)
|
||||
if(ctx == NULL)
|
||||
return 1; /* error */
|
||||
|
||||
if(EVP_DigestInit(ctx, EVP_get_digestbyname("sha512"))) {
|
||||
@@ -1143,10 +1145,10 @@ _libssh2_md5_init(libssh2_md5_ctx *ctx)
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
*ctx = EVP_MD_CTX_new();
|
||||
|
||||
if (*ctx == NULL)
|
||||
if(*ctx == NULL)
|
||||
return 0;
|
||||
|
||||
if (EVP_DigestInit(*ctx, EVP_get_digestbyname("md5")))
|
||||
if(EVP_DigestInit(*ctx, EVP_get_digestbyname("md5")))
|
||||
return 1;
|
||||
|
||||
EVP_MD_CTX_free(*ctx);
|
||||
@@ -1165,8 +1167,8 @@ gen_publickey_from_rsa(LIBSSH2_SESSION *session, RSA *rsa,
|
||||
{
|
||||
int e_bytes, n_bytes;
|
||||
unsigned long len;
|
||||
unsigned char* key;
|
||||
unsigned char* p;
|
||||
unsigned char *key;
|
||||
unsigned char *p;
|
||||
const BIGNUM * e;
|
||||
const BIGNUM * n;
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
@@ -1182,7 +1184,7 @@ gen_publickey_from_rsa(LIBSSH2_SESSION *session, RSA *rsa,
|
||||
len = 4 + 7 + 4 + e_bytes + 4 + n_bytes;
|
||||
|
||||
key = LIBSSH2_ALLOC(session, len);
|
||||
if (key == NULL) {
|
||||
if(key == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1208,8 +1210,8 @@ gen_publickey_from_dsa(LIBSSH2_SESSION* session, DSA *dsa,
|
||||
{
|
||||
int p_bytes, q_bytes, g_bytes, k_bytes;
|
||||
unsigned long len;
|
||||
unsigned char* key;
|
||||
unsigned char* p;
|
||||
unsigned char *key;
|
||||
unsigned char *p;
|
||||
|
||||
const BIGNUM * p_bn;
|
||||
const BIGNUM * q;
|
||||
@@ -1237,7 +1239,7 @@ gen_publickey_from_dsa(LIBSSH2_SESSION* session, DSA *dsa,
|
||||
len = 4 + 7 + 4 + p_bytes + 4 + q_bytes + 4 + g_bytes + 4 + k_bytes;
|
||||
|
||||
key = LIBSSH2_ALLOC(session, len);
|
||||
if (key == NULL) {
|
||||
if(key == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1268,8 +1270,8 @@ gen_publickey_from_rsa_evp(LIBSSH2_SESSION *session,
|
||||
EVP_PKEY *pk)
|
||||
{
|
||||
RSA* rsa = NULL;
|
||||
unsigned char* key;
|
||||
unsigned char* method_buf = NULL;
|
||||
unsigned char *key;
|
||||
unsigned char *method_buf = NULL;
|
||||
size_t key_len;
|
||||
|
||||
_libssh2_debug(session,
|
||||
@@ -1277,18 +1279,18 @@ gen_publickey_from_rsa_evp(LIBSSH2_SESSION *session,
|
||||
"Computing public key from RSA private key envelop");
|
||||
|
||||
rsa = EVP_PKEY_get1_RSA(pk);
|
||||
if (rsa == NULL) {
|
||||
if(rsa == NULL) {
|
||||
/* Assume memory allocation error... what else could it be ? */
|
||||
goto __alloc_error;
|
||||
}
|
||||
|
||||
method_buf = LIBSSH2_ALLOC(session, 7); /* ssh-rsa. */
|
||||
if (method_buf == NULL) {
|
||||
if(method_buf == NULL) {
|
||||
goto __alloc_error;
|
||||
}
|
||||
|
||||
key = gen_publickey_from_rsa(session, rsa, &key_len);
|
||||
if (key == NULL) {
|
||||
if(key == NULL) {
|
||||
goto __alloc_error;
|
||||
}
|
||||
RSA_free(rsa);
|
||||
@@ -1301,10 +1303,10 @@ gen_publickey_from_rsa_evp(LIBSSH2_SESSION *session,
|
||||
return 0;
|
||||
|
||||
__alloc_error:
|
||||
if (rsa != NULL) {
|
||||
if(rsa != NULL) {
|
||||
RSA_free(rsa);
|
||||
}
|
||||
if (method_buf != NULL) {
|
||||
if(method_buf != NULL) {
|
||||
LIBSSH2_FREE(session, method_buf);
|
||||
}
|
||||
|
||||
@@ -1323,8 +1325,8 @@ gen_publickey_from_dsa_evp(LIBSSH2_SESSION *session,
|
||||
EVP_PKEY *pk)
|
||||
{
|
||||
DSA* dsa = NULL;
|
||||
unsigned char* key;
|
||||
unsigned char* method_buf = NULL;
|
||||
unsigned char *key;
|
||||
unsigned char *method_buf = NULL;
|
||||
size_t key_len;
|
||||
|
||||
_libssh2_debug(session,
|
||||
@@ -1332,18 +1334,18 @@ gen_publickey_from_dsa_evp(LIBSSH2_SESSION *session,
|
||||
"Computing public key from DSA private key envelop");
|
||||
|
||||
dsa = EVP_PKEY_get1_DSA(pk);
|
||||
if (dsa == NULL) {
|
||||
if(dsa == NULL) {
|
||||
/* Assume memory allocation error... what else could it be ? */
|
||||
goto __alloc_error;
|
||||
}
|
||||
|
||||
method_buf = LIBSSH2_ALLOC(session, 7); /* ssh-dss. */
|
||||
if (method_buf == NULL) {
|
||||
if(method_buf == NULL) {
|
||||
goto __alloc_error;
|
||||
}
|
||||
|
||||
key = gen_publickey_from_dsa(session, dsa, &key_len);
|
||||
if (key == NULL) {
|
||||
if(key == NULL) {
|
||||
goto __alloc_error;
|
||||
}
|
||||
DSA_free(dsa);
|
||||
@@ -1356,10 +1358,10 @@ gen_publickey_from_dsa_evp(LIBSSH2_SESSION *session,
|
||||
return 0;
|
||||
|
||||
__alloc_error:
|
||||
if (dsa != NULL) {
|
||||
if(dsa != NULL) {
|
||||
DSA_free(dsa);
|
||||
}
|
||||
if (method_buf != NULL) {
|
||||
if(method_buf != NULL) {
|
||||
LIBSSH2_FREE(session, method_buf);
|
||||
}
|
||||
|
||||
@@ -1382,7 +1384,7 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session,
|
||||
int rc = 0;
|
||||
EC_KEY *ec = NULL;
|
||||
unsigned char *p;
|
||||
unsigned char* method_buf = NULL;
|
||||
unsigned char *method_buf = NULL;
|
||||
unsigned char *key;
|
||||
size_t key_len = 0;
|
||||
unsigned char *octal_value = NULL;
|
||||
@@ -1397,11 +1399,11 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session,
|
||||
"Computing public key from EC private key envelop");
|
||||
|
||||
bn_ctx = BN_CTX_new();
|
||||
if ( bn_ctx == NULL )
|
||||
if(bn_ctx == NULL)
|
||||
return -1;
|
||||
|
||||
ec = EVP_PKEY_get1_EC_KEY(pk);
|
||||
if ( ec == NULL ) {
|
||||
if(ec == NULL) {
|
||||
rc = -1;
|
||||
goto clean_exit;
|
||||
}
|
||||
@@ -1411,16 +1413,16 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session,
|
||||
type = _libssh2_ecdsa_key_get_curve_type(ec);
|
||||
|
||||
method_buf = LIBSSH2_ALLOC(session, 19);
|
||||
if (method_buf == NULL) {
|
||||
if(method_buf == NULL) {
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"out of memory");
|
||||
}
|
||||
|
||||
if ( type == LIBSSH2_EC_CURVE_NISTP256 )
|
||||
if(type == LIBSSH2_EC_CURVE_NISTP256)
|
||||
memcpy(method_buf, "ecdsa-sha2-nistp256", 19);
|
||||
else if ( type == LIBSSH2_EC_CURVE_NISTP384 )
|
||||
else if(type == LIBSSH2_EC_CURVE_NISTP384)
|
||||
memcpy(method_buf, "ecdsa-sha2-nistp384", 19);
|
||||
else if ( type == LIBSSH2_EC_CURVE_NISTP521 )
|
||||
else if(type == LIBSSH2_EC_CURVE_NISTP521)
|
||||
memcpy(method_buf, "ecdsa-sha2-nistp521", 19);
|
||||
else {
|
||||
_libssh2_debug(session,
|
||||
@@ -1432,19 +1434,19 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session,
|
||||
|
||||
/* get length */
|
||||
octal_len = EC_POINT_point2oct(group, public_key, POINT_CONVERSION_UNCOMPRESSED, NULL, 0, bn_ctx);
|
||||
if (octal_len > EC_MAX_POINT_LEN) {
|
||||
if(octal_len > EC_MAX_POINT_LEN) {
|
||||
rc = -1;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
octal_value = malloc(octal_len);
|
||||
if ( octal_value == NULL ) {
|
||||
if(octal_value == NULL) {
|
||||
rc = -1;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
/* convert to octal */
|
||||
if (EC_POINT_point2oct(group, public_key, POINT_CONVERSION_UNCOMPRESSED,
|
||||
if(EC_POINT_point2oct(group, public_key, POINT_CONVERSION_UNCOMPRESSED,
|
||||
octal_value, octal_len, bn_ctx) != octal_len) {
|
||||
rc = -1;
|
||||
goto clean_exit;
|
||||
@@ -1453,7 +1455,7 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session,
|
||||
/* Key form is: type_len(4) + type(19) + domain_len(4) + domain(8) + pub_key_len(4) + pub_key(~65). */
|
||||
key_len = 4 + 19 + 4 + 8 + 4 + octal_len;
|
||||
key = LIBSSH2_ALLOC(session, key_len);
|
||||
if (key == NULL) {
|
||||
if(key == NULL) {
|
||||
rc = -1;
|
||||
goto clean_exit;
|
||||
}
|
||||
@@ -1462,13 +1464,13 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session,
|
||||
p = key;
|
||||
|
||||
/* Key type */
|
||||
_libssh2_store_str(&p, (const char*)method_buf, 19);
|
||||
_libssh2_store_str(&p, (const char *)method_buf, 19);
|
||||
|
||||
/* Name domain */
|
||||
_libssh2_store_str(&p, (const char*)method_buf + 11, 8);
|
||||
_libssh2_store_str(&p, (const char *)method_buf + 11, 8);
|
||||
|
||||
/* Public key */
|
||||
_libssh2_store_str(&p, (const char*)octal_value, octal_len);
|
||||
_libssh2_store_str(&p, (const char *)octal_value, octal_len);
|
||||
|
||||
*method = method_buf;
|
||||
*method_len = 19;
|
||||
@@ -1477,20 +1479,20 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session,
|
||||
|
||||
clean_exit:
|
||||
|
||||
if ( ec != NULL)
|
||||
if(ec != NULL)
|
||||
EC_KEY_free(ec);
|
||||
|
||||
if (bn_ctx != NULL) {
|
||||
if(bn_ctx != NULL) {
|
||||
BN_CTX_free(bn_ctx);
|
||||
}
|
||||
|
||||
if ( octal_value != NULL )
|
||||
if(octal_value != NULL)
|
||||
free(octal_value);
|
||||
|
||||
if ( rc == 0 )
|
||||
if(rc == 0)
|
||||
return 0;
|
||||
|
||||
if (method_buf != NULL )
|
||||
if(method_buf != NULL)
|
||||
LIBSSH2_FREE(session, method_buf);
|
||||
|
||||
return -1;
|
||||
@@ -1518,7 +1520,7 @@ _libssh2_ecdsa_create_key(_libssh2_ec_key **out_private_key,
|
||||
|
||||
/* create key */
|
||||
BN_CTX *bn_ctx = BN_CTX_new();
|
||||
if (!bn_ctx)
|
||||
if(!bn_ctx)
|
||||
return -1;
|
||||
|
||||
private_key = EC_KEY_new_by_curve_name(curve_type);
|
||||
@@ -1529,24 +1531,24 @@ _libssh2_ecdsa_create_key(_libssh2_ec_key **out_private_key,
|
||||
|
||||
/* get length */
|
||||
octal_len = EC_POINT_point2oct(group, public_key, POINT_CONVERSION_UNCOMPRESSED, NULL, 0, bn_ctx);
|
||||
if (octal_len > EC_MAX_POINT_LEN) {
|
||||
if(octal_len > EC_MAX_POINT_LEN) {
|
||||
ret = -1;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
/* convert to octal */
|
||||
if (EC_POINT_point2oct(group, public_key, POINT_CONVERSION_UNCOMPRESSED,
|
||||
octal_value, octal_len, bn_ctx) != octal_len){
|
||||
if(EC_POINT_point2oct(group, public_key, POINT_CONVERSION_UNCOMPRESSED,
|
||||
octal_value, octal_len, bn_ctx) != octal_len) {
|
||||
ret = -1;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
if (out_private_key != NULL)
|
||||
if(out_private_key != NULL)
|
||||
*out_private_key = private_key;
|
||||
|
||||
if (out_public_key_octal) {
|
||||
if(out_public_key_octal) {
|
||||
*out_public_key_octal = malloc(octal_len);
|
||||
if (out_public_key_octal == NULL) {
|
||||
if(out_public_key_octal == NULL) {
|
||||
ret = -1;
|
||||
goto clean_exit;
|
||||
}
|
||||
@@ -1554,12 +1556,12 @@ _libssh2_ecdsa_create_key(_libssh2_ec_key **out_private_key,
|
||||
memcpy(*out_public_key_octal, octal_value, octal_len);
|
||||
}
|
||||
|
||||
if (out_public_key_octal_len != NULL)
|
||||
if(out_public_key_octal_len != NULL)
|
||||
*out_public_key_octal_len = octal_len;
|
||||
|
||||
clean_exit:
|
||||
|
||||
if (bn_ctx)
|
||||
if(bn_ctx)
|
||||
BN_CTX_free(bn_ctx);
|
||||
|
||||
return (ret == 1) ? 0 : -1;
|
||||
@@ -1584,34 +1586,34 @@ _libssh2_ecdh_gen_k(_libssh2_bn **k, _libssh2_ec_key *private_key,
|
||||
|
||||
BN_CTX *bn_ctx = BN_CTX_new();
|
||||
|
||||
if ( !bn_ctx )
|
||||
if(!bn_ctx)
|
||||
return -1;
|
||||
|
||||
if ( k == NULL )
|
||||
if(k == NULL)
|
||||
return -1;
|
||||
|
||||
private_key_group = EC_KEY_get0_group(private_key);
|
||||
|
||||
server_public_key_point = EC_POINT_new(private_key_group);
|
||||
if ( server_public_key_point == NULL )
|
||||
if(server_public_key_point == NULL)
|
||||
return -1;
|
||||
|
||||
rc = EC_POINT_oct2point(private_key_group, server_public_key_point, server_public_key, server_public_key_len, bn_ctx);
|
||||
if ( rc != 1 ) {
|
||||
if(rc != 1) {
|
||||
ret = -1;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
secret_len = (EC_GROUP_get_degree(private_key_group) + 7) / 8;
|
||||
secret = malloc(secret_len);
|
||||
if (!secret) {
|
||||
if(!secret) {
|
||||
ret = -1;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
secret_len = ECDH_compute_key(secret, secret_len, server_public_key_point, private_key, NULL);
|
||||
|
||||
if( secret_len <= 0 || secret_len > EC_MAX_POINT_LEN ) {
|
||||
if(secret_len <= 0 || secret_len > EC_MAX_POINT_LEN) {
|
||||
ret = -1;
|
||||
goto clean_exit;
|
||||
}
|
||||
@@ -1620,13 +1622,13 @@ _libssh2_ecdh_gen_k(_libssh2_bn **k, _libssh2_ec_key *private_key,
|
||||
|
||||
clean_exit:
|
||||
|
||||
if ( server_public_key_point != NULL )
|
||||
if(server_public_key_point != NULL)
|
||||
EC_POINT_free(server_public_key_point);
|
||||
|
||||
if ( bn_ctx != NULL )
|
||||
if(bn_ctx != NULL)
|
||||
BN_CTX_free(bn_ctx);
|
||||
|
||||
if ( secret != NULL )
|
||||
if(secret != NULL)
|
||||
free(secret);
|
||||
|
||||
return ret;
|
||||
@@ -1655,7 +1657,7 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
|
||||
privatekey);
|
||||
|
||||
bp = BIO_new_file(privatekey, "r");
|
||||
if (bp == NULL) {
|
||||
if(bp == NULL) {
|
||||
return _libssh2_error(session,
|
||||
LIBSSH2_ERROR_FILE,
|
||||
"Unable to extract public key from private key "
|
||||
@@ -1663,10 +1665,10 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
|
||||
}
|
||||
|
||||
BIO_reset(bp);
|
||||
pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void*)passphrase);
|
||||
pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void *)passphrase);
|
||||
BIO_free(bp);
|
||||
|
||||
if (pk == NULL) {
|
||||
if(pk == NULL) {
|
||||
return _libssh2_error(session,
|
||||
LIBSSH2_ERROR_FILE,
|
||||
"Unable to extract public key "
|
||||
@@ -1681,7 +1683,7 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
|
||||
pktype = pk->type;
|
||||
#endif
|
||||
|
||||
switch (pktype) {
|
||||
switch(pktype) {
|
||||
case EVP_PKEY_RSA :
|
||||
st = gen_publickey_from_rsa_evp(
|
||||
session, method, method_len, pubkeydata, pubkeydata_len, pk);
|
||||
@@ -1734,15 +1736,15 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
|
||||
"Computing public key from private key.");
|
||||
|
||||
bp = BIO_new_mem_buf((char *)privatekeydata, privatekeydata_len);
|
||||
if (!bp) {
|
||||
if(!bp) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
BIO_reset(bp);
|
||||
pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void*)passphrase);
|
||||
pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void *)passphrase);
|
||||
BIO_free(bp);
|
||||
|
||||
if (pk == NULL) {
|
||||
if(pk == NULL) {
|
||||
return _libssh2_error(session,
|
||||
LIBSSH2_ERROR_FILE,
|
||||
"Unable to extract public key "
|
||||
@@ -1757,7 +1759,7 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
|
||||
pktype = pk->type;
|
||||
#endif
|
||||
|
||||
switch (pktype) {
|
||||
switch(pktype) {
|
||||
case EVP_PKEY_RSA :
|
||||
st = gen_publickey_from_rsa_evp(session, method, method_len,
|
||||
pubkeydata, pubkeydata_len, pk);
|
||||
|
||||
Reference in New Issue
Block a user