Skip to content

Latest commit

 

History

History
60 lines (40 loc) · 1.57 KB

GUID-994EE987-AAE2-49B4-84D4-2DB4BB4BD21E.md

File metadata and controls

60 lines (40 loc) · 1.57 KB

CRYPT_TDES_KeySet Function

Parent topic:MPLAB® Harmony Crypto Library

C

int CRYPT_TDES_KeySet(
    CRYPT_TDES_CTX* tdes, 
    const unsigned char* key, 
    const unsigned char* iv, 
    int dir
);

Description

This function sets the key and initialization vector (IV) for a set of Triple-DES operations.

Preconditions

None.

Parameters

Parameters Description
tdes Pointer to context which saves state between calls.
key Pointer to buffer holding the key. Must be 24 bytes in size.
iv Pointer to buffer holding the initialization vector. Must be 8 bytes in size.
dir Indicates whether encryption or decryption will be done. Can be set to CRYPT_TDES_ENCRYPTION for encryption operations or CRYPT_TDES_DECRYPTION for decryption operations.

Returns

  • BAD_FUNC_ARG - An invalid pointer was passed to the function.

  • 0 - An invalid pointer was not passed to the function.

Remarks

The input data must be a multiple of 8 bytes, and must be padded at the end with zeros to meet the length.

Example

CRYPT_TDES_CTX mcDes3;
int            ret;
byte           out1[TDES_SIZE];
byte           out2[TDES_SIZE];

strncpy((char*)key, "1234567890abcdefghijklmn", 24);
strncpy((char*)iv,  "12345678", 8);

ret = CRYPT_TDES_KeySet(&mcDes3, key, iv, CRYPT_TDES_ENCRYPTION);
ret = CRYPT_TDES_CBC_Encrypt(&mcDes3, out1, ourData, TDES_SIZE);
ret = CRYPT_TDES_KeySet(&mcDes3, key, iv, CRYPT_TDES_DECRYPTION);
ret = CRYPT_TDES_CBC_Decrypt(&mcDes3, out2, out1, TDES_TEST_SIZE);