My Project
Functions
Algorithms - 3DES

Functions

int wc_Des_SetKey (Des *des, const byte *key, const byte *iv, int dir)
 This function sets the key and initialization vector (iv) for the Des structure given as argument. It also initializes and allocates space for the buffers needed for encryption and decryption, if these have not yet been initialized. Note: If no iv is provided (i.e. iv == NULL) the initialization vector defaults to an iv of 0. More...
 
void wc_Des_SetIV (Des *des, const byte *iv)
 This function sets the initialization vector (iv) for the Des structure given as argument. When passed a NULL iv, it sets the initialization vector to 0. More...
 
int wc_Des_CbcEncrypt (Des *des, byte *out, const byte *in, word32 sz)
 This function encrypts the input message, in, and stores the result in the output buffer, out. It uses DES encryption with cipher block chaining (CBC) mode. More...
 
int wc_Des_CbcDecrypt (Des *des, byte *out, const byte *in, word32 sz)
 This function decrypts the input ciphertext, in, and stores the resulting plaintext in the output buffer, out. It uses DES encryption with cipher block chaining (CBC) mode. More...
 
int wc_Des_EcbEncrypt (Des *des, byte *out, const byte *in, word32 sz)
 This function encrypts the input message, in, and stores the result in the output buffer, out. It uses Des encryption with Electronic Codebook (ECB) mode. More...
 
int wc_Des3_EcbEncrypt (Des3 *des, byte *out, const byte *in, word32 sz)
 This function encrypts the input message, in, and stores the result in the output buffer, out. It uses Des3 encryption with Electronic Codebook (ECB) mode. Warning: In nearly all use cases ECB mode is considered to be less secure. Please avoid using ECB API’s directly whenever possible. More...
 
int wc_Des3_SetKey (Des3 *des, const byte *key, const byte *iv, int dir)
 This function sets the key and initialization vector (iv) for the Des3 structure given as argument. It also initializes and allocates space for the buffers needed for encryption and decryption, if these have not yet been initialized. Note: If no iv is provided (i.e. iv == NULL) the initialization vector defaults to an iv of 0. More...
 
int wc_Des3_SetIV (Des3 *des, const byte *iv)
 This function sets the initialization vector (iv) for the Des3 structure given as argument. When passed a NULL iv, it sets the initialization vector to 0. More...
 
int wc_Des3_CbcEncrypt (Des3 *des, byte *out, const byte *in, word32 sz)
 This function encrypts the input message, in, and stores the result in the output buffer, out. It uses Triple Des (3DES) encryption with cipher block chaining (CBC) mode. More...
 
int wc_Des3_CbcDecrypt (Des3 *des, byte *out, const byte *in, word32 sz)
 This function decrypts the input ciphertext, in, and stores the resulting plaintext in the output buffer, out. It uses Triple Des (3DES) encryption with cipher block chaining (CBC) mode. More...
 
int wc_Des_CbcDecryptWithKey (byte *out, const byte *in, word32 sz, const byte *key, const byte *iv)
 This function decrypts the input ciphertext, in, and stores the resulting plaintext in the output buffer, out. It uses DES encryption with cipher block chaining (CBC) mode. This function is a substitute for wc_Des_CbcDecrypt, allowing the user to decrypt a message without directly instantiating a Des structure. More...
 
int wc_Des_CbcEncryptWithKey (byte *out, const byte *in, word32 sz, const byte *key, const byte *iv)
 This function encrypts the input plaintext, in, and stores the resulting ciphertext in the output buffer, out. It uses DES encryption with cipher block chaining (CBC) mode. This function is a substitute for wc_Des_CbcEncrypt, allowing the user to encrypt a message without directly instantiating a Des structure. More...
 
int wc_Des3_CbcEncryptWithKey (byte *out, const byte *in, word32 sz, const byte *key, const byte *iv)
 This function encrypts the input plaintext, in, and stores the resulting ciphertext in the output buffer, out. It uses Triple DES (3DES) encryption with cipher block chaining (CBC) mode. This function is a substitute for wc_Des3_CbcEncrypt, allowing the user to encrypt a message without directly instantiating a Des3 structure. More...
 
int wc_Des3_CbcDecryptWithKey (byte *out, const byte *in, word32 sz, const byte *key, const byte *iv)
 This function decrypts the input ciphertext, in, and stores the resulting plaintext in the output buffer, out. It uses Triple Des (3DES) encryption with cipher block chaining (CBC) mode. This function is a substitute for wc_Des3_CbcDecrypt, allowing the user to decrypt a message without directly instantiating a Des3 structure. More...
 

