2 Copyright (c) 2013 Eugene Crosser
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
12 1. The origin of this software must not be misrepresented; you must
13 not claim that you wrote the original software. If you use this
14 software in a product, an acknowledgment in the product documentation
15 would be appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must
18 not be misrepresented as being the original software.
20 3. This notice may not be removed or altered from any source
29 #include "crypto_if.h"
31 static const char *tom_init(void)
33 /* nothing to initialize */
37 static unsigned long tom_encrypt(const void *key, const size_t keylen, void *iv,
38 const void *pt, void *ct, const size_t tlen)
43 if ((index = register_cipher(&aes_desc)) == -1)
44 return CRYPT_INVALID_CIPHER;
45 if ((err = cbc_start(index, iv, key, keylen, 0, &cbc)) != CRYPT_OK)
47 err= cbc_encrypt(pt, ct, tlen, &cbc);
52 static unsigned long tom_decrypt(const void *key, const size_t keylen, void *iv,
53 const void *ct, void *pt, const size_t tlen)
58 if ((index = register_cipher(&aes_desc)) == -1)
59 return CRYPT_INVALID_CIPHER;
60 if ((err = cbc_start(index, iv, key, keylen, 0, &cbc)) != CRYPT_OK)
62 err= cbc_decrypt(ct, pt, tlen, &cbc);
67 static unsigned long tom_hash(const void *pt, const size_t tlen,
68 void *tag, size_t *taglen)
71 unsigned long ltaglen = *taglen;
73 if ((index = register_hash(&sha1_desc)) == -1)
74 return CRYPT_INVALID_HASH;
75 rc = hash_memory(index, pt, tlen, tag, <aglen);
80 static unsigned long tom_hmac(const void *key, const size_t keylen,
81 const void *pt, const size_t tlen,
82 void *tag, size_t *taglen)
85 unsigned long ltaglen = *taglen;
87 if ((index = register_hash(&sha1_desc)) == -1)
88 return CRYPT_INVALID_HASH;
89 rc = hmac_memory(index, key, keylen, pt, tlen, tag, <aglen);
94 static const char *tom_errstr(const unsigned long err)
96 return error_to_string((int)err);
99 struct crypto_interface tom_crypto_if = {
101 .encrypt = tom_encrypt,
102 .decrypt = tom_decrypt,
105 .errstr = tom_errstr,