Upgrade libtomcrypt
This commit is contained in:
@@ -27,7 +27,7 @@ int der_encode_object_identifier(const unsigned long *words, unsigned long nwor
|
||||
LTC_ARGCHK(outlen != NULL);
|
||||
|
||||
/* check length */
|
||||
if ((err = der_length_object_identifier(words, nwords, &x)) != CRYPT_OK) {
|
||||
if ((err = der_length_object_identifier_full(words, nwords, &x, &z)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
if (x > *outlen) {
|
||||
@@ -35,17 +35,6 @@ int der_encode_object_identifier(const unsigned long *words, unsigned long nwor
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
/* compute length to store OID data */
|
||||
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) {
|
||||
wordbuf = words[y + 1];
|
||||
}
|
||||
}
|
||||
|
||||
/* store header + length */
|
||||
x = 0;
|
||||
out[x++] = 0x06;
|
||||
@@ -59,7 +48,7 @@ int der_encode_object_identifier(const unsigned long *words, unsigned long nwor
|
||||
wordbuf = words[0] * 40 + words[1];
|
||||
for (i = 1; i < nwords; i++) {
|
||||
/* store 7 bit words in little endian */
|
||||
t = wordbuf & 0xFFFFFFFF;
|
||||
t = wordbuf;
|
||||
if (t) {
|
||||
y = x;
|
||||
mask = 0;
|
||||
|
||||
@@ -9,27 +9,24 @@
|
||||
|
||||
#ifdef LTC_DER
|
||||
|
||||
unsigned long der_object_identifier_bits(unsigned long x)
|
||||
static LTC_INLINE unsigned long s_der_object_identifier_bits(unsigned long x)
|
||||
{
|
||||
#if defined(LTC_HAVE_CLZL_BUILTIN)
|
||||
if (x == 0)
|
||||
return 0;
|
||||
return sizeof(unsigned long) * CHAR_BIT - __builtin_clzl(x);
|
||||
#else
|
||||
unsigned long c;
|
||||
x &= 0xFFFFFFFF;
|
||||
c = 0;
|
||||
while (x) {
|
||||
++c;
|
||||
x >>= 1;
|
||||
}
|
||||
return c;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Gets length of DER encoding of Object Identifier
|
||||
@param nwords The number of OID words
|
||||
@param words The actual OID words to get the size of
|
||||
@param outlen [out] The length of the DER encoding for the given string
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int der_length_object_identifier(const unsigned long *words, unsigned long nwords, unsigned long *outlen)
|
||||
int der_length_object_identifier_full(const unsigned long *words, unsigned long nwords, unsigned long *outlen, unsigned long *datalen)
|
||||
{
|
||||
unsigned long y, z, t, wordbuf;
|
||||
|
||||
@@ -51,7 +48,7 @@ int der_length_object_identifier(const unsigned long *words, unsigned long nword
|
||||
z = 0;
|
||||
wordbuf = words[0] * 40 + words[1];
|
||||
for (y = 1; y < nwords; y++) {
|
||||
t = der_object_identifier_bits(wordbuf);
|
||||
t = s_der_object_identifier_bits(wordbuf);
|
||||
z += t/7 + ((t%7) ? 1 : 0) + (wordbuf == 0 ? 1 : 0);
|
||||
if (y < nwords - 1) {
|
||||
/* grab next word */
|
||||
@@ -59,6 +56,9 @@ int der_length_object_identifier(const unsigned long *words, unsigned long nword
|
||||
}
|
||||
}
|
||||
|
||||
if (datalen) {
|
||||
*datalen = z;
|
||||
}
|
||||
/* now depending on the length our length encoding changes */
|
||||
if (z < 128) {
|
||||
z += 2;
|
||||
@@ -74,4 +74,16 @@ int der_length_object_identifier(const unsigned long *words, unsigned long nword
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
Gets length of DER encoding of Object Identifier
|
||||
@param nwords The number of OID words
|
||||
@param words The actual OID words to get the size of
|
||||
@param outlen [out] The length of the DER encoding for the given string
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int der_length_object_identifier(const unsigned long *words, unsigned long nwords, unsigned long *outlen)
|
||||
{
|
||||
return der_length_object_identifier_full(words, nwords, outlen, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user