aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-10-18 23:21:52 +0200
committerAndreas Schneider <asn@cryptomilk.org>2013-10-18 23:22:24 +0200
commit15e31eb464b31c30499131e184f77d0ad13dcdec (patch)
treea2b5c0b0068cfa825fd803cb41f494be5af2415e
parent2e81dd61dde4165cb6c34e13df60b86850dd6ab8 (diff)
downloadlibssh-15e31eb464b31c30499131e184f77d0ad13dcdec.tar.gz
libssh-15e31eb464b31c30499131e184f77d0ad13dcdec.tar.xz
libssh-15e31eb464b31c30499131e184f77d0ad13dcdec.zip
wrapper: Add more evp functions.
-rw-r--r--include/libssh/libcrypto.h3
-rw-r--r--include/libssh/wrapper.h3
-rw-r--r--src/libcrypto.c24
3 files changed, 30 insertions, 0 deletions
diff --git a/include/libssh/libcrypto.h b/include/libssh/libcrypto.h
index 54c78b16..c8b157b0 100644
--- a/include/libssh/libcrypto.h
+++ b/include/libssh/libcrypto.h
@@ -38,6 +38,9 @@ typedef SHA_CTX* SHACTX;
typedef SHA256_CTX* SHA256CTX;
typedef MD5_CTX* MD5CTX;
typedef HMAC_CTX* HMACCTX;
+#ifdef HAVE_ECC
+typedef EVP_MD_CTX *EVPCTX;
+#endif
#define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
#ifdef MD5_DIGEST_LEN
diff --git a/include/libssh/wrapper.h b/include/libssh/wrapper.h
index 90c268d9..7374a88a 100644
--- a/include/libssh/wrapper.h
+++ b/include/libssh/wrapper.h
@@ -53,6 +53,9 @@ void sha1(unsigned char *digest,int len,unsigned char *hash);
void sha256(unsigned char *digest, int len, unsigned char *hash);
void evp(int nid, unsigned char *digest, int len, unsigned char *hash, unsigned int *hlen);
+EVPCTX evp_init(int nid);
+void evp_update(EVPCTX ctx, const void *data, unsigned long len);
+void evp_final(EVPCTX ctx, unsigned char *md, unsigned int *mdlen);
ssh_mac_ctx ssh_mac_ctx_init(enum ssh_mac_e type);
void ssh_mac_update(ssh_mac_ctx ctx, const void *data, unsigned long len);
diff --git a/src/libcrypto.c b/src/libcrypto.c
index 44b0fb36..bb1d96ad 100644
--- a/src/libcrypto.c
+++ b/src/libcrypto.c
@@ -123,6 +123,30 @@ void evp(int nid, unsigned char *digest, int len, unsigned char *hash, unsigned
EVP_DigestUpdate(&md, digest, len);
EVP_DigestFinal(&md, hash, hlen);
}
+
+EVPCTX evp_init(int nid)
+{
+ const EVP_MD *evp_md = nid_to_evpmd(nid);
+
+ EVPCTX ctx = malloc(sizeof(EVP_MD_CTX));
+ if (ctx == NULL) {
+ return NULL;
+ }
+
+ EVP_DigestInit(ctx, evp_md);
+
+ return ctx;
+}
+
+void evp_update(EVPCTX ctx, const void *data, unsigned long len)
+{
+ EVP_DigestUpdate(ctx, data, len);
+}
+
+void evp_final(EVPCTX ctx, unsigned char *md, unsigned int *mdlen)
+{
+ EVP_DigestFinal(ctx, md, mdlen);
+}
#endif
SHA256CTX sha256_init(void){