From: couturie Date: Sat, 30 Sep 2017 12:16:48 +0000 (+0200) Subject: new X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/commitdiff_plain/a0503b76c805d08e9556705c3e690818ecac3abc new --- diff --git a/Arduino/libraries/Arduino-crypto-master/Crypto.cpp b/Arduino/libraries/Arduino-crypto-master/Crypto.cpp index d2d8adf..2999026 100644 --- a/Arduino/libraries/Arduino-crypto-master/Crypto.cpp +++ b/Arduino/libraries/Arduino-crypto-master/Crypto.cpp @@ -652,6 +652,46 @@ void AES::process(const uint8_t *in, uint8_t *out, int length) decryptCBC(in, out, length); } + +void AES::encryptCTR(const uint8_t *in, uint8_t *out, int length) +{ + int i; + uint32_t tin[4], tout[4], iv[4]; + + memcpy(iv, _iv, AES_IV_SIZE); + for (i = 0; i < 4; i++) + tout[i] = crypto_ntohl(iv[i]); + + for (length -= AES_BLOCKSIZE; length >= 0; length -= AES_BLOCKSIZE) + { + uint32_t msg_32[4]; + uint32_t out_32[4]; + memcpy(msg_32, in, AES_BLOCKSIZE); + in += AES_BLOCKSIZE; + + for (i = 0; i < 4; i++) + tin[i] = crypto_ntohl(tout[i]); + + AES::encrypt(tin); + + for (i = 0; i < 4; i++) + { + + out_32[i] = crypto_htonl(tin[i])^msg_32[i]; + } + // tout[0]= tout[0]+1; + + memcpy(out, out_32, AES_BLOCKSIZE); + out += AES_BLOCKSIZE; + } + + for (i = 0; i < 4; i++) + iv[i] = crypto_htonl(tout[i])+1; + memcpy(_iv, iv, AES_IV_SIZE); +} + + + void AES::encryptCBC(const uint8_t *in, uint8_t *out, int length) { int i; diff --git a/Arduino/libraries/Arduino-crypto-master/Crypto.h b/Arduino/libraries/Arduino-crypto-master/Crypto.h index 651d9f8..8959817 100644 --- a/Arduino/libraries/Arduino-crypto-master/Crypto.h +++ b/Arduino/libraries/Arduino-crypto-master/Crypto.h @@ -124,6 +124,7 @@ class AES * Note: the length must be a multiple of 16 bytes */ void process(const uint8_t *in, uint8_t *out, int length); + void encryptCTR(const uint8_t *in, uint8_t *out, int length); void encryptCBC(const uint8_t *in, uint8_t *out, int length); void decryptCBC(const uint8_t *in, uint8_t *out, int length); void convertKey();