9
9
10
10
#ifdef LTC_DER
11
11
12
- unsigned long der_object_identifier_bits (unsigned long x )
12
+ static LTC_INLINE unsigned long s_der_object_identifier_bits (unsigned long x )
13
13
{
14
14
#if defined(LTC_HAVE_CLZL_BUILTIN )
15
15
if (x == 0 )
@@ -26,14 +26,7 @@ unsigned long der_object_identifier_bits(unsigned long x)
26
26
#endif
27
27
}
28
28
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 )
37
30
{
38
31
unsigned long y , z , t , wordbuf ;
39
32
@@ -55,14 +48,17 @@ int der_length_object_identifier(const unsigned long *words, unsigned long nword
55
48
z = 0 ;
56
49
wordbuf = words [0 ] * 40 + words [1 ];
57
50
for (y = 1 ; y < nwords ; y ++ ) {
58
- t = der_object_identifier_bits (wordbuf );
51
+ t = s_der_object_identifier_bits (wordbuf );
59
52
z += t /7 + ((t %7 ) ? 1 : 0 ) + (wordbuf == 0 ? 1 : 0 );
60
53
if (y < nwords - 1 ) {
61
54
/* grab next word */
62
55
wordbuf = words [y + 1 ];
63
56
}
64
57
}
65
58
59
+ if (datalen ) {
60
+ * datalen = z ;
61
+ }
66
62
/* now depending on the length our length encoding changes */
67
63
if (z < 128 ) {
68
64
z += 2 ;
@@ -78,4 +74,16 @@ int der_length_object_identifier(const unsigned long *words, unsigned long nword
78
74
return CRYPT_OK ;
79
75
}
80
76
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
+
81
89
#endif
0 commit comments