]> www.average.org Git - pam_pcsc_cr.git/blobdiff - ossl_crypto.c
cleaner crypto init
[pam_pcsc_cr.git] / ossl_crypto.c
index 4fdbcf3df134c0a73930a0a46a2c4acde50f9687..4b475a4fcbe807d0e0d0894027873764861dba12 100644 (file)
@@ -8,6 +8,12 @@
 
 #include "crypto_if.h"
 
+static const char *ossl_init(void)
+{
+       ERR_load_crypto_strings();
+       return "openssl";
+}
+
 static unsigned long ossl_encrypt(void *key, int keylen, void *iv,
                        void *pt, void *ct, int tlen)
 {
@@ -15,8 +21,6 @@ static unsigned long ossl_encrypt(void *key, int keylen, void *iv,
        int outlen1, outlen2;
        unsigned char hkey[16];
 
-       ERR_load_crypto_strings(); /* FIXME */
-
        if (EVP_BytesToKey(EVP_aes_128_cbc(), EVP_sha1(),
                        NULL, key, keylen, 5, hkey, NULL) != 16) return 1UL;
        if (!EVP_EncryptInit(&ctx, EVP_aes_128_cbc(), hkey, iv))
@@ -70,14 +74,9 @@ static unsigned long ossl_hash(void *pt, int tlen, void *tag, int *taglen)
 static unsigned long ossl_hmac(void *pt, int tlen, void *key, int keylen,
                        void *tag, int *taglen)
 {
-       HMAC_CTX hctx;
-
-       HMAC_CTX_init(&hctx);
-       if (!HMAC_Init_ex(&hctx, key, keylen, EVP_sha1(), NULL)) return ERR_get_error();
-       if (!HMAC_Update(&hctx, pt, tlen)) return ERR_get_error();
-       if (!HMAC_Final(&hctx, tag, (unsigned int *)taglen))
-               return ERR_get_error();
-       HMAC_CTX_cleanup(&hctx);
+       if (!HMAC(EVP_sha1(), key, keylen, pt, tlen,
+                               tag, (unsigned int *)taglen))
+                       return ERR_get_error();
        return 0UL;
 }
 
@@ -87,7 +86,7 @@ static const char *ossl_errstr(unsigned long err)
 }
 
 struct crypto_interface ossl_crypto_if = {
-       .name           = "openssl",
+       .init           = ossl_init,
        .encrypt        = ossl_encrypt,
        .decrypt        = ossl_decrypt,
        .hash           = ossl_hash,