Ensure we use a non-zero time for tickets in early data
[openssl.git] / crypto / asn1_dsa.c
index 8423ff883f4cb1f9aeb302823720e0899d0f65be..0782fe7c2a54e7e23fcc73c776837414591c30f8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -23,7 +23,7 @@
 
 #include <openssl/crypto.h>
 #include <openssl/bn.h>
-#include "internal/asn1_dsa.h"
+#include "crypto/asn1_dsa.h"
 #include "internal/packet.h"
 
 #define ID_SEQUENCE 0x30
@@ -36,7 +36,7 @@
  *
  * Returns 1 on success or 0 on error.
  */
-int encode_der_length(WPACKET *pkt, size_t cont_len)
+int ossl_encode_der_length(WPACKET *pkt, size_t cont_len)
 {
     if (cont_len > 0xffff)
         return 0; /* Too large for supported length encodings */
@@ -63,7 +63,7 @@ int encode_der_length(WPACKET *pkt, size_t cont_len)
  *
  * Returns 1 on success or 0 on error.
  */
-int encode_der_integer(WPACKET *pkt, const BIGNUM *n)
+int ossl_encode_der_integer(WPACKET *pkt, const BIGNUM *n)
 {
     unsigned char *bnbytes;
     size_t cont_len;
@@ -84,7 +84,7 @@ int encode_der_integer(WPACKET *pkt, const BIGNUM *n)
 
     if (!WPACKET_start_sub_packet(pkt)
             || !WPACKET_put_bytes_u8(pkt, ID_INTEGER)
-            || !encode_der_length(pkt, cont_len)
+            || !ossl_encode_der_length(pkt, cont_len)
             || !WPACKET_allocate_bytes(pkt, cont_len, &bnbytes)
             || !WPACKET_close(pkt))
         return 0;
@@ -99,11 +99,11 @@ int encode_der_integer(WPACKET *pkt, const BIGNUM *n)
 /*
  * Outputs the DER encoding of a DSA-Sig-Value or ECDSA-Sig-Value to pkt. pkt
  * may be initialised with a NULL buffer which enables pkt to be used to
- * calulate how many bytes would be needed.
+ * calculate how many bytes would be needed.
  *
  * Returns 1 on success or 0 on error.
  */
-int encode_der_dsa_sig(WPACKET *pkt, const BIGNUM *r, const BIGNUM *s)
+int ossl_encode_der_dsa_sig(WPACKET *pkt, const BIGNUM *r, const BIGNUM *s)
 {
     WPACKET tmppkt, *dummypkt;
     size_t cont_len;
@@ -122,8 +122,8 @@ int encode_der_dsa_sig(WPACKET *pkt, const BIGNUM *r, const BIGNUM *s)
     }
 
     /* Calculate the content length */
-    if (!encode_der_integer(dummypkt, r)
-            || !encode_der_integer(dummypkt, s)
+    if (!ossl_encode_der_integer(dummypkt, r)
+            || !ossl_encode_der_integer(dummypkt, s)
             || !WPACKET_get_length(dummypkt, &cont_len)
             || (!isnull && !WPACKET_finish(dummypkt))) {
         if (!isnull)
@@ -133,13 +133,13 @@ int encode_der_dsa_sig(WPACKET *pkt, const BIGNUM *r, const BIGNUM *s)
 
     /* Add the tag and length bytes */
     if (!WPACKET_put_bytes_u8(pkt, ID_SEQUENCE)
-            || !encode_der_length(pkt, cont_len)
+            || !ossl_encode_der_length(pkt, cont_len)
                /*
                 * Really encode the integers. We already wrote to the main pkt
                 * if it had a NULL buffer, so don't do it again
                 */
-            || (!isnull && !encode_der_integer(pkt, r))
-            || (!isnull && !encode_der_integer(pkt, s))
+            || (!isnull && !ossl_encode_der_integer(pkt, r))
+            || (!isnull && !ossl_encode_der_integer(pkt, s))
             || !WPACKET_close(pkt))
         return 0;
 
@@ -152,7 +152,7 @@ int encode_der_dsa_sig(WPACKET *pkt, const BIGNUM *r, const BIGNUM *s)
  *
  * Returns 1 on success or 0 on failure.
  */
-int decode_der_length(PACKET *pkt, PACKET *subpkt)
+int ossl_decode_der_length(PACKET *pkt, PACKET *subpkt)
 {
     unsigned int byte;
 
@@ -184,7 +184,7 @@ int decode_der_length(PACKET *pkt, PACKET *subpkt)
  * trailing garbage then it is up to the caller to verify that all bytes
  * were consumed.
  */
-int decode_der_integer(PACKET *pkt, BIGNUM *n)
+int ossl_decode_der_integer(PACKET *pkt, BIGNUM *n)
 {
     PACKET contpkt, tmppkt;
     unsigned int tag, tmp;
@@ -192,7 +192,7 @@ int decode_der_integer(PACKET *pkt, BIGNUM *n)
     /* Check we have an integer and get the content bytes */
     if (!PACKET_get_1(pkt, &tag)
             || tag != ID_INTEGER
-            || !decode_der_length(pkt, &contpkt))
+            || !ossl_decode_der_length(pkt, &contpkt))
         return 0;
 
     /* Peek ahead at the first bytes to check for proper encoding */
@@ -230,8 +230,8 @@ int decode_der_integer(PACKET *pkt, BIGNUM *n)
  * trailing garbage then it is up to the caller to verify that all bytes
  * were consumed.
  */
-size_t decode_der_dsa_sig(BIGNUM *r, BIGNUM *s, const unsigned char **ppin,
-                          size_t len)
+size_t ossl_decode_der_dsa_sig(BIGNUM *r, BIGNUM *s,
+                               const unsigned char **ppin, size_t len)
 {
     size_t consumed;
     PACKET pkt, contpkt;
@@ -240,9 +240,9 @@ size_t decode_der_dsa_sig(BIGNUM *r, BIGNUM *s, const unsigned char **ppin,
     if (!PACKET_buf_init(&pkt, *ppin, len)
             || !PACKET_get_1(&pkt, &tag)
             || tag != ID_SEQUENCE
-            || !decode_der_length(&pkt, &contpkt)
-            || !decode_der_integer(&contpkt, r)
-            || !decode_der_integer(&contpkt, s)
+            || !ossl_decode_der_length(&pkt, &contpkt)
+            || !ossl_decode_der_integer(&contpkt, r)
+            || !ossl_decode_der_integer(&contpkt, s)
             || PACKET_remaining(&contpkt) != 0)
         return 0;
 
@@ -250,4 +250,3 @@ size_t decode_der_dsa_sig(BIGNUM *r, BIGNUM *s, const unsigned char **ppin,
     *ppin += consumed;
     return consumed;
 }
-