diff src/pk/asn1/der/object_identifier/der_length_object_identifier.c @ 380:d5faf4814ddb libtomcrypt-orig libtomcrypt-1.16

Update to LibTomCrypt 1.16
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 02:22:00 +0000
parents 59400faa4b44
children
line wrap: on
line diff
--- a/src/pk/asn1/der/object_identifier/der_length_object_identifier.c	Wed Mar 08 12:58:00 2006 +0000
+++ b/src/pk/asn1/der/object_identifier/der_length_object_identifier.c	Thu Jan 11 02:22:00 2007 +0000
@@ -6,7 +6,7 @@
  * The library is free for all purposes without any express
  * guarantee it works.
  *
- * Tom St Denis, [email protected], http://libtomcrypt.org
+ * Tom St Denis, [email protected], http://libtomcrypt.com
  */
 #include "tomcrypt.h"
 
@@ -39,7 +39,7 @@
 */
 int der_length_object_identifier(unsigned long *words, unsigned long nwords, unsigned long *outlen)
 {
-   unsigned long y, z, t;   
+   unsigned long y, z, t, wordbuf;   
 
    LTC_ARGCHK(words  != NULL);
    LTC_ARGCHK(outlen != NULL);
@@ -50,16 +50,21 @@
       return CRYPT_INVALID_ARG;
    }
 
-   /* word1 = 0,1,2 and word2 0..39 */
-   if (words[0] > 2 || words[1] > 39) {
+   /* word1 = 0,1,2,3 and word2 0..39 */
+   if (words[0] > 3 || (words[0] < 2 && words[1] > 39)) {
       return CRYPT_INVALID_ARG;
    }
 
-   /* leading byte of first two words */
-   z = 1;
-   for (y = 2; y < nwords; y++) {
-       t = der_object_identifier_bits(words[y]);
-       z += t/7 + ((t%7) ? 1 : 0);
+   /* leading word is the first two */
+   z = 0;
+   wordbuf = words[0] * 40 + words[1];
+   for (y = 1; y < nwords; y++) {
+       t = der_object_identifier_bits(wordbuf);
+       z += t/7 + ((t%7) ? 1 : 0) + (wordbuf == 0 ? 1 : 0);
+       if (y < nwords - 1) {
+          /* grab next word */
+          wordbuf = words[y+1];
+       }
    }
 
    /* now depending on the length our length encoding changes */
@@ -80,5 +85,5 @@
 #endif
 
 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/object_identifier/der_length_object_identifier.c,v $ */
-/* $Revision: 1.1 $ */
-/* $Date: 2005/05/16 15:08:11 $ */
+/* $Revision: 1.4 $ */
+/* $Date: 2006/04/16 20:17:42 $ */