Detailed Description

Function Documentation

◆ wc_Des3_CbcDecrypt()

int wc_Des3_CbcDecrypt ( Des3 *  des,
byte *  out,
const byte *  in,
word32  sz 
)

This function decrypts the input ciphertext, in, and stores the resulting plaintext in the output buffer, out. It uses Triple Des (3DES) encryption with cipher block chaining (CBC) mode.

3

Returns
0 Returned upon successfully decrypting the given ciphertext
Parameters
despointer to the Des3 structure to use for decryption
outpointer to the buffer in which to store the decrypted plaintext
inpointer to the input buffer containing the encrypted ciphertext
szlength of the ciphertext to decrypt

Example

Des3 dec; // Des structure used for decryption
// initialize dec with wc_Des3_SetKey, use mode DES_DECRYPTION
byte cipher[] = { // initialize with ciphertext };
byte decoded[sizeof(cipher)];
if ( wc_Des3_CbcDecrypt(&dec, decoded, cipher, sizeof(cipher)) != 0) {
// error decrypting message
}
int wc_Des3_CbcDecrypt(Des3 *des, byte *out, const byte *in, word32 sz)
This function decrypts the input ciphertext, in, and stores the resulting plaintext in the output buf...
See also
wc_Des3_SetKey
wc_Des3_CbcEncrypt

◆ wc_Des3_CbcDecryptWithKey()

int wc_Des3_CbcDecryptWithKey ( byte *  out,
const byte *  in,
word32  sz,
const byte *  key,
const byte *  iv 
)

This function decrypts the input ciphertext, in, and stores the resulting plaintext in the output buffer, out. It uses Triple Des (3DES) encryption with cipher block chaining (CBC) mode. This function is a substitute for wc_Des3_CbcDecrypt, allowing the user to decrypt a message without directly instantiating a Des3 structure.

3

Returns
0 Returned upon successfully decrypting the given ciphertext
MEMORY_E Returned if there is an error allocating space for a Des structure
Parameters
outpointer to the buffer in which to store the decrypted plaintext
inpointer to the input buffer containing the encrypted ciphertext
szlength of the ciphertext to decrypt
keypointer to the buffer containing the 24 byte key to use for decryption
ivpointer to the buffer containing the 8 byte iv to use for decryption. If no iv is provided, the iv defaults to 0

Example

int ret;
byte key[] = { // initialize with 24 byte key };
byte iv[] = { // initialize with 8 byte iv };
byte cipher[] = { // initialize with ciphertext };
byte decoded[sizeof(cipher)];
if ( wc_Des3_CbcDecryptWithKey(decoded, cipher, sizeof(cipher),
key, iv) != 0) {
// error decrypting message
}
int wc_Des3_CbcDecryptWithKey(byte *out, const byte *in, word32 sz, const byte *key, const byte *iv)
This function decrypts the input ciphertext, in, and stores the resulting plaintext in the output buf...
See also
wc_Des3_CbcDecrypt

◆ wc_Des3_CbcEncrypt()

int wc_Des3_CbcEncrypt ( Des3 *  des,
byte *  out,
const byte *  in,
word32  sz 
)

This function encrypts the input message, in, and stores the result in the output buffer, out. It uses Triple Des (3DES) encryption with cipher block chaining (CBC) mode.

3

Returns
0 Returned upon successfully encrypting the given input message
Parameters
despointer to the Des3 structure to use for encryption
outpointer to the buffer in which to store the encrypted ciphertext
inpointer to the input buffer containing the message to encrypt
szlength of the message to encrypt

Example

Des3 enc; // Des3 structure used for encryption
// initialize enc with wc_Des3_SetKey, use mode DES_ENCRYPTION
byte plain[] = { // initialize with message };
byte cipher[sizeof(plain)];
if ( wc_Des3_CbcEncrypt(&enc, cipher, plain, sizeof(plain)) != 0) {
// error encrypting message
}
int wc_Des3_CbcEncrypt(Des3 *des, byte *out, const byte *in, word32 sz)
This function encrypts the input message, in, and stores the result in the output buffer,...
See also
wc_Des3_SetKey
wc_Des3_CbcDecrypt

◆ wc_Des3_CbcEncryptWithKey()

int wc_Des3_CbcEncryptWithKey ( byte *  out,
const byte *  in,
word32  sz,
const byte *  key,
const byte *  iv 
)

This function encrypts the input plaintext, in, and stores the resulting ciphertext in the output buffer, out. It uses Triple DES (3DES) encryption with cipher block chaining (CBC) mode. This function is a substitute for wc_Des3_CbcEncrypt, allowing the user to encrypt a message without directly instantiating a Des3 structure.

3

Returns
0 Returned after successfully encrypting data.
MEMORY_E Returned if there's an error allocating memory for a Des structure.
<0 Returned on any error during encryption.
Parameters
outFinal encrypted data
inData to be encrypted, must be padded to Des block size.
szSize of input buffer.
keyPointer to the key to use for encryption.
ivInitialization vector

Example

byte key[] = { // initialize with 8 byte key };
byte iv[] = { // initialize with 8 byte iv };
byte in[] = { // Initialize with plaintext };
byte out[sizeof(in)];
if ( wc_Des3_CbcEncryptWithKey(&out, in, sizeof(in), key, iv) != 0)
{
// error encrypting message
}
int wc_Des3_CbcEncryptWithKey(byte *out, const byte *in, word32 sz, const byte *key, const byte *iv)
This function encrypts the input plaintext, in, and stores the resulting ciphertext in the output buf...
See also
wc_Des3_CbcDecryptWithKey
wc_Des_CbcEncryptWithKey
wc_Des_CbcDecryptWithKey

◆ wc_Des3_EcbEncrypt()

int wc_Des3_EcbEncrypt ( Des3 *  des,
byte *  out,
const byte *  in,
word32  sz 
)

This function encrypts the input message, in, and stores the result in the output buffer, out. It uses Des3 encryption with Electronic Codebook (ECB) mode. Warning: In nearly all use cases ECB mode is considered to be less secure. Please avoid using ECB API’s directly whenever possible.

3

Returns
0 Returned upon successfully encrypting the given plaintext
Parameters
des3pointer to the Des3 structure to use for encryption
outpointer to the buffer in which to store the encrypted message
inpointer to the input buffer containing the plaintext to encrypt
szlength of the plaintext to encrypt

Example

Des3 enc; // Des3 structure used for encryption
// initialize enc with wc_Des3_SetKey, use mode DES_ENCRYPTION
byte plain[] = { // initialize with message to encrypt };
byte cipher[sizeof(plain)];
if ( wc_Des3_EcbEncrypt(&enc,cipher, plain, sizeof(plain)) != 0) {
// error encrypting message
}
int wc_Des3_EcbEncrypt(Des3 *des, byte *out, const byte *in, word32 sz)
This function encrypts the input message, in, and stores the result in the output buffer,...
See also
wc_Des3_SetKey

◆ wc_Des3_SetIV()

int wc_Des3_SetIV ( Des3 *  des,
const byte *  iv 
)

This function sets the initialization vector (iv) for the Des3 structure given as argument. When passed a NULL iv, it sets the initialization vector to 0.

3

Returns
none No returns.
Parameters
despointer to the Des3 structure for which to set the iv
ivpointer to the buffer containing the 8 byte iv with which to initialize the Des3 structure. If this is not provided, the iv defaults to 0

Example

Des3 enc; // Des3 structure used for encryption
// initialize enc with wc_Des3_SetKey
byte iv[] = { // initialize with 8 byte iv };
wc_Des3_SetIV(&enc, iv);
}
int wc_Des3_SetIV(Des3 *des, const byte *iv)
This function sets the initialization vector (iv) for the Des3 structure given as argument....
See also
wc_Des3_SetKey

◆ wc_Des3_SetKey()

int wc_Des3_SetKey ( Des3 *  des,
const byte *  key,
const byte *  iv,
int  dir 
)

This function sets the key and initialization vector (iv) for the Des3 structure given as argument. It also initializes and allocates space for the buffers needed for encryption and decryption, if these have not yet been initialized. Note: If no iv is provided (i.e. iv == NULL) the initialization vector defaults to an iv of 0.

3

Returns
0 On successfully setting the key and initialization vector for the Des structure
Parameters
des3pointer to the Des3 structure to initialize
keypointer to the buffer containing the 24 byte key with which to initialize the Des3 structure
ivpointer to the buffer containing the 8 byte iv with which to initialize the Des3 structure. If this is not provided, the iv defaults to 0
dirdirection of encryption. Valid options are: DES_ENCRYPTION, and DES_DECRYPTION

Example

Des3 enc; // Des3 structure used for encryption
int ret;
byte key[] = { // initialize with 24 byte key };
byte iv[] = { // initialize with 8 byte iv };
ret = wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION);
if (ret != 0) {
// error initializing des structure
}
int wc_Des3_SetKey(Des3 *des, const byte *key, const byte *iv, int dir)
This function sets the key and initialization vector (iv) for the Des3 structure given as argument....
See also
wc_Des3_SetIV
wc_Des3_CbcEncrypt
wc_Des3_CbcDecrypt

◆ wc_Des_CbcDecrypt()

int wc_Des_CbcDecrypt ( Des *  des,
byte *  out,
const byte *  in,
word32  sz 
)

This function decrypts the input ciphertext, in, and stores the resulting plaintext in the output buffer, out. It uses DES encryption with cipher block chaining (CBC) mode.

3

Returns
0 Returned upon successfully decrypting the given ciphertext
Parameters
despointer to the Des structure to use for decryption
outpointer to the buffer in which to store the decrypted plaintext
inpointer to the input buffer containing the encrypted ciphertext
szlength of the ciphertext to decrypt

Example

Des dec; // Des structure used for decryption
// initialize dec with wc_Des_SetKey, use mode DES_DECRYPTION
byte cipher[] = { // initialize with ciphertext };
byte decoded[sizeof(cipher)];
if ( wc_Des_CbcDecrypt(&dec, decoded, cipher, sizeof(cipher)) != 0) {
// error decrypting message
}
int wc_Des_CbcDecrypt(Des *des, byte *out, const byte *in, word32 sz)
This function decrypts the input ciphertext, in, and stores the resulting plaintext in the output buf...
See also
wc_Des_SetKey
wc_Des_CbcEncrypt

◆ wc_Des_CbcDecryptWithKey()

int wc_Des_CbcDecryptWithKey ( byte *  out,
const byte *  in,
word32  sz,
const byte *  key,
const byte *  iv 
)

This function decrypts the input ciphertext, in, and stores the resulting plaintext in the output buffer, out. It uses DES encryption with cipher block chaining (CBC) mode. This function is a substitute for wc_Des_CbcDecrypt, allowing the user to decrypt a message without directly instantiating a Des structure.

3

Returns
0 Returned upon successfully decrypting the given ciphertext
MEMORY_E Returned if there is an error allocating space for a Des structure
Parameters
outpointer to the buffer in which to store the decrypted plaintext
inpointer to the input buffer containing the encrypted ciphertext
szlength of the ciphertext to decrypt
keypointer to the buffer containing the 8 byte key to use for decryption
ivpointer to the buffer containing the 8 byte iv to use for decryption. If no iv is provided, the iv defaults to 0

Example

int ret;
byte key[] = { // initialize with 8 byte key };
byte iv[] = { // initialize with 8 byte iv };
byte cipher[] = { // initialize with ciphertext };
byte decoded[sizeof(cipher)];
if ( wc_Des_CbcDecryptWithKey(decoded, cipher, sizeof(cipher), key,
iv) != 0) {
// error decrypting message
}
int wc_Des_CbcDecryptWithKey(byte *out, const byte *in, word32 sz, const byte *key, const byte *iv)
This function decrypts the input ciphertext, in, and stores the resulting plaintext in the output buf...
See also
wc_Des_CbcDecrypt

◆ wc_Des_CbcEncrypt()

int wc_Des_CbcEncrypt ( Des *  des,
byte *  out,
const byte *  in,
word32  sz 
)

This function encrypts the input message, in, and stores the result in the output buffer, out. It uses DES encryption with cipher block chaining (CBC) mode.

3

Returns
0 Returned upon successfully encrypting the given input message
Parameters
despointer to the Des structure to use for encryption
outpointer to the buffer in which to store the encrypted ciphertext
inpointer to the input buffer containing the message to encrypt
szlength of the message to encrypt

Example

Des enc; // Des structure used for encryption
// initialize enc with wc_Des_SetKey, use mode DES_ENCRYPTION
byte plain[] = { // initialize with message };
byte cipher[sizeof(plain)];
if ( wc_Des_CbcEncrypt(&enc, cipher, plain, sizeof(plain)) != 0) {
// error encrypting message
}
int wc_Des_CbcEncrypt(Des *des, byte *out, const byte *in, word32 sz)
This function encrypts the input message, in, and stores the result in the output buffer,...
See also
wc_Des_SetKey
wc_Des_CbcDecrypt

◆ wc_Des_CbcEncryptWithKey()

int wc_Des_CbcEncryptWithKey ( byte *  out,
const byte *  in,
word32  sz,
const byte *  key,
const byte *  iv 
)

This function encrypts the input plaintext, in, and stores the resulting ciphertext in the output buffer, out. It uses DES encryption with cipher block chaining (CBC) mode. This function is a substitute for wc_Des_CbcEncrypt, allowing the user to encrypt a message without directly instantiating a Des structure.

3

Returns
0 Returned after successfully encrypting data.
MEMORY_E Returned if there's an error allocating memory for a Des structure.
<0 Returned on any error during encryption.
Parameters
outFinal encrypted data
inData to be encrypted, must be padded to Des block size.
szSize of input buffer.
keyPointer to the key to use for encryption.
ivInitialization vector

Example

byte key[] = { // initialize with 8 byte key };
byte iv[] = { // initialize with 8 byte iv };
byte in[] = { // Initialize with plaintext };
byte out[sizeof(in)];
if ( wc_Des_CbcEncryptWithKey(&out, in, sizeof(in), key, iv) != 0)
{
// error encrypting message
}
int wc_Des_CbcEncryptWithKey(byte *out, const byte *in, word32 sz, const byte *key, const byte *iv)
This function encrypts the input plaintext, in, and stores the resulting ciphertext in the output buf...
See also
wc_Des_CbcDecryptWithKey
wc_Des_CbcEncrypt

◆ wc_Des_EcbEncrypt()

int wc_Des_EcbEncrypt ( Des *  des,
byte *  out,
const byte *  in,
word32  sz 
)

This function encrypts the input message, in, and stores the result in the output buffer, out. It uses Des encryption with Electronic Codebook (ECB) mode.

3

Returns
0: Returned upon successfully encrypting the given plaintext.
Parameters
despointer to the Des structure to use for encryption
outpointer to the buffer in which to store the encrypted message
inpointer to the input buffer containing the plaintext to encrypt
szlength of the plaintext to encrypt

Example

Des enc; // Des structure used for encryption
// initialize enc with wc_Des_SetKey, use mode DES_ENCRYPTION
byte plain[] = { // initialize with message to encrypt };
byte cipher[sizeof(plain)];
if ( wc_Des_EcbEncrypt(&enc,cipher, plain, sizeof(plain)) != 0) {
// error encrypting message
}
int wc_Des_EcbEncrypt(Des *des, byte *out, const byte *in, word32 sz)
This function encrypts the input message, in, and stores the result in the output buffer,...
See also
wc_Des_SetKe

◆ wc_Des_SetIV()

void wc_Des_SetIV ( Des *  des,
const byte *  iv 
)

This function sets the initialization vector (iv) for the Des structure given as argument. When passed a NULL iv, it sets the initialization vector to 0.

3

Returns
none No returns.
Parameters
despointer to the Des structure for which to set the iv
ivpointer to the buffer containing the 8 byte iv with which to initialize the Des structure. If this is not provided, the iv defaults to 0

Example

Des enc; // Des structure used for encryption
// initialize enc with wc_Des_SetKey
byte iv[] = { // initialize with 8 byte iv };
wc_Des_SetIV(&enc, iv);
}
void wc_Des_SetIV(Des *des, const byte *iv)
This function sets the initialization vector (iv) for the Des structure given as argument....
See also
wc_Des_SetKey

◆ wc_Des_SetKey()

int wc_Des_SetKey ( Des *  des,
const byte *  key,
const byte *  iv,
int  dir 
)

This function sets the key and initialization vector (iv) for the Des structure given as argument. It also initializes and allocates space for the buffers needed for encryption and decryption, if these have not yet been initialized. Note: If no iv is provided (i.e. iv == NULL) the initialization vector defaults to an iv of 0.

3

Returns
0 On successfully setting the key and initialization vector for the Des structure
Parameters
despointer to the Des structure to initialize
keypointer to the buffer containing the 8 byte key with which to initialize the Des structure
ivpointer to the buffer containing the 8 byte iv with which to initialize the Des structure. If this is not provided, the iv defaults to 0
dirdirection of encryption. Valid options are: DES_ENCRYPTION, and DES_DECRYPTION

Example

Des enc; // Des structure used for encryption
int ret;
byte key[] = { // initialize with 8 byte key };
byte iv[] = { // initialize with 8 byte iv };
ret = wc_Des_SetKey(&des, key, iv, DES_ENCRYPTION);
if (ret != 0) {
// error initializing des structure
}
int wc_Des_SetKey(Des *des, const byte *key, const byte *iv, int dir)
This function sets the key and initialization vector (iv) for the Des structure given as argument....
See also
wc_Des_SetIV
wc_Des3_SetKey