Add a test for SPKI and PKCS8 parsing with unknown algorithms

In particular, EVP_parse_public_key was written to avoid checking for a
whole number of bytes until *after* we've recognized the OID. This is
almost certainly not worth the effort, but I suppose if we tried to do
that, we should test it.

Why X.509 decided SPKIs use BIT STRINGs instead of OCTET STRINGs, who
knows.

Change-Id: Ib18887c6bed2dbbd3407de262b4912ad38ccf9dd
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81507
Reviewed-by: Lily Chen <chlily@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/crypto/evp/evp_tests.txt b/crypto/evp/evp_tests.txt
index 749e641..6ba31ca 100644
--- a/crypto/evp/evp_tests.txt
+++ b/crypto/evp/evp_tests.txt
@@ -252,6 +252,21 @@
 Type = Ed25519
 Input = 302e020100300506032b657004220420d4ee72dbf913584ad5b6d8f1f769f8ad3afe7c28cbf1d4fbe097a88f44755842
 
+# Unsupported algorithms in the public and private key parser should be
+# rejected with EVP_R_UNSUPPORTED_ALGORITHM. This includes if the
+# subjectPublicKey BIT STRING field in the SPKI isn't a whole number of bytes.
+# Although all supported algorithms use a whole number of bytes, and it would be
+# unreasonable to define one that doesn't, such an SPKI is not necessarily a
+# syntax error when the algorithm is unknown.
+
+PublicKey = UnknownAlgorithm-Public
+Input = 3014300e060c2a864886f712040184b70902030205e0
+Error = UNSUPPORTED_ALGORITHM
+
+PrivateKey = UnknownAlgorithm-Private
+Input = 301b020100300e060c2a864886f712040184b709020406040474657374
+Error = UNSUPPORTED_ALGORITHM
+
 
 # RSA tests