|
@@ -44,9 +44,9 @@ static int qsort_helper(const void *a, const void *b)
|
|
|
{
|
|
|
ltc_asn1_list *A = (ltc_asn1_list *)a, *B = (ltc_asn1_list *)b;
|
|
|
int r;
|
|
|
-
|
|
|
+
|
|
|
r = ltc_to_asn1(A->type) - ltc_to_asn1(B->type);
|
|
|
-
|
|
|
+
|
|
|
/* for QSORT the order is UNDEFINED if they are "equal" which means it is NOT DETERMINISTIC. So we force it to be :-) */
|
|
|
if (r == 0) {
|
|
|
/* their order in the original list now determines the position */
|
|
@@ -54,13 +54,13 @@ static int qsort_helper(const void *a, const void *b)
|
|
|
} else {
|
|
|
return r;
|
|
|
}
|
|
|
-}
|
|
|
+}
|
|
|
|
|
|
/*
|
|
|
Encode a SET type
|
|
|
@param list The list of items to encode
|
|
|
@param inlen The number of items in the list
|
|
|
- @param out [out] The destination
|
|
|
+ @param out [out] The destination
|
|
|
@param outlen [in/out] The size of the output
|
|
|
@return CRYPT_OK on success
|
|
|
*/
|
|
@@ -70,30 +70,30 @@ int der_encode_set(ltc_asn1_list *list, unsigned long inlen,
|
|
|
ltc_asn1_list *copy;
|
|
|
unsigned long x;
|
|
|
int err;
|
|
|
-
|
|
|
+
|
|
|
/* make copy of list */
|
|
|
copy = XCALLOC(inlen, sizeof(*copy));
|
|
|
if (copy == NULL) {
|
|
|
return CRYPT_MEM;
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
/* fill in used member with index so we can fully sort it */
|
|
|
for (x = 0; x < inlen; x++) {
|
|
|
copy[x] = list[x];
|
|
|
copy[x].used = x;
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
/* sort it by the "type" field */
|
|
|
- XQSORT(copy, inlen, sizeof(*copy), &qsort_helper);
|
|
|
-
|
|
|
+ XQSORT(copy, inlen, sizeof(*copy), &qsort_helper);
|
|
|
+
|
|
|
/* call der_encode_sequence_ex() */
|
|
|
- err = der_encode_sequence_ex(copy, inlen, out, outlen, LTC_ASN1_SET);
|
|
|
-
|
|
|
+ err = der_encode_sequence_ex(copy, inlen, out, outlen, LTC_ASN1_SET);
|
|
|
+
|
|
|
/* free list */
|
|
|
XFREE(copy);
|
|
|
-
|
|
|
+
|
|
|
return err;
|
|
|
-}
|
|
|
+}
|
|
|
|
|
|
|
|
|
#endif
|