diff --git a/src/openvpn/ssl_verify_openssl.c b/src/openvpn/ssl_verify_openssl.c
index ee29691..ab3c872 100644
--- a/src/openvpn/ssl_verify_openssl.c
+++ b/src/openvpn/ssl_verify_openssl.c
@@ -61,7 +61,11 @@
     BIGNUM *bn_serial = ASN1_INTEGER_to_BN(asn1_i, NULL);
     if (bn_serial != NULL)
     {
-        int size = BN_num_bytes(bn_serial);
+        /* Cast the return value of BN_num_bytes to unsigned int because it is
+         * int in OpenSSL and unsigned int in AWS-LC. The return value of
+         * BN_num_bytes should never be negative, and if it is, the cast will
+         * turn it into an unacceptably large value which will fail this check. */
+        unsigned int size = (unsigned int)BN_num_bytes(bn_serial);
         size_ok = size <= MAX_SERIAL_SIZE;
     }
     BN_free(bn_serial);
