Don't use BN_ULLONG in n2l8 use SCTS_TIMESTAMP.
[openssl.git] / crypto / x509v3 / v3_scts.c
index 32548007d8b68033a00a7dfdebf3617fd3901379..457d5acaaaa4b85c0ed960fddf31d54db2a296e2 100644 (file)
 #include <openssl/bn.h>
 #include "../ssl/ssl_locl.h"
 
+#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
+#define SCTS_TIMESTAMP unsigned __int64
+#elif defined(__arch64__)
+#define SCTS_TIMESTAMP unsigned long
+#else
+#define SCTS_TIMESTAMP unsigned long long
+#endif
+
+#define n2l8(c,l)      (l =((SCTS_TIMESTAMP)(*((c)++)))<<56, \
+                        l|=((SCTS_TIMESTAMP)(*((c)++)))<<48, \
+                        l|=((SCTS_TIMESTAMP)(*((c)++)))<<40, \
+                        l|=((SCTS_TIMESTAMP)(*((c)++)))<<32, \
+                        l|=((SCTS_TIMESTAMP)(*((c)++)))<<24, \
+                        l|=((SCTS_TIMESTAMP)(*((c)++)))<<16, \
+                        l|=((SCTS_TIMESTAMP)(*((c)++)))<< 8, \
+                        l|=((SCTS_TIMESTAMP)(*((c)++))))
+
+
 static int i2r_scts(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct, BIO *out, int indent);
 
 const X509V3_EXT_METHOD v3_ct_scts[] = {
@@ -96,7 +114,7 @@ static void tls12_signature_print(BIO *out, const unsigned char *data)
                BIO_printf(out, "%s", OBJ_nid2ln(nid));
        }
 
-static void timestamp_print(BIO *out, BN_ULLONG timestamp)
+static void timestamp_print(BIO *out, SCTS_TIMESTAMP timestamp)
        {
        ASN1_GENERALIZEDTIME *gen;
        char genstr[20];
@@ -118,7 +136,7 @@ static void timestamp_print(BIO *out, BN_ULLONG timestamp)
 static int i2r_scts(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct,
                       BIO *out, int indent)
        {
-       BN_ULLONG timestamp;
+       SCTS_TIMESTAMP timestamp;
        unsigned char* data = oct->data;
        unsigned short listlen, sctlen = 0, fieldlen;
 
@@ -141,9 +159,12 @@ static int i2r_scts(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct,
 
                BIO_printf(out, "%*sSigned Certificate Timestamp:", indent,
                           "");
+               BIO_printf(out, "\n%*sVersion   : ", indent + 4, "");
 
                if (*data == 0)         /* SCT v1 */
                        {
+                       BIO_printf(out, "v1(0)");
+
                        /* Fixed-length header:
                         *              struct {
                         * (1 byte)       Version sct_version;
@@ -155,9 +176,6 @@ static int i2r_scts(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct,
                                return 0;
                        sctlen -= 43;
 
-                       BIO_printf(out, "\n%*sVersion   : v1(0)", indent + 4,
-                                  "");
-
                        BIO_printf(out, "\n%*sLog ID    : ", indent + 4, "");
                        BIO_hex_string(out, indent + 16, 16, data + 1, 32);
 
@@ -195,9 +213,16 @@ static int i2r_scts(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct,
                                return 0;
                        BIO_printf(out, "\n%*s            ", indent + 4, "");
                        BIO_hex_string(out, indent + 16, 16, data, fieldlen);
-                       if (listlen > 0) BIO_printf(out, "\n");
                        data += fieldlen;
                        }
+               else                    /* Unknown version */
+                       {
+                       BIO_printf(out, "unknown\n%*s", indent + 16, "");
+                       BIO_hex_string(out, indent + 16, 16, data, sctlen);
+                       data += sctlen;
+                       }
+
+               if (listlen > 0) BIO_printf(out, "\n");
                }
 
        return 1;