Created
March 30, 2015 04:05
-
-
Save archshift/170d2605dce07720ed99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 33ac99c83160760eb42bc3481d0f47ef3f2adcc8 Mon Sep 17 00:00:00 2001 | |
From: archshift <gh@archshift.com> | |
Date: Tue, 24 Mar 2015 19:01:48 -0700 | |
Subject: [PATCH] Small optimization in add_ctr | |
--- | |
source/decryptor/crypto.c | 19 ++++--------------- | |
1 file changed, 4 insertions(+), 15 deletions(-) | |
diff --git a/source/decryptor/crypto.c b/source/decryptor/crypto.c | |
index 60accc4..acddd02 100644 | |
--- a/source/decryptor/crypto.c | |
+++ b/source/decryptor/crypto.c | |
@@ -92,26 +92,15 @@ void add_ctr(void* ctr, u32 carry) | |
u32 counter[4]; | |
u8 *outctr = (u8 *) ctr; | |
u32 sum; | |
- int32_t i; | |
+ u32 i; | |
for(i=0; i<4; i++) { | |
counter[i] = (outctr[i*4+0]<<24) | (outctr[i*4+1]<<16) | (outctr[i*4+2]<<8) | (outctr[i*4+3]<<0); | |
- } | |
- for(i=3; i>=0; i--) | |
- { | |
- sum = counter[i] + carry; | |
- if (sum < counter[i]) { | |
- carry = 1; | |
- } | |
- else { | |
- carry = 0; | |
- } | |
- counter[i] = sum; | |
- } | |
+ sum = counter[3-i] + carry; | |
+ carry = (u32)(sum < counter[3-i]); | |
+ counter[3-i] = sum; | |
- for(i=0; i<4; i++) | |
- { | |
outctr[i*4+0] = counter[i]>>24; | |
outctr[i*4+1] = counter[i]>>16; | |
outctr[i*4+2] = counter[i]>>8; | |
-- | |
2.2.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment