Browse Source

der_writer: Use uint32_t instead of long.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18615)
Daniel Fiala 1 year ago
parent
commit
59196250cb

+ 6 - 6
crypto/der_writer.c

@@ -106,11 +106,11 @@ static int int_der_w_integer(WPACKET *pkt, int tag,
         && int_end_context(pkt, tag);
 }
 
-static int int_put_bytes_ulong(WPACKET *pkt, const void *v,
+static int int_put_bytes_uint32(WPACKET *pkt, const void *v,
                                unsigned int *top_byte)
 {
-    const unsigned long *value = v;
-    unsigned long tmp = *value;
+    const uint32_t *value = v;
+    uint32_t tmp = *value;
     size_t n = 0;
 
     while (tmp != 0) {
@@ -125,9 +125,9 @@ static int int_put_bytes_ulong(WPACKET *pkt, const void *v,
 }
 
 /* For integers, we only support unsigned values for now */
-int ossl_DER_w_ulong(WPACKET *pkt, int tag, unsigned long v)
+int ossl_DER_w_uint32(WPACKET *pkt, int tag, uint32_t v)
 {
-    return int_der_w_integer(pkt, tag, int_put_bytes_ulong, &v);
+    return int_der_w_integer(pkt, tag, int_put_bytes_uint32, &v);
 }
 
 static int int_put_bytes_bn(WPACKET *pkt, const void *v,
@@ -153,7 +153,7 @@ int ossl_DER_w_bn(WPACKET *pkt, int tag, const BIGNUM *v)
     if (v == NULL || BN_is_negative(v))
         return 0;
     if (BN_is_zero(v))
-        return ossl_DER_w_ulong(pkt, tag, 0);
+        return ossl_DER_w_uint32(pkt, tag, 0);
 
     return int_der_w_integer(pkt, tag, int_put_bytes_bn, v);
 }

+ 3 - 3
doc/internal/man3/ossl_DER_w_bn.pod

@@ -2,7 +2,7 @@
 
 =head1 NAME
 
-ossl_DER_w_boolean, ossl_DER_w_ulong, ossl_DER_w_bn, ossl_DER_w_null,
+ossl_DER_w_boolean, ossl_DER_w_uint32, ossl_DER_w_bn, ossl_DER_w_null,
 ossl_DER_w_octet_string, ossl_DER_w_octet_string_uint32
 - internal DER writers for DER primitives
 
@@ -11,7 +11,7 @@ ossl_DER_w_octet_string, ossl_DER_w_octet_string_uint32
  #include "internal/der.h"
 
  int ossl_DER_w_boolean(WPACKET *pkt, int tag, int b);
- int ossl_DER_w_ulong(WPACKET *pkt, int tag, unsigned long v);
+ int ossl_DER_w_uint32(WPACKET *pkt, int tag, uint32_t v);
  int ossl_DER_w_bn(WPACKET *pkt, int tag, const BIGNUM *v);
  int ossl_DER_w_null(WPACKET *pkt, int tag);
  int ossl_DER_w_octet_string(WPACKET *pkt, int tag,
@@ -29,7 +29,7 @@ ossl_DER_w_boolean() writes the primitive BOOLEAN using the value I<b>.
 Any value that evaluates as true will render a B<true> BOOLEAN,
 otherwise a B<false> BOOLEAN.
 
-ossl_DER_w_ulong() and ossl_DER_w_bn() both write the primitive INTEGER using
+ossl_DER_w_uint32() and ossl_DER_w_bn() both write the primitive INTEGER using
 the value I<v>.
 
 =for comment Other similar functions for diverse C integers should be

+ 1 - 1
doc/internal/man7/DERlib.pod

@@ -118,7 +118,7 @@ value:
     {
         return ossl_DER_w_begin_sequence(pkt, tag)
             && (ossl_DER_w_begin_sequence(pkt, DER_NO_CONTEXT)
-                && ossl_DER_w_ulong(pkt, 2, 20)
+                && ossl_DER_w_uint32(pkt, 2, 20)
                 && ossl_DER_w_precompiled(pkt, 1,
                                           der_mgf1SHA256Identifier,
                                           sizeof(der_mgf1SHA256Identifier))

+ 1 - 1
include/internal/der.h

@@ -78,7 +78,7 @@ int ossl_DER_w_precompiled(WPACKET *pkt, int tag,
                            size_t precompiled_n);
 
 int ossl_DER_w_boolean(WPACKET *pkt, int tag, int b);
-int ossl_DER_w_ulong(WPACKET *pkt, int tag, unsigned long v);
+int ossl_DER_w_uint32(WPACKET *pkt, int tag, uint32_t v);
 int ossl_DER_w_bn(WPACKET *pkt, int tag, const BIGNUM *v);
 int ossl_DER_w_null(WPACKET *pkt, int tag);
 int ossl_DER_w_octet_string(WPACKET *pkt, int tag,

+ 2 - 2
providers/common/der/der_rsa_key.c

@@ -347,8 +347,8 @@ int ossl_DER_w_RSASSA_PSS_params(WPACKET *pkt, int tag,
 
     return ossl_DER_w_begin_sequence(pkt, tag)
         && (trailerfield == default_trailerfield
-            || ossl_DER_w_ulong(pkt, 3, trailerfield))
-        && (saltlen == default_saltlen || ossl_DER_w_ulong(pkt, 2, saltlen))
+            || ossl_DER_w_uint32(pkt, 3, trailerfield))
+        && (saltlen == default_saltlen || ossl_DER_w_uint32(pkt, 2, saltlen))
         && DER_w_MaskGenAlgorithm(pkt, 1, pss)
         && (hashalg_nid == default_hashalg_nid
             || ossl_DER_w_precompiled(pkt, 0, hashalg, hashalg_sz))