documented updates
[cryptodev-linux.git] / lib / threshold.c
blobf1215a3e6c6cb95dd8be2a213f48f3862a99e3d4
1 #include <stdio.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <fcntl.h>
5 #include <sys/ioctl.h>
6 #include <crypto/cryptodev.h>
7 #include <openssl/aes.h>
8 #include <openssl/engine.h>
9 #include <openssl/hmac.h>
10 #include <openssl/evp.h>
11 #include "hash.h"
12 #include "threshold.h"
14 void sha_hash(void* text, int size, void* digest)
16 SHA_CTX ctx;
18 SHA_Init(&ctx);
20 SHA_Update(&ctx, text, size);
22 SHA_Final(digest, &ctx);
25 void aes_sha_combo(void* ctx, void* plaintext, void* ciphertext, int size, void* tag)
27 uint8_t iv[16];
28 AES_KEY* key = ctx;
29 HMAC_CTX hctx;
30 unsigned int rlen = 20;
32 HMAC_CTX_init(&hctx);
33 HMAC_Init_ex(&hctx, iv, 16, EVP_sha1(), NULL);
35 HMAC_Update(&hctx, plaintext, size);
37 HMAC_Final(&hctx, tag, &rlen);
38 HMAC_CTX_cleanup(&hctx);
40 AES_cbc_encrypt(plaintext, ciphertext, size, key, iv, 1);
43 int get_sha1_threshold()
45 return hash_test(CRYPTO_SHA1, sha_hash);
48 int get_aes_sha1_threshold()
50 AES_KEY key;
51 uint8_t ukey[16];
53 ENGINE_load_builtin_engines();
54 ENGINE_register_all_complete();
56 memset(ukey, 0xaf, sizeof(ukey));
57 AES_set_encrypt_key(ukey, 16*8, &key);
59 return aead_test(CRYPTO_AES_CBC, CRYPTO_SHA1, ukey, 16, &key, aes_sha_combo);