summaryrefslogtreecommitdiff
path: root/libtomcrypt/src/misc
diff options
context:
space:
mode:
Diffstat (limited to 'libtomcrypt/src/misc')
-rw-r--r--libtomcrypt/src/misc/base64/base64_decode.c12
-rw-r--r--libtomcrypt/src/misc/crypt/crypt.c1
-rw-r--r--libtomcrypt/src/misc/crypt/crypt_constants.c29
-rw-r--r--libtomcrypt/src/misc/crypt/crypt_sizes.c24
4 files changed, 30 insertions, 36 deletions
diff --git a/libtomcrypt/src/misc/base64/base64_decode.c b/libtomcrypt/src/misc/base64/base64_decode.c
index 4c58c68..c1d3c80 100644
--- a/libtomcrypt/src/misc/base64/base64_decode.c
+++ b/libtomcrypt/src/misc/base64/base64_decode.c
@@ -43,8 +43,8 @@ static const unsigned char map_base64[256] = {
255, 255, 255, 255 };
#endif /* LTC_BASE64 */
-static const unsigned char map_base64url[] = {
#if defined(LTC_BASE64_URL)
+static const unsigned char map_base64url[] = {
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
@@ -67,8 +67,8 @@ static const unsigned char map_base64url[] = {
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255
-#endif /* LTC_BASE64_URL */
};
+#endif /* LTC_BASE64_URL */
enum {
relaxed = 0,
@@ -117,8 +117,14 @@ static int _base64_decode_internal(const unsigned char *in, unsigned long inlen
}
if (y != 0) {
+ int allow_b64url = 0;
+#ifdef LTC_BASE64_URL
+ if (map == map_base64url) {
+ allow_b64url = 1;
+ }
+#endif
if (y == 1) return CRYPT_INVALID_PACKET;
- if ((y + g) != 4 && is_strict && map != map_base64url) return CRYPT_INVALID_PACKET;
+ if ((y + g) != 4 && is_strict && !allow_b64url) return CRYPT_INVALID_PACKET;
t = t << (6 * (4 - y));
if (z + y - 1 > *outlen) return CRYPT_BUFFER_OVERFLOW;
if (y >= 2) out[z++] = (unsigned char) ((t >> 16) & 255);
diff --git a/libtomcrypt/src/misc/crypt/crypt.c b/libtomcrypt/src/misc/crypt/crypt.c
index 83b6c21..9b9c867 100644
--- a/libtomcrypt/src/misc/crypt/crypt.c
+++ b/libtomcrypt/src/misc/crypt/crypt.c
@@ -399,6 +399,7 @@ const char *crypt_build_settings =
#endif
#if defined(LTC_DER)
" DER "
+ " " NAME_VALUE(LTC_DER_MAX_RECURSION) " "
#endif
#if defined(LTC_PKCS_1)
" PKCS#1 "
diff --git a/libtomcrypt/src/misc/crypt/crypt_constants.c b/libtomcrypt/src/misc/crypt/crypt_constants.c
index a7418d5..9b3c938 100644
--- a/libtomcrypt/src/misc/crypt/crypt_constants.c
+++ b/libtomcrypt/src/misc/crypt/crypt_constants.c
@@ -111,6 +111,7 @@ static const crypt_constant _crypt_constants[] = {
#ifdef LTC_DER
/* DER handling */
+ {"LTC_DER", 1},
_C_STRINGIFY(LTC_ASN1_EOL),
_C_STRINGIFY(LTC_ASN1_BOOLEAN),
_C_STRINGIFY(LTC_ASN1_INTEGER),
@@ -132,6 +133,9 @@ static const crypt_constant _crypt_constants[] = {
_C_STRINGIFY(LTC_ASN1_CONSTRUCTED),
_C_STRINGIFY(LTC_ASN1_CONTEXT_SPECIFIC),
_C_STRINGIFY(LTC_ASN1_GENERALIZEDTIME),
+ _C_STRINGIFY(LTC_DER_MAX_RECURSION),
+#else
+ {"LTC_DER", 0},
#endif
#ifdef LTC_CTR_MODE
@@ -248,20 +252,16 @@ int crypt_get_constant(const char* namein, int *valueout) {
int crypt_list_all_constants(char *names_list, unsigned int *names_list_size) {
int i;
unsigned int total_len = 0;
- char number[32], *ptr;
+ char *ptr;
int number_len;
int count = sizeof(_crypt_constants) / sizeof(_crypt_constants[0]);
/* calculate amount of memory required for the list */
for (i=0; i<count; i++) {
- total_len += (unsigned int)strlen(_crypt_constants[i].name) + 1;
- /* the above +1 is for the commas */
- number_len = snprintf(number, sizeof(number), "%d", _crypt_constants[i].value);
- if ((number_len < 0) ||
- ((unsigned int)number_len >= sizeof(number)))
+ number_len = snprintf(NULL, 0, "%s,%d\n", _crypt_constants[i].name, _crypt_constants[i].value);
+ if (number_len < 0)
return -1;
- total_len += number_len + 1;
- /* this last +1 is for newlines (and ending NULL) */
+ total_len += number_len;
}
if (names_list == NULL) {
@@ -273,16 +273,11 @@ int crypt_list_all_constants(char *names_list, unsigned int *names_list_size) {
/* build the names list */
ptr = names_list;
for (i=0; i<count; i++) {
- strcpy(ptr, _crypt_constants[i].name);
- ptr += strlen(_crypt_constants[i].name);
- strcpy(ptr, ",");
- ptr += 1;
-
- number_len = snprintf(number, sizeof(number), "%d", _crypt_constants[i].value);
- strcpy(ptr, number);
+ number_len = snprintf(ptr, total_len, "%s,%d\n", _crypt_constants[i].name, _crypt_constants[i].value);
+ if (number_len < 0) return -1;
+ if ((unsigned int)number_len > total_len) return -1;
+ total_len -= number_len;
ptr += number_len;
- strcpy(ptr, "\n");
- ptr += 1;
}
/* to remove the trailing new-line */
ptr -= 1;
diff --git a/libtomcrypt/src/misc/crypt/crypt_sizes.c b/libtomcrypt/src/misc/crypt/crypt_sizes.c
index 79b3bd4..dd857ea 100644
--- a/libtomcrypt/src/misc/crypt/crypt_sizes.c
+++ b/libtomcrypt/src/misc/crypt/crypt_sizes.c
@@ -307,19 +307,16 @@ int crypt_get_size(const char* namein, unsigned int *sizeout) {
int crypt_list_all_sizes(char *names_list, unsigned int *names_list_size) {
int i;
unsigned int total_len = 0;
- char number[32], *ptr;
+ char *ptr;
int number_len;
int count = sizeof(_crypt_sizes) / sizeof(_crypt_sizes[0]);
/* calculate amount of memory required for the list */
for (i=0; i<count; i++) {
- total_len += (unsigned int)strlen(_crypt_sizes[i].name) + 1;
- /* the above +1 is for the commas */
- number_len = snprintf(number, sizeof(number), "%u", _crypt_sizes[i].size);
- if ((number_len < 0) ||
- ((unsigned int)number_len >= sizeof(number)))
+ number_len = snprintf(NULL, 0, "%s,%u\n", _crypt_sizes[i].name, _crypt_sizes[i].size);
+ if (number_len < 0)
return -1;
- total_len += (unsigned int)strlen(number) + 1;
+ total_len += number_len;
/* this last +1 is for newlines (and ending NULL) */
}
@@ -332,16 +329,11 @@ int crypt_list_all_sizes(char *names_list, unsigned int *names_list_size) {
/* build the names list */
ptr = names_list;
for (i=0; i<count; i++) {
- strcpy(ptr, _crypt_sizes[i].name);
- ptr += strlen(_crypt_sizes[i].name);
- strcpy(ptr, ",");
- ptr += 1;
-
- number_len = snprintf(number, sizeof(number), "%u", _crypt_sizes[i].size);
- strcpy(ptr, number);
+ number_len = snprintf(ptr, total_len, "%s,%u\n", _crypt_sizes[i].name, _crypt_sizes[i].size);
+ if (number_len < 0) return -1;
+ if ((unsigned int)number_len > total_len) return -1;
+ total_len -= number_len;
ptr += number_len;
- strcpy(ptr, "\n");
- ptr += 1;
}
/* to remove the trailing new-line */
ptr -= 1;