GitHub PullRequestReviewCommentEvent at 2014-03-30 13:11:58
Repository: mooltipass
Actor: jim17
Payload: {"comment":{"url":"https://api.github.com/repos/limpkin/mooltipass/pulls/comments/11097952","id":11097952,"diff_hunk":"@@ -161,23 +123,49 @@ void incrementCtr(uint8_t *ctr)\n *\t\\brief\tEncrypt data and save it in data.\n * \n *   \\param  data - pointer to data, this is also the location to store encrypted data\n-*   \\param  dataLen - size of data, must be multiple of 16.\n+*   \\param  dataLen - size of data\n */\n void aes256CtrEncrypt(aes256CtrCtx_t *ctx, uint8_t *data, uint16_t dataLen)\n {\n     uint16_t i;\n \n-    // dataLen must be multiple of 16 !\n-    if(dataLen%16 != 0)\n+    // Loop will advance by a variable amount: ctx->cipherstreamAvailable in the\n+    // first round, 16 then, dataLen - i in the last round.\n+    for (i=0; i<dataLen; )\n     {\n-        return;\n-    }\n+        // if we need new cipherstream, calculate it\n+        if(ctx->cipherstreamAvailable == 0)\n+        {\n+            int j;\n+            for(j = 0; j < 16; j++)\n+            {\n+                ctx->cipherstream[j] = ctx->ctr[j];\n+            }\n \n-    // start encryption/decryption\n-    for (i=0; i<dataLen; i+=16)\n-    {\n-        aes256CtrEncBlock(ctx->ctr, ctx->key, &data[i]);\n-        incrementCtr(ctx->ctr);\n+            // encrypt ctr with key, then store the result in cipherstream\n+            aes256_enc(ctx->cipherstream, &(ctx->aesCtx));\n+\n+            ctx->cipherstreamAvailable = 16;\n+        }\n+\n+        uint8_t thisLoop = dataLen - i;","path":"source_code/src/AES/aes256_ctr.c","position":147,"original_position":147,"commit_id":"5ccac286bfaede17da714b09996df2aab8278973","original_commit_id":"5ccac286bfaede17da714b09996df2aab8278973","user":{"login":"jim17","id":3835572,"avatar_url":"https://avatars.githubusercontent.com/u/3835572?","gravatar_id":"786b24e2b074369be98cf15f6db91a57","url":"https://api.github.com/users/jim17","html_url":"https://github.com/jim17","followers_url":"https://api.github.com/users/jim17/followers","following_url":"https://api.github.com/users/jim17/following{/other_user}","gists_url":"https://api.github.com/users/jim17/gists{/gist_id}","starred_url":"https://api.github.com/users/jim17/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jim17/subscriptions","organizations_url":"https://api.github.com/users/jim17/orgs","repos_url":"https://api.github.com/users/jim17/repos","events_url":"https://api.github.com/users/jim17/events{/privacy}","received_events_url":"https://api.github.com/users/jim17/received_events","type":"User","site_admin":false},"body":"Due to 'dataLen' and 'i' are  uint16_t maybe thisLoop should be uint16_t type too.","created_at":"2014-03-30T13:11:58Z","updated_at":"2014-03-30T13:11:58Z","html_url":"https://github.com/limpkin/mooltipass/pull/26#discussion_r11097952","pull_request_url":"https://api.github.com/repos/limpkin/mooltipass/pulls/26","_links":{"self":{"href":"https://api.github.com/repos/limpkin/mooltipass/pulls/comments/11097952"},"html":{"href":"https://github.com/limpkin/mooltipass/pull/26#discussion_r11097952"},"pull_request":{"href":"https://api.github.com/repos/limpkin/mooltipass/pulls/26"}}}}