Indent.
Fix mem leak on errors.
Этот коммит содержится в:
родитель
a0eda7365e
Коммит
576d37dafd
@ -102,17 +102,18 @@ int _libssh2_dsa_new(libssh2_dsa_ctx **dsactx,
|
|||||||
const unsigned char *y,
|
const unsigned char *y,
|
||||||
unsigned long y_len)
|
unsigned long y_len)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = gcry_sexp_build (dsactx, NULL, "(public-key(dsa(p%b)(q%b)(g%b)(y%b)))",
|
rc = gcry_sexp_build (dsactx, NULL,
|
||||||
p_len, p, q_len, q, g_len, g, y_len, y);
|
"(public-key(dsa(p%b)(q%b)(g%b)(y%b)))",
|
||||||
if (rc)
|
p_len, p, q_len, q, g_len, g, y_len, y);
|
||||||
{
|
if (rc)
|
||||||
*dsactx = NULL;
|
{
|
||||||
return -1;
|
*dsactx = NULL;
|
||||||
}
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -122,34 +123,34 @@ int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsactx,
|
|||||||
const unsigned char *m,
|
const unsigned char *m,
|
||||||
unsigned long m_len)
|
unsigned long m_len)
|
||||||
{
|
{
|
||||||
unsigned char hash[SHA_DIGEST_LENGTH+1];
|
unsigned char hash[SHA_DIGEST_LENGTH+1];
|
||||||
int ret;
|
int ret;
|
||||||
gcry_sexp_t s_sig, s_hash;
|
gcry_sexp_t s_sig, s_hash;
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
|
|
||||||
libssh2_sha1(m, m_len, hash+1);
|
libssh2_sha1(m, m_len, hash+1);
|
||||||
hash[0] = 0;
|
hash[0] = 0;
|
||||||
|
|
||||||
rc = gcry_sexp_build (&s_hash, NULL, "(data(flags raw)(value %b))",
|
rc = gcry_sexp_build (&s_hash, NULL, "(data(flags raw)(value %b))",
|
||||||
SHA_DIGEST_LENGTH+1, hash);
|
SHA_DIGEST_LENGTH+1, hash);
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = gcry_sexp_build (&s_sig, NULL, "(sig-val(dsa(r %b)(s %b)))",
|
rc = gcry_sexp_build (&s_sig, NULL, "(sig-val(dsa(r %b)(s %b)))",
|
||||||
20, sig, 20, sig + 20);
|
20, sig, 20, sig + 20);
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
{
|
{
|
||||||
gcry_sexp_release (s_hash);
|
gcry_sexp_release (s_hash);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = gcry_pk_verify (s_sig, s_hash, dsactx);
|
rc = gcry_pk_verify (s_sig, s_hash, dsactx);
|
||||||
gcry_sexp_release (s_sig);
|
gcry_sexp_release (s_sig);
|
||||||
gcry_sexp_release (s_hash);
|
gcry_sexp_release (s_hash);
|
||||||
|
|
||||||
return (rc == 0) ? 0 : -1;
|
return (rc == 0) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
||||||
@ -158,8 +159,9 @@ int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
|||||||
unsigned char *secret,
|
unsigned char *secret,
|
||||||
int encrypt)
|
int encrypt)
|
||||||
{
|
{
|
||||||
int mode = 0, keylen, err;
|
int mode = 0, err;
|
||||||
keylen = gcry_cipher_get_algo_keylen (algo);
|
int keylen = gcry_cipher_get_algo_keylen (algo);
|
||||||
|
|
||||||
if (algo != GCRY_CIPHER_ARCFOUR)
|
if (algo != GCRY_CIPHER_ARCFOUR)
|
||||||
{
|
{
|
||||||
mode = GCRY_CIPHER_MODE_CBC;
|
mode = GCRY_CIPHER_MODE_CBC;
|
||||||
@ -174,6 +176,7 @@ int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
|||||||
err = gcry_cipher_setkey (*h, secret, keylen);
|
err = gcry_cipher_setkey (*h, secret, keylen);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
|
gcry_cipher_close (*h);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,6 +186,7 @@ int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
|||||||
err = gcry_cipher_setiv (*h, iv, blklen);
|
err = gcry_cipher_setiv (*h, iv, blklen);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
|
gcry_cipher_close (*h);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user