]> www.average.org Git - pam_pcsc_cr.git/blob - ossl_crypto.c
crypto interface
[pam_pcsc_cr.git] / ossl_crypto.c
1 #include <openssl/evp.h>
2 #include <openssl/hmac.h>
3
4 #include "crypto_if.h"
5
6 static int ossl_encrypt(void *pt, int ptlen, void *key, int keylen,
7                         void *ct, int *ctlen)
8 {
9     EVP_CIPHER_CTX ctx;
10     unsigned char iv[16] = {0};
11     int outlen1, outlen2;
12
13     EVP_EncryptInit(&ctx, EVP_aes_256_cbc(), key, iv);
14     EVP_EncryptUpdate(&ctx, ct, &outlen1, pt, ptlen);
15     EVP_EncryptFinal(&ctx, ct + outlen1, &outlen2);
16     if (outlen1 + outlen2 > *ctlen) return -1;
17     *ctlen = outlen1 + outlen2;
18
19     return 0;
20 }
21
22 static int ossl_decrypt()
23 {
24         return 0;
25 }
26
27 static int ossl_hash()
28 {
29         return 0;
30 }
31
32 static int ossl_hmac()
33 {
34         return 0;
35 }
36
37 // result = HMAC(EVP_sha256(), key, 999, data, 888, NULL, NULL);
38 //               EVP_MD *
39
40 // HMAC_CTX hctx;
41 // HMAC_CTX_init(&hctx);
42 // if (HMAC_Init(&hctx, key, keylen, EVP_sha1())) success;
43 // if (HMAC_Update(&hctx, data, datalen)) success;
44 // if (HMAC_Final(&hctx, &digest, &digestlen)) success
45 // HMAC_CTX_cleanup(&hctx);
46
47 struct crypto_interface ossl_crypto_if = {
48         .name           = "openssl",
49         .encrypt        = ossl_encrypt,
50         .decrypt        = ossl_decrypt,
51         .hash           = ossl_hash,
52         .hmac           = ossl_hmac,
53 };