Upgrade libtomcrypt

This commit is contained in:
2025-10-24 19:33:21 +03:00
parent d770dd8df3
commit acc69bb8ad
157 changed files with 922 additions and 761 deletions

View File

@@ -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;

View File

@@ -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