Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/tomcrypt/src/modes/ecb/ecb_encrypt.c
5972 views
1
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2
*
3
* LibTomCrypt is a library that provides various cryptographic
4
* algorithms in a highly modular and flexible manner.
5
*
6
* The library is free for all purposes without any express
7
* guarantee it works.
8
*/
9
#include "tomcrypt.h"
10
11
/**
12
@file ecb_encrypt.c
13
ECB implementation, encrypt a block, Tom St Denis
14
*/
15
16
#ifdef LTC_ECB_MODE
17
18
/**
19
ECB encrypt
20
@param pt Plaintext
21
@param ct [out] Ciphertext
22
@param len The number of octets to process (must be multiple of the cipher block size)
23
@param ecb ECB state
24
@return CRYPT_OK if successful
25
*/
26
int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb)
27
{
28
int err;
29
LTC_ARGCHK(pt != NULL);
30
LTC_ARGCHK(ct != NULL);
31
LTC_ARGCHK(ecb != NULL);
32
if ((err = cipher_is_valid(ecb->cipher)) != CRYPT_OK) {
33
return err;
34
}
35
if (len % cipher_descriptor[ecb->cipher].block_length) {
36
return CRYPT_INVALID_ARG;
37
}
38
39
/* check for accel */
40
if (cipher_descriptor[ecb->cipher].accel_ecb_encrypt != NULL) {
41
return cipher_descriptor[ecb->cipher].accel_ecb_encrypt(pt, ct, len / cipher_descriptor[ecb->cipher].block_length, &ecb->key);
42
} else {
43
while (len) {
44
if ((err = cipher_descriptor[ecb->cipher].ecb_encrypt(pt, ct, &ecb->key)) != CRYPT_OK) {
45
return err;
46
}
47
pt += cipher_descriptor[ecb->cipher].block_length;
48
ct += cipher_descriptor[ecb->cipher].block_length;
49
len -= cipher_descriptor[ecb->cipher].block_length;
50
}
51
}
52
return CRYPT_OK;
53
}
54
55
#endif
56
57