svn rev #21618: branches/aes-ccm/src/lib/crypto/enc_provider/
lhoward@MIT.EDU
lhoward at MIT.EDU
Sun Dec 28 08:04:15 EST 2008
http://src.mit.edu/fisheye/changelog/krb5/?cs=21618
Commit By: lhoward
Log Message:
cleanup
Changed Files:
U branches/aes-ccm/src/lib/crypto/enc_provider/aes_ctr.c
Modified: branches/aes-ccm/src/lib/crypto/enc_provider/aes_ctr.c
===================================================================
--- branches/aes-ccm/src/lib/crypto/enc_provider/aes_ctr.c 2008-12-28 12:52:19 UTC (rev 21617)
+++ branches/aes-ccm/src/lib/crypto/enc_provider/aes_ctr.c 2008-12-28 13:04:14 UTC (rev 21618)
@@ -33,13 +33,48 @@
#define CCM_COUNTER_LENGTH 3
-static void xorblock(unsigned char *out, const unsigned char *in)
+static inline void xorblock(unsigned char *out, const unsigned char *in)
{
int z;
for (z = 0; z < BLOCK_SIZE; z++)
out[z] ^= in[z];
}
+/* Get the current counter block number from the IV */
+static inline void getctrblockno(krb5_ui_8 *pblockno,
+ const unsigned char ctr[BLOCK_SIZE])
+{
+ register krb5_octet q, i;
+ krb5_ui_8 blockno;
+
+ q = ctr[0] + 1;
+
+ assert(q >= 2 && q <= 8);
+
+ for (i = 0, blockno = 0; i < q; i++) {
+ register int s = (q - i - 1) * 8;
+
+ blockno |= ctr[16 - q + i] << s;
+ }
+
+ *pblockno = blockno;
+}
+
+/* Store the current counter block number in the IV */
+static inline void putctrblockno(krb5_ui_8 blockno,
+ unsigned char ctr[BLOCK_SIZE])
+{
+ register krb5_octet q, i;
+
+ q = ctr[0] + 1;
+
+ for (i = 0; i < q; i++) {
+ register int s = (q - i - 1) * 8;
+
+ ctr[16 - q + i] = (blockno >> s) & 0xFF;
+ }
+}
+
/*
* ivec must be a correctly formatted counter block per SP800-38C A.3
*/
@@ -51,7 +86,6 @@
{
aes_ctx ctx;
unsigned char ctr[BLOCK_SIZE];
- register krb5_octet q, i;
krb5_ui_8 blockno;
struct iov_block_state input_pos, output_pos;
@@ -74,16 +108,9 @@
memset(ctr, 0, BLOCK_SIZE);
ctr[0] = CCM_COUNTER_LENGTH - 1; /* default q=3 from RFC 5116 5.3 */
}
- q = ctr[0] + 1;
- assert(q >= 2 && q <= 8);
+ getctrblockno(&blockno, ctr);
- for (i = 0, blockno = 0; i < q; i++) {
- register int s = (q - i - 1) * 8;
-
- blockno |= ctr[16 - q + i] << s;
- }
-
for (;;) {
unsigned char plain[BLOCK_SIZE];
unsigned char ectr[BLOCK_SIZE];
@@ -97,13 +124,7 @@
xorblock(plain, ectr);
krb5int_c_iov_put_block(data, num_data, (unsigned char *)plain, BLOCK_SIZE, &output_pos);
- blockno++;
-
- for (i = 0; i < q; i++) {
- register int s = (q - i - 1) * 8;
-
- ctr[16 - q + i] = (blockno >> s) & 0xFF;
- }
+ putctrblockno(++blockno, ctr);
}
if (ivec != NULL)
@@ -120,7 +141,6 @@
{
aes_ctx ctx;
unsigned char ctr[BLOCK_SIZE];
- register krb5_octet q, i;
krb5_ui_8 blockno;
struct iov_block_state input_pos, output_pos;
@@ -143,16 +163,9 @@
memset(ctr, 0, BLOCK_SIZE);
ctr[0] = CCM_COUNTER_LENGTH - 1; /* default q=3 from RFC 5116 5.3 */
}
- q = ctr[0] + 1;
- assert(q >= 2 && q <= 8);
+ getctrblockno(&blockno, ctr);
- for (i = 0, blockno = 0; i < q; i++) {
- register krb5_octet s = (q - i - 1) * 8;
-
- blockno |= ctr[16 - q + i] << s;
- }
-
for (;;) {
unsigned char ectr[BLOCK_SIZE];
unsigned char cipher[BLOCK_SIZE];
@@ -166,13 +179,7 @@
xorblock(cipher, ectr);
krb5int_c_iov_put_block(data, num_data, (unsigned char *)cipher, BLOCK_SIZE, &output_pos);
- blockno++;
-
- for (i = 0; i < q; i++) {
- register krb5_octet s = (q - i - 1) * 8;
-
- ctr[16 - q + i] = (blockno >> s) & 0xFF;
- }
+ putctrblockno(++blockno, ctr);
}
if (ivec != NULL)
More information about the cvs-krb5
mailing list