Mercurial > dropbear
comparison libtomcrypt/src/pk/asn1/der/object_identifier/der_length_object_identifier.c @ 415:8b9aba1d5fa4 channel-fix
merge of '73fe066c5d9e2395354ba74756124d45c978a04d'
and 'f5014cc84558f1e8eba42dbecf9f72f94bfe6134'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 06 Feb 2007 16:00:18 +0000 |
parents | 0cbe8f6dbf9e |
children | f849a5ca2efc |
comparison
equal
deleted
inserted
replaced
414:c53a26c430e5 | 415:8b9aba1d5fa4 |
---|---|
4 * algorithms in a highly modular and flexible manner. | 4 * algorithms in a highly modular and flexible manner. |
5 * | 5 * |
6 * The library is free for all purposes without any express | 6 * The library is free for all purposes without any express |
7 * guarantee it works. | 7 * guarantee it works. |
8 * | 8 * |
9 * Tom St Denis, [email protected], http://libtomcrypt.org | 9 * Tom St Denis, [email protected], http://libtomcrypt.com |
10 */ | 10 */ |
11 #include "tomcrypt.h" | 11 #include "tomcrypt.h" |
12 | 12 |
13 /** | 13 /** |
14 @file der_length_object_identifier.c | 14 @file der_length_object_identifier.c |
37 @param outlen [out] The length of the DER encoding for the given string | 37 @param outlen [out] The length of the DER encoding for the given string |
38 @return CRYPT_OK if successful | 38 @return CRYPT_OK if successful |
39 */ | 39 */ |
40 int der_length_object_identifier(unsigned long *words, unsigned long nwords, unsigned long *outlen) | 40 int der_length_object_identifier(unsigned long *words, unsigned long nwords, unsigned long *outlen) |
41 { | 41 { |
42 unsigned long y, z, t; | 42 unsigned long y, z, t, wordbuf; |
43 | 43 |
44 LTC_ARGCHK(words != NULL); | 44 LTC_ARGCHK(words != NULL); |
45 LTC_ARGCHK(outlen != NULL); | 45 LTC_ARGCHK(outlen != NULL); |
46 | 46 |
47 | 47 |
48 /* must be >= 2 words */ | 48 /* must be >= 2 words */ |
49 if (nwords < 2) { | 49 if (nwords < 2) { |
50 return CRYPT_INVALID_ARG; | 50 return CRYPT_INVALID_ARG; |
51 } | 51 } |
52 | 52 |
53 /* word1 = 0,1,2 and word2 0..39 */ | 53 /* word1 = 0,1,2,3 and word2 0..39 */ |
54 if (words[0] > 2 || words[1] > 39) { | 54 if (words[0] > 3 || (words[0] < 2 && words[1] > 39)) { |
55 return CRYPT_INVALID_ARG; | 55 return CRYPT_INVALID_ARG; |
56 } | 56 } |
57 | 57 |
58 /* leading byte of first two words */ | 58 /* leading word is the first two */ |
59 z = 1; | 59 z = 0; |
60 for (y = 2; y < nwords; y++) { | 60 wordbuf = words[0] * 40 + words[1]; |
61 t = der_object_identifier_bits(words[y]); | 61 for (y = 1; y < nwords; y++) { |
62 z += t/7 + ((t%7) ? 1 : 0); | 62 t = der_object_identifier_bits(wordbuf); |
63 z += t/7 + ((t%7) ? 1 : 0) + (wordbuf == 0 ? 1 : 0); | |
64 if (y < nwords - 1) { | |
65 /* grab next word */ | |
66 wordbuf = words[y+1]; | |
67 } | |
63 } | 68 } |
64 | 69 |
65 /* now depending on the length our length encoding changes */ | 70 /* now depending on the length our length encoding changes */ |
66 if (z < 128) { | 71 if (z < 128) { |
67 z += 2; | 72 z += 2; |
78 } | 83 } |
79 | 84 |
80 #endif | 85 #endif |
81 | 86 |
82 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/object_identifier/der_length_object_identifier.c,v $ */ | 87 /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/object_identifier/der_length_object_identifier.c,v $ */ |
83 /* $Revision: 1.1 $ */ | 88 /* $Revision: 1.4 $ */ |
84 /* $Date: 2005/05/16 15:08:11 $ */ | 89 /* $Date: 2006/04/16 20:17:42 $ */ |