99
1010#ifdef LTC_DER
1111
12- unsigned long der_object_identifier_bits (unsigned long x )
12+ static LTC_INLINE unsigned long s_der_object_identifier_bits (unsigned long x )
1313{
1414#if defined(LTC_HAVE_CLZL_BUILTIN )
1515 if (x == 0 )
@@ -26,14 +26,7 @@ unsigned long der_object_identifier_bits(unsigned long x)
2626#endif
2727}
2828
29- /**
30- Gets length of DER encoding of Object Identifier
31- @param nwords The number of OID words
32- @param words The actual OID words to get the size of
33- @param outlen [out] The length of the DER encoding for the given string
34- @return CRYPT_OK if successful
35- */
36- int der_length_object_identifier (const unsigned long * words , unsigned long nwords , unsigned long * outlen )
29+ int der_length_object_identifier_full (const unsigned long * words , unsigned long nwords , unsigned long * outlen , unsigned long * datalen )
3730{
3831 unsigned long y , z , t , wordbuf ;
3932
@@ -55,14 +48,17 @@ int der_length_object_identifier(const unsigned long *words, unsigned long nword
5548 z = 0 ;
5649 wordbuf = words [0 ] * 40 + words [1 ];
5750 for (y = 1 ; y < nwords ; y ++ ) {
58- t = der_object_identifier_bits (wordbuf );
51+ t = s_der_object_identifier_bits (wordbuf );
5952 z += t /7 + ((t %7 ) ? 1 : 0 ) + (wordbuf == 0 ? 1 : 0 );
6053 if (y < nwords - 1 ) {
6154 /* grab next word */
6255 wordbuf = words [y + 1 ];
6356 }
6457 }
6558
59+ if (datalen ) {
60+ * datalen = z ;
61+ }
6662 /* now depending on the length our length encoding changes */
6763 if (z < 128 ) {
6864 z += 2 ;
@@ -78,4 +74,16 @@ int der_length_object_identifier(const unsigned long *words, unsigned long nword
7874 return CRYPT_OK ;
7975}
8076
77+ /**
78+ Gets length of DER encoding of Object Identifier
79+ @param nwords The number of OID words
80+ @param words The actual OID words to get the size of
81+ @param outlen [out] The length of the DER encoding for the given string
82+ @return CRYPT_OK if successful
83+ */
84+ int der_length_object_identifier (const unsigned long * words , unsigned long nwords , unsigned long * outlen )
85+ {
86+ return der_length_object_identifier_full (words , nwords , outlen , NULL );
87+ }
88+
8189#endif
0 commit comments