Skip to content

Commit

Permalink
Stashing LibNFC external USB reader test code online to test on Linux…
Browse files Browse the repository at this point in the history
… (builds on MacOS)
  • Loading branch information
maxieds committed Mar 30, 2022
1 parent f4faaa7 commit 19e0d1c
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Firmware/Chameleon-Mini/Application/CryptoAES128.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#define CRYPTO_AES_KEY_SIZE 16
typedef uint8_t CryptoAESKey_t[CRYPTO_AES_KEY_SIZE];

#define CRYPTO_AES_BLOCK_SIZE 16
#define CRYPTO_AES_BLOCK_SIZE 16
typedef uint8_t CryptoAESBlock_t[CRYPTO_AES_BLOCK_SIZE];

#define CryptoAESBytesToBlocks(byteCount) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@ uint16_t EV0CmdAuthenticateLegacy2(uint8_t *Buffer, uint16_t ByteCount) {
BYTE challengeRndB[CRYPTO_CHALLENGE_RESPONSE_BYTES];
Decrypt2K3DESBuffer(2 * CRYPTO_CHALLENGE_RESPONSE_BYTES, challengeRndAB,
&Buffer[1], NULL, Key);
RotateArrayRight(challengeRndAB + CRYPTO_CHALLENGE_RESPONSE_BYTES, challengeRndB,
CRYPTO_CHALLENGE_RESPONSE_BYTES);
RotateArrayLeft(challengeRndAB + CRYPTO_CHALLENGE_RESPONSE_BYTES, challengeRndB,
CRYPTO_CHALLENGE_RESPONSE_BYTES);
memcpy(challengeRndA, challengeRndAB, CRYPTO_CHALLENGE_RESPONSE_BYTES);

/* Check that the returned RndB matches what we sent in the previous round */
Expand All @@ -562,7 +562,7 @@ uint16_t EV0CmdAuthenticateLegacy2(uint8_t *Buffer, uint16_t ByteCount) {
}

/* Encrypt and send back the once rotated RndA buffer to the PCD */
RotateArrayLeft(challengeRndA, challengeRndAB, CRYPTO_CHALLENGE_RESPONSE_BYTES);
RotateArrayRight(challengeRndA, challengeRndAB, CRYPTO_CHALLENGE_RESPONSE_BYTES);
Encrypt2K3DESBuffer(CRYPTO_CHALLENGE_RESPONSE_BYTES, challengeRndAB,
&Buffer[1], NULL, Key);

Expand Down Expand Up @@ -845,7 +845,6 @@ uint16_t EV0CmdDeleteApplication(uint8_t *Buffer, uint16_t ByteCount) {
}
PiccKeySettings = GetPiccKeySettings();
const char *logMsg = PSTR("PICC key settings -- %02x");
DEBUG_PRINT_P(logMsg, PiccKeySettings);
/* Check the PICC key settings whether it is OK to delete using app master key */
if ((PiccKeySettings & DESFIRE_FREE_CREATE_DELETE) == 0x00) {
Status = STATUS_AUTHENTICATION_ERROR;
Expand Down
10 changes: 5 additions & 5 deletions Software/DESFireLibNFCTesting/LocalInclude/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
#define MAX_FRAME_LENGTH (264)
#define APPLICATION_AID_LENGTH (3)

static const inline uint8_t MASTER_APPLICATION_AID[] = {
static const uint8_t MASTER_APPLICATION_AID[] = {
0x00, 0x00, 0x00
};

static const inline uint8_t MASTER_KEY_INDEX = 0x00;
static const uint8_t MASTER_KEY_INDEX = 0x00;

static inline uint8_t CRYPTO_RNDB_STATE[] = {
static uint8_t CRYPTO_RNDB_STATE[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static inline bool AUTHENTICATED = false;
static inline int AUTHENTICATED_PROTO = 0;
static bool AUTHENTICATED = false;
static int AUTHENTICATED_PROTO = 0;

#endif
169 changes: 136 additions & 33 deletions Software/DESFireLibNFCTesting/LocalInclude/CryptoUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@

#include "LibNFCUtils.h"

/* DES Operation cipher mode */
#define CRYPTO_DES_ECB_MODE 0 // Electronic Code Book mode
#define CRYPTO_DES_CBC_MODE 1 // Cipher Block Chaining mode

/* AES Operation cipher mode */
#define CRYPTO_AES_ECB_MODE 0 // Electronic Code Book mode
#define CRYPTO_AES_CBC_MODE 1 // Cipher Block Chaining mode

#define DESFIRE_CRYPTO_AUTHTYPE_AES128 (1)
#define DESFIRE_CRYPTO_AUTHTYPE_ISODES (2)
#define DESFIRE_CRYPTO_AUTHTYPE_LEGACY (3)
Expand All @@ -23,24 +31,32 @@
#define CRYPTO_DES_BLOCK_SIZE (8)
#define CRYPTO_3KTDEA_BLOCK_SIZE (CRYPTO_DES_BLOCK_SIZE)
#define AES128_BLOCK_SIZE (16)
#define CRYPTO_MAX_BLOCK_SIZE (16)

typedef uint8_t CryptoAESBlock_t[AES128_BLOCK_SIZE];
static uint8_t SessionIV[CRYPTO_MAX_BLOCK_SIZE];

/* Key sizes, block sizes (in bytes): */
#define CRYPTO_MAX_KEY_SIZE (24)
#define CRYPTO_MAX_BLOCK_SIZE (16)

#define CRYPTO_CHALLENGE_RESPONSE_SIZE (16)

static const inline uint8_t ZERO_KEY[] = {
static const uint8_t ZERO_KEY[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static const inline uint8_t TEST_KEY1[] = {
static const uint8_t TEST_KEY1[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
};

static const inline uint8_t TEST_KEY1_INDEX = 0x01;
static const uint8_t TEST_KEY1_INDEX = 0x01;

typedef AES128Context DesfireAESCryptoContext;

Expand Down Expand Up @@ -82,25 +98,34 @@ static inline void PrintAESCryptoContext(DesfireAESCryptoContext *cryptoCtx) {
print_hex(cryptoCtx->keyData, 16);
}

/* Set the last operation mode (ECB or CBC) init for the context */
static uint8_t __CryptoAESOpMode = CRYPTO_AES_ECB_MODE;

static inline size_t EncryptAES128(const uint8_t *plainSrcBuf, size_t bufSize,
uint8_t *encDestBuf, CryptoData_t cdata) {
DesfireAESCryptoContext *cryptoCtx = &(cdata.cryptoCtx);
DesfireAESCryptoInit(cdata.keyData, cdata.keySize, cryptoCtx);
size_t bufBlocks = bufSize / AES128_BLOCK_SIZE;
bool padLastBlock = (bufSize % AES128_BLOCK_SIZE) != 0;
uint8_t IV[AES128_BLOCK_SIZE];
uint8_t *IV = SessionIV;
uint8_t inputBlock[AES128_BLOCK_SIZE];
memset(IV, 0x00, AES128_BLOCK_SIZE);
for (int blk = 0; blk < bufBlocks; blk++) {
uint8_t inputBlock[AES128_BLOCK_SIZE];
if (blk == 0) {
memcpy(inputBlock, &plainSrcBuf[0], AES128_BLOCK_SIZE);
if (__CryptoAESOpMode == CRYPTO_AES_CBC_MODE) {
if (blk == 0) {
memcpy(inputBlock, &plainSrcBuf[0], AES128_BLOCK_SIZE);
CryptoMemoryXOR(IV, inputBlock, AES128_BLOCK_SIZE);
} else {
memcpy(inputBlock, &encDestBuf[(blk - 1) * AES128_BLOCK_SIZE], AES128_BLOCK_SIZE);
CryptoMemoryXOR(&plainSrcBuf[blk * AES128_BLOCK_SIZE], inputBlock, AES128_BLOCK_SIZE);
}
aes128EncryptBlock(cryptoCtx, encDestBuf + blk * AES128_BLOCK_SIZE, inputBlock);
} else { /* ECB mode */
memcpy(inputBlock, &plainSrcBuf[blk * AES128_BLOCK_SIZE], AES128_BLOCK_SIZE);
CryptoMemoryXOR(IV, inputBlock, AES128_BLOCK_SIZE);
} else {
memcpy(inputBlock, &encDestBuf[(blk - 1) * AES128_BLOCK_SIZE], AES128_BLOCK_SIZE);
CryptoMemoryXOR(&plainSrcBuf[blk * AES128_BLOCK_SIZE], inputBlock, AES128_BLOCK_SIZE);
aes128EncryptBlock(cryptoCtx, encDestBuf + blk * AES128_BLOCK_SIZE, inputBlock);
memcpy(IV, encDestBuf + blk * AES128_BLOCK_SIZE, AES128_BLOCK_SIZE);
}
aes128EncryptBlock(cryptoCtx, encDestBuf + blk * AES128_BLOCK_SIZE,
inputBlock);
}
return bufSize;
}
Expand All @@ -111,27 +136,36 @@ static inline size_t DecryptAES128(const uint8_t *encSrcBuf, size_t bufSize,
DesfireAESCryptoInit(cdata.keyData, cdata.keySize, cryptoCtx);
size_t bufBlocks = (bufSize + AES128_BLOCK_SIZE - 1) / AES128_BLOCK_SIZE;
bool padLastBlock = (bufSize % AES128_BLOCK_SIZE) != 0;
uint8_t IV[AES128_BLOCK_SIZE];
uint8_t *IV = SessionIV;
uint8_t inputBlock[AES128_BLOCK_SIZE];
memset(IV, 0x00, AES128_BLOCK_SIZE);
for (int blk = 0; blk < bufBlocks; blk++) {
uint8_t inputBlock[AES128_BLOCK_SIZE];
aes128DecryptBlock(cryptoCtx, inputBlock, encSrcBuf + blk * AES128_BLOCK_SIZE);
if (blk == 0) {
memcpy(plainDestBuf + blk * AES128_BLOCK_SIZE, inputBlock, AES128_BLOCK_SIZE);
if (__CryptoAESOpMode == CRYPTO_AES_CBC_MODE) {
aes128DecryptBlock(cryptoCtx, inputBlock, encSrcBuf + blk * AES128_BLOCK_SIZE);
if (blk == 0) {
memcpy(plainDestBuf + blk * AES128_BLOCK_SIZE, inputBlock, AES128_BLOCK_SIZE);
CryptoMemoryXOR(IV, plainDestBuf + blk * AES128_BLOCK_SIZE, AES128_BLOCK_SIZE);
} else {
memcpy(plainDestBuf + blk * AES128_BLOCK_SIZE, inputBlock, AES128_BLOCK_SIZE);
CryptoMemoryXOR(&encSrcBuf[(blk - 1) * AES128_BLOCK_SIZE],
plainDestBuf + blk * AES128_BLOCK_SIZE, AES128_BLOCK_SIZE);
}
} else { /* ECB mode */
aes128DecryptBlock(cryptoCtx, plainDestBuf + blk * AES128_BLOCK_SIZE, encSrcBuf + blk * AES128_BLOCK_SIZE);
CryptoMemoryXOR(IV, plainDestBuf + blk * AES128_BLOCK_SIZE, AES128_BLOCK_SIZE);
} else {
memcpy(plainDestBuf + blk * AES128_BLOCK_SIZE, inputBlock, AES128_BLOCK_SIZE);
CryptoMemoryXOR(&encSrcBuf[(blk - 1) * AES128_BLOCK_SIZE],
plainDestBuf + blk * AES128_BLOCK_SIZE, AES128_BLOCK_SIZE);
memcpy(IV, encSrcBuf + blk * AES128_BLOCK_SIZE, AES128_BLOCK_SIZE);
}
}
return bufSize;
}

/* Set the last operation mode (ECB or CBC) init for the context */
static uint8_t __CryptoDESOpMode = CRYPTO_DES_ECB_MODE;

static inline size_t Encrypt2K3DES(const uint8_t *plainSrcBuf, size_t bufSize,
uint8_t *encDestBuf, const uint8_t *IVIn, CryptoData_t cdata) {
DES_key_schedule keySched1, keySched2;
uint8_t IV[2 * CRYPTO_DES_BLOCK_SIZE];
uint8_t *IV = SessionIV;
uint8_t *kd1 = cdata.keyData, *kd2 = &(cdata.keyData[CRYPTO_DES_BLOCK_SIZE]);
DES_set_key(kd1, &keySched1);
DES_set_key(kd2, &keySched2);
Expand All @@ -140,14 +174,26 @@ static inline size_t Encrypt2K3DES(const uint8_t *plainSrcBuf, size_t bufSize,
} else {
memcpy(IV, IVIn, 2 * CRYPTO_DES_BLOCK_SIZE);
}
DES_ede2_cbc_encrypt(plainSrcBuf, encDestBuf, bufSize, &keySched1, &keySched2, &IV, DES_ENCRYPT);
if (__CryptoDESOpMode == CRYPTO_DES_CBC_MODE) {
DES_ede2_cbc_encrypt(plainSrcBuf, encDestBuf, bufSize, &keySched1, &keySched2, &IV, DES_ENCRYPT);
} else {
uint8_t inputBlock[CRYPTO_DES_BLOCK_SIZE];
uint16_t numBlocks = bufSize / CRYPTO_DES_BLOCK_SIZE;
for (int blk = 0; blk < numBlocks; blk++) {
memcpy(inputBlock, &plainSrcBuf[blk * CRYPTO_DES_BLOCK_SIZE], CRYPTO_DES_BLOCK_SIZE);
CryptoMemoryXOR(IV, inputBlock, CRYPTO_DES_BLOCK_SIZE);
DES_ecb2_encrypt(&encDestBuf[blk * CRYPTO_DES_BLOCK_SIZE],
&plainSrcBuf[blk * CRYPTO_DES_BLOCK_SIZE], &keySched1, &keySched2, DES_ENCRYPT);
memcpy(IV, &encDestBuf[blk * CRYPTO_DES_BLOCK_SIZE], CRYPTO_DES_BLOCK_SIZE);
}
}
return bufSize;
}

static inline size_t Decrypt2K3DES(const uint8_t *encSrcBuf, size_t bufSize,
uint8_t *plainDestBuf, const uint8_t *IVIn, CryptoData_t cdata) {
DES_key_schedule keySched1, keySched2;
uint8_t IV[2 * CRYPTO_DES_BLOCK_SIZE];
uint8_t *IV = SessionIV;
uint8_t *kd1 = cdata.keyData, *kd2 = &(cdata.keyData[CRYPTO_DES_BLOCK_SIZE]);
DES_set_key(kd1, &keySched1);
DES_set_key(kd2, &keySched2);
Expand All @@ -156,14 +202,25 @@ static inline size_t Decrypt2K3DES(const uint8_t *encSrcBuf, size_t bufSize,
} else {
memcpy(IV, IVIn, 2 * CRYPTO_DES_BLOCK_SIZE);
}
DES_ede2_cbc_encrypt(encSrcBuf, plainDestBuf, bufSize, &keySched1, &keySched2, &IV, DES_DECRYPT);
if (__CryptoDESOpMode == CRYPTO_DES_CBC_MODE) {
DES_ede2_cbc_encrypt(encSrcBuf, plainDestBuf, bufSize, &keySched1, &keySched2, &IV, DES_DECRYPT);
} else {
uint8_t inputBlock[CRYPTO_DES_BLOCK_SIZE];
uint16_t numBlocks = bufSize / CRYPTO_DES_BLOCK_SIZE;
for (int blk = 0; blk < numBlocks; blk++) {
DES_ecb2_encrypt(&encSrcBuf[blk * CRYPTO_DES_BLOCK_SIZE],
&plainDestBuf[blk * CRYPTO_DES_BLOCK_SIZE], &keySched1, &keySched2, DES_DECRYPT);
CryptoMemoryXOR(IV, &plainDestBuf[blk * CRYPTO_DES_BLOCK_SIZE], CRYPTO_DES_BLOCK_SIZE);
memcpy(IV, &encSrcBuf[blk * CRYPTO_DES_BLOCK_SIZE], CRYPTO_DES_BLOCK_SIZE);
}
}
return bufSize;
}

static inline size_t Encrypt3DES(const uint8_t *plainSrcBuf, size_t bufSize,
uint8_t *encDestBuf, const uint8_t *IVIn, CryptoData_t cdata) {
DES_key_schedule keySched1, keySched2, keySched3;
uint8_t IV[CRYPTO_DES_BLOCK_SIZE];
uint8_t *IV = SessionIV;
uint8_t *kd1 = cdata.keyData, *kd2 = &(cdata.keyData[CRYPTO_DES_BLOCK_SIZE]), *kd3 = &(cdata.keyData[2 * CRYPTO_DES_BLOCK_SIZE]);
DES_set_key(kd1, &keySched1);
DES_set_key(kd2, &keySched2);
Expand All @@ -173,14 +230,26 @@ static inline size_t Encrypt3DES(const uint8_t *plainSrcBuf, size_t bufSize,
} else {
memcpy(IV, IVIn, CRYPTO_DES_BLOCK_SIZE);
}
DES_ede3_cbc_encrypt(plainSrcBuf, encDestBuf, bufSize, &keySched1, &keySched2, &keySched3, &IV, DES_ENCRYPT);
if (__CryptoDESOpMode == CRYPTO_DES_CBC_MODE) {
DES_ede3_cbc_encrypt(plainSrcBuf, encDestBuf, bufSize, &keySched1, &keySched2, &keySched3, &IV, DES_ENCRYPT);
} else {
uint8_t inputBlock[CRYPTO_DES_BLOCK_SIZE];
uint16_t numBlocks = bufSize / CRYPTO_DES_BLOCK_SIZE;
for (int blk = 0; blk < numBlocks; blk++) {
memcpy(inputBlock, &plainSrcBuf[blk * CRYPTO_DES_BLOCK_SIZE], CRYPTO_DES_BLOCK_SIZE);
CryptoMemoryXOR(IV, inputBlock, CRYPTO_DES_BLOCK_SIZE);
DES_ecb3_encrypt(&encDestBuf[blk * CRYPTO_DES_BLOCK_SIZE],
&plainSrcBuf[blk * CRYPTO_DES_BLOCK_SIZE], &keySched1, &keySched2, &keySched3, DES_ENCRYPT);
memcpy(IV, &encDestBuf[blk * CRYPTO_DES_BLOCK_SIZE], CRYPTO_DES_BLOCK_SIZE);
}
}
return bufSize;
}

static inline size_t Decrypt3DES(const uint8_t *encSrcBuf, size_t bufSize,
uint8_t *plainDestBuf, const uint8_t *IVIn, CryptoData_t cdata) {
DES_key_schedule keySched1, keySched2, keySched3;
uint8_t IV[CRYPTO_DES_BLOCK_SIZE];
uint8_t *IV = SessionIV;
uint8_t *kd1 = cdata.keyData, *kd2 = &(cdata.keyData[CRYPTO_DES_BLOCK_SIZE]), *kd3 = &(cdata.keyData[2 * CRYPTO_DES_BLOCK_SIZE]);
DES_set_key(kd1, &keySched1);
DES_set_key(kd2, &keySched2);
Expand All @@ -190,7 +259,18 @@ static inline size_t Decrypt3DES(const uint8_t *encSrcBuf, size_t bufSize,
} else {
memcpy(IV, IVIn, CRYPTO_DES_BLOCK_SIZE);
}
DES_ede3_cbc_encrypt(encSrcBuf, plainDestBuf, bufSize, &keySched1, &keySched2, &keySched3, &IV, DES_DECRYPT);
if (__CryptoDESOpMode == CRYPTO_DES_CBC_MODE) {
DES_ede3_cbc_encrypt(encSrcBuf, plainDestBuf, bufSize, &keySched1, &keySched2, &keySched3, &IV, DES_DECRYPT);
} else {
uint8_t inputBlock[CRYPTO_DES_BLOCK_SIZE];
uint16_t numBlocks = bufSize / CRYPTO_DES_BLOCK_SIZE;
for (int blk = 0; blk < numBlocks; blk++) {
DES_ecb3_encrypt(&encSrcBuf[blk * CRYPTO_DES_BLOCK_SIZE],
&plainDestBuf[blk * CRYPTO_DES_BLOCK_SIZE], &keySched1, &keySched2, &keySched3, DES_DECRYPT);
CryptoMemoryXOR(IV, &plainDestBuf[blk * CRYPTO_DES_BLOCK_SIZE], CRYPTO_DES_BLOCK_SIZE);
memcpy(IV, &encSrcBuf[blk * CRYPTO_DES_BLOCK_SIZE], CRYPTO_DES_BLOCK_SIZE);
}
}
return bufSize;
}

Expand All @@ -200,13 +280,25 @@ static inline size_t EncryptDES(const uint8_t *plainSrcBuf, size_t bufSize,
DES_key_schedule keySched;
uint8_t *kd = cdata.keyData;
DES_set_key(kd, &keySched);
uint8_t IV[CRYPTO_DES_BLOCK_SIZE];
uint8_t *IV = SessionIV;
if (IVIn == NULL) {
memset(IV, 0x00, CRYPTO_DES_BLOCK_SIZE);
} else {
memcpy(IV, IVIn, CRYPTO_DES_BLOCK_SIZE);
}
DES_cbc_encrypt(plainSrcBuf, encDestBuf, bufSize, &keySched, &IV, DES_ENCRYPT);
if (__CryptoDESOpMode == CRYPTO_DES_CBC_MODE) {
DES_cbc_encrypt(plainSrcBuf, encDestBuf, bufSize, &keySched, &IV, DES_ENCRYPT);
} else {
uint8_t inputBlock[CRYPTO_DES_BLOCK_SIZE];
uint16_t numBlocks = bufSize / CRYPTO_DES_BLOCK_SIZE;
for (int blk = 0; blk < numBlocks; blk++) {
memcpy(inputBlock, &plainSrcBuf[blk * CRYPTO_DES_BLOCK_SIZE], CRYPTO_DES_BLOCK_SIZE);
CryptoMemoryXOR(IV, inputBlock, CRYPTO_DES_BLOCK_SIZE);
DES_ecb_encrypt(&encDestBuf[blk * CRYPTO_DES_BLOCK_SIZE],
&plainSrcBuf[blk * CRYPTO_DES_BLOCK_SIZE], &keySched, DES_ENCRYPT);
memcpy(IV, &encDestBuf[blk * CRYPTO_DES_BLOCK_SIZE], CRYPTO_DES_BLOCK_SIZE);
}
}
return bufSize;
}

Expand All @@ -215,13 +307,24 @@ static inline size_t DecryptDES(const uint8_t *encSrcBuf, size_t bufSize,
DES_key_schedule keySched;
uint8_t *kd = cdata.keyData;
DES_set_key(kd, &keySched);
uint8_t IV[CRYPTO_DES_BLOCK_SIZE];
uint8_t *IV = SessionIV;
if (IVIn == NULL) {
memset(IV, 0x00, CRYPTO_DES_BLOCK_SIZE);
} else {
memcpy(IV, IVIn, CRYPTO_DES_BLOCK_SIZE);
}
DES_cbc_encrypt(encSrcBuf, plainDestBuf, bufSize, &keySched, &IV, DES_DECRYPT);
if (__CryptoDESOpMode == CRYPTO_DES_CBC_MODE) {
DES_cbc_encrypt(encSrcBuf, plainDestBuf, bufSize, &keySched, &IV, DES_DECRYPT);
} else {
uint8_t inputBlock[CRYPTO_DES_BLOCK_SIZE];
uint16_t numBlocks = bufSize / CRYPTO_DES_BLOCK_SIZE;
for (int blk = 0; blk < numBlocks; blk++) {
DES_ecb_encrypt(&encSrcBuf[blk * CRYPTO_DES_BLOCK_SIZE],
&plainDestBuf[blk * CRYPTO_DES_BLOCK_SIZE], &keySched, DES_DECRYPT);
CryptoMemoryXOR(IV, &plainDestBuf[blk * CRYPTO_DES_BLOCK_SIZE], CRYPTO_DES_BLOCK_SIZE);
memcpy(IV, &encSrcBuf[blk * CRYPTO_DES_BLOCK_SIZE], CRYPTO_DES_BLOCK_SIZE);
}
}
return bufSize;
}

Expand Down
Loading

0 comments on commit 19e0d1c

Please sign in to comment.