Oops, s can be NULL
[oweals/openssl.git] / crypto / x509 / x509_cmp.c
index 4f157ba8076b0baec07b24c1e13b3770a12d81bd..2e444f28483e0f5b960249bd35d0f8b7b31b504a 100644 (file)
@@ -116,6 +116,13 @@ int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b)
        return(X509_NAME_cmp(a->crl->issuer,b->crl->issuer));
        }
 
+#ifndef OPENSSL_NO_SHA
+int X509_CRL_match(const X509_CRL *a, const X509_CRL *b)
+       {
+       return memcmp(a->sha1_hash, b->sha1_hash, 20);
+       }
+#endif
+
 X509_NAME *X509_get_issuer_name(X509 *a)
        {
        return(a->cert_info->issuer);
@@ -166,16 +173,16 @@ int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b)
        {
        int ret;
 
-       /* Ensure canonical encoding is present */
+       /* Ensure canonical encoding is present and up to date */
 
-       if (!a->canon_enc)
+       if (!a->canon_enc || a->modified)
                {
                ret = i2d_X509_NAME((X509_NAME *)a, NULL);
                if (ret < 0)
                        return -2;
                }
 
-       if (!b->canon_enc)
+       if (!b->canon_enc || b->modified)
                {
                ret = i2d_X509_NAME((X509_NAME *)b, NULL);
                if (ret < 0)
@@ -191,11 +198,27 @@ int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b)
 
        }
 
+unsigned long X509_NAME_hash(X509_NAME *x)
+       {
+       unsigned long ret=0;
+       unsigned char md[SHA_DIGEST_LENGTH];
+
+       /* Make sure X509_NAME structure contains valid cached encoding */
+       i2d_X509_NAME(x,NULL);
+       EVP_Digest(x->canon_enc, x->canon_enclen, md, NULL, EVP_sha1(), NULL);
+
+       ret=(   ((unsigned long)md[0]     )|((unsigned long)md[1]<<8L)|
+               ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L)
+               )&0xffffffffL;
+       return(ret);
+       }
+
 
 #ifndef OPENSSL_NO_MD5
 /* I now DER encode the name and hash it.  Since I cache the DER encoding,
  * this is reasonably efficient. */
-unsigned long X509_NAME_hash(X509_NAME *x)
+
+unsigned long X509_NAME_hash_old(X509_NAME *x)
        {
        unsigned long ret=0;
        unsigned char md[16];