cdb02d05aee3f46b71f01f0e3f2dd2728fc3431d
[pam_pcsc_cr.git] / tom_crypto.c
1 #include <tomcrypt.h>
2
3 #include "crypto_if.h"
4
5 static int tom_encrypt(void *pt, int ptlen, void *key, int keylen,
6                         void *ct, int *ctlen)
7 {
8         symmentric_cbc cbc;
9         unsigned char iv[16] = {0};
10         int index, err;
11
12         if ((index = register_cipher(&aes_desc)) == -1) return -1;
13         // if ((index = find_cipher("aes")) == -1) return -1;
14         cipher = cipher_descriptor[index];
15         if ((err = cbc_start(index, iv, key, keylen, 0, &cbc)) != CRYPT_OK)
16                 return err;
17         if ((err = cbc_encrypt(pt, ct, ptlen, &cbc)) != CRYPT_OK)
18                 return err;
19         if ((err = cbc_done(&cbc)) != CRYPT_OK)
20                 return err;
21         if ((err = unregister_cipher(&aes_desc)) != CRYPT_OK)
22                 return err;
23         return 0;
24 }
25
26 static int tom_decrypt()
27 {
28         return 0;
29 }
30
31 static int tom_hash()
32 {
33         return 0;
34 }
35
36 static int tom_hmac()
37 {
38         return 0;
39 }
40
41 struct crypto_interface tom_crypto_if = {
42         .name           = "tomcrypt",
43         .encrypt        = tom_encrypt,
44         .decrypt        = tom_decrypt,
45         .hash           = tom_hash,
46         .hmac           = tom_hmac,
47 };