summaryrefslogtreecommitdiff
path: root/libs/libssh2/src/libgcrypt.c
diff options
context:
space:
mode:
Diffstat (limited to 'libs/libssh2/src/libgcrypt.c')
-rw-r--r--libs/libssh2/src/libgcrypt.c107
1 files changed, 105 insertions, 2 deletions
diff --git a/libs/libssh2/src/libgcrypt.c b/libs/libssh2/src/libgcrypt.c
index e463d9e347..b92ec7c97d 100644
--- a/libs/libssh2/src/libgcrypt.c
+++ b/libs/libssh2/src/libgcrypt.c
@@ -40,6 +40,105 @@
#ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */
+int _libssh2_hmac_ctx_init(libssh2_hmac_ctx *ctx)
+{
+ *ctx = NULL;
+ return 1;
+}
+
+#if LIBSSH2_MD5
+int _libssh2_hmac_md5_init(libssh2_hmac_ctx *ctx,
+ void *key, size_t keylen)
+{
+ gcry_error_t err;
+ err = gcry_md_open(ctx, GCRY_MD_MD5, GCRY_MD_FLAG_HMAC);
+ if(gcry_err_code(err) != GPG_ERR_NO_ERROR)
+ return 0;
+ err = gcry_md_setkey(*ctx, key, keylen);
+ if(gcry_err_code(err) != GPG_ERR_NO_ERROR)
+ return 0;
+ return 1;
+}
+#endif
+
+#if LIBSSH2_HMAC_RIPEMD
+int _libssh2_hmac_ripemd160_init(libssh2_hmac_ctx *ctx,
+ void *key, size_t keylen)
+{
+ gcry_error_t err;
+ err = gcry_md_open(ctx, GCRY_MD_RMD160, GCRY_MD_FLAG_HMAC);
+ if(gcry_err_code(err) != GPG_ERR_NO_ERROR)
+ return 0;
+ err = gcry_md_setkey(*ctx, key, keylen);
+ if(gcry_err_code(err) != GPG_ERR_NO_ERROR)
+ return 0;
+ return 1;
+}
+#endif
+
+int _libssh2_hmac_sha1_init(libssh2_hmac_ctx *ctx,
+ void *key, size_t keylen)
+{
+ gcry_error_t err;
+ err = gcry_md_open(ctx, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
+ if(gcry_err_code(err) != GPG_ERR_NO_ERROR)
+ return 0;
+ err = gcry_md_setkey(*ctx, key, keylen);
+ if(gcry_err_code(err) != GPG_ERR_NO_ERROR)
+ return 0;
+ return 1;
+}
+
+int _libssh2_hmac_sha256_init(libssh2_hmac_ctx *ctx,
+ void *key, size_t keylen)
+{
+ gcry_error_t err;
+ err = gcry_md_open(ctx, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC);
+ if(gcry_err_code(err) != GPG_ERR_NO_ERROR)
+ return 0;
+ err = gcry_md_setkey(*ctx, key, keylen);
+ if(gcry_err_code(err) != GPG_ERR_NO_ERROR)
+ return 0;
+ return 1;
+}
+
+int _libssh2_hmac_sha512_init(libssh2_hmac_ctx *ctx,
+ void *key, size_t keylen)
+{
+ gcry_error_t err;
+ err = gcry_md_open(ctx, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC);
+ if(gcry_err_code(err) != GPG_ERR_NO_ERROR)
+ return 0;
+ err = gcry_md_setkey(*ctx, key, keylen);
+ if(gcry_err_code(err) != GPG_ERR_NO_ERROR)
+ return 0;
+ return 1;
+}
+
+int _libssh2_hmac_update(libssh2_hmac_ctx *ctx,
+ const void *data, size_t datalen)
+{
+ gcry_md_write(*ctx, data, datalen);
+ return 1;
+}
+
+int _libssh2_hmac_final(libssh2_hmac_ctx *ctx, void *data)
+{
+ unsigned char *res = gcry_md_read(*ctx, 0);
+
+ if(!res)
+ return 0;
+
+ memcpy(data, res, gcry_md_get_algo_dlen(gcry_md_get_algo(*ctx)));
+
+ return 1;
+}
+
+void _libssh2_hmac_cleanup(libssh2_hmac_ctx *ctx)
+{
+ gcry_md_close(*ctx);
+}
+
#if LIBSSH2_RSA
int
_libssh2_rsa_new(libssh2_rsa_ctx ** rsa,
@@ -95,7 +194,9 @@ _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa,
gcry_sexp_t s_sig, s_hash;
int rc = -1;
- libssh2_sha1(m, m_len, hash);
+ if(libssh2_sha1(m, m_len, hash)) {
+ return -1;
+ }
rc = gcry_sexp_build(&s_hash, NULL,
"(data (flags pkcs1) (hash sha1 %b))",
@@ -544,7 +645,9 @@ _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx,
gcry_sexp_t s_sig, s_hash;
int rc = -1;
- libssh2_sha1(m, m_len, hash + 1);
+ if(libssh2_sha1(m, m_len, hash + 1)) {
+ return -1;
+ }
hash[0] = 0;
if(gcry_sexp_build(&s_hash, NULL, "(data(flags raw)(value %b))",