X-Git-Url: http://www.average.org/gitweb/?p=pam_pcsc_cr.git;a=blobdiff_plain;f=ossl_crypto.c;h=4b475a4fcbe807d0e0d0894027873764861dba12;hp=4fdbcf3df134c0a73930a0a46a2c4acde50f9687;hb=724570ad4aaaa5eb67fe0e808d638321d522eba7;hpb=8c8a47cd542e60381773fe23f2075aa5b896be4f diff --git a/ossl_crypto.c b/ossl_crypto.c index 4fdbcf3..4b475a4 100644 --- a/ossl_crypto.c +++ b/ossl_crypto.c @@ -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,