X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/blobdiff_plain/3935cf9ac06b7bc328ee3d942edb5f60130d5b74..7bf76349716cc9e4932459def1bb794a4eb90cae:/Arduino/libraries/Arduino-crypto-master/Crypto.cpp?ds=sidebyside

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;