#
# Copyright 2001-2023 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
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html

# Tests start with one of these keywords
#       Cipher Decrypt Derive Digest Encoding KDF MAC PBE
#       PrivPubKeyPair Sign Verify VerifyRecover
# and continue until a blank line. Lines starting with a pound sign are ignored.


# Private keys used for PKEY operations.

# DSA key
PrivateKey=DSA-1024
-----BEGIN PRIVATE KEY-----
MIIBSwIBADCCASwGByqGSM44BAEwggEfAoGBAO0SwRpkAeM21qSM5ch4CLEHpFk4
19R5ve1UUr421y3HEUURsrVpxYKvyx8aOBQC/akz95cYxNN3y1JnJJMxPklhdJrJ
f/WDYPxjMk8BqNJmeZtLuCVLKGwQomuo7ZkG955WRyLHYEdQ6uC7K2QTPKpW6psF
YFaDYjAjSEKk2MFxAhUAykDkKLZdhPWzwM8/qYaE31VmWz0CgYEApNVF8oFK41ez
Qci9XbSZJHyPB+3jML1YQkHxiiInaIz6GEFtjUbIUEYA/ovY+6ECNI1aIDHTd7CH
woS0mp33oQYs43nt29B6UwbtMmbzCOQ9vGGwWVho+JtHyyPWrDuLmkvLtoQPaxYt
6PVa3gncr2v3njcVuH+EQ6DuFR93zksEFgIUbyv6pqH+UQurernJn/7sUm2U2i0=
-----END PRIVATE KEY-----

PublicKey=DSA-1024-PUBLIC
-----BEGIN PUBLIC KEY-----

SzJw2oHciIOt+UU=
-----END PUBLIC KEY-----

PrivPubKeyPair = DSA-1024:DSA-1024-PUBLIC

Title = DSA tests

Verify = DSA-1024
Ctrl = digest:SHA1
Input = "0123456789ABCDEF1234"
Output = 302d021500942b8c5850e05b59e24495116b1e8559e51b610e0214237aedf272d91f2397f63c9fc8790e1a6cde5d87

Verify = DSA-1024-PUBLIC
Ctrl = digest:SHA1
Input = "0123456789ABCDEF1234"
Output = 302d021500942b8c5850e05b59e24495116b1e8559e51b610e0214237aedf272d91f2397f63c9fc8790e1a6cde5d87

# Modified signature
Verify = DSA-1024-PUBLIC
Ctrl = digest:SHA1
Input = "0123456789ABCDEF1234"
Output = 302d021500942b8c5850e05b59e24495116b1e8559e51b610e0214237aedf272d91f2397f63c9fc8790e1a6cde5d88
Result = VERIFY_ERROR

# Digest too short
Verify = DSA-1024-PUBLIC
Ctrl = digest:SHA1
Input = "0123456789ABCDEF123"
Output = 302d021500942b8c5850e05b59e24495116b1e8559e51b610e0214237aedf272d91f2397f63c9fc8790e1a6cde5d87
Result = VERIFY_ERROR

# Digest too long
Verify = DSA-1024-PUBLIC
Ctrl = digest:SHA1
Input = "0123456789ABCDEF12345"
Output = 302d021500942b8c5850e05b59e24495116b1e8559e51b610e0214237aedf272d91f2397f63c9fc8790e1a6cde5d87
Result = VERIFY_ERROR

# Garbage after signature
Verify = DSA-1024-PUBLIC
Input = "0123456789ABCDEF1234"
Output = 302d021500942b8c5850e05b59e24495116b1e8559e51b610e0214237aedf272d91f2397f63c9fc8790e1a6cde5d8700
Result = VERIFY_ERROR

# Invalid tag
Verify = DSA-1024-PUBLIC
Ctrl = digest:SHA1
Input = "0123456789ABCDEF1234"
Output = 312d021500942b8c5850e05b59e24495116b1e8559e51b610e0214237aedf272d91f2397f63c9fc8790e1a6cde5d87
Result = VERIFY_ERROR

# BER signature
Verify = DSA-1024-PUBLIC
Ctrl = digest:SHA1
Input = "0123456789ABCDEF1234"
Output = 3080021500942b8c5850e05b59e24495116b1e8559e51b610e0214237aedf272d91f2397f63c9fc8790e1a6cde5d870000
Result = VERIFY_ERROR

Title = Test keypair mismatches

PrivateKey = DSA-1024-BIS
-----BEGIN PRIVATE KEY-----
MIIBSwIBADCCASwGByqGSM44BAEwggEfAoGBAO0SwRpkAeM21qSM5ch4CLEHpFk419R5ve1UUr42
1y3HEUURsrVpxYKvyx8aOBQC/akz95cYxNN3y1JnJJMxPklhdJrJf/WDYPxjMk8BqNJmeZtLuCVL
KGwQomuo7ZkG955WRyLHYEdQ6uC7K2QTPKpW6psFYFaDYjAjSEKk2MFxAhUAykDkKLZdhPWzwM8/
qYaE31VmWz0CgYEApNVF8oFK41ezQci9XbSZJHyPB+3jML1YQkHxiiInaIz6GEFtjUbIUEYA/ovY
+6ECNI1aIDHTd7CHwoS0mp33oQYs43nt29B6UwbtMmbzCOQ9vGGwWVho+JtHyyPWrDuLmkvLtoQP
axYt6PVa3gncr2v3njcVuH+EQ6DuFR93zksEFgIUFQFshP0hj7i6ClXkSPYoFW6KrIY=
-----END PRIVATE KEY-----

PublicKey = DSA-1024-BIS-PUBLIC
-----BEGIN PUBLIC KEY-----

Q4A0wDK8dmF2dFI=
-----END PUBLIC KEY-----

PrivPubKeyPair = DSA-1024-BIS:DSA-1024-BIS-PUBLIC

PrivPubKeyPair = DSA-1024:DSA-1024-BIS-PUBLIC
Result = KEYPAIR_MISMATCH

PrivPubKeyPair = DSA-1024-BIS:DSA-1024-PUBLIC
Result = KEYPAIR_MISMATCH


PrivateKey = DSA-1024-FIPS186-2
-----BEGIN PRIVATE KEY-----
MIIBWgIBADCCATMGByqGSM44BAEwggEmAoGBALRSnNcjMPIl4tekT5D3AgqsK042
Ar1dGKeJCmWrSngAELtSH0yZCwsbl7wLEgG2lfusbn5sdtbpFioKInohZruRhzwC
59GRXjAFD0QPhVE/qy6Oto+8WIHAa/RiEIkxRfTiAe9Ach56k9lZYONDUHDqH38u
UIfjoUN+jlzoJcWbAh0A6TfgjmB+CxvxG/2pz8OAXXfNP8/JLfYvolE/fwKBgH7l
jLeoOofKc+rwO2Fha8nuFddXRSePZKzC7mRQsPXwfvX5V6msU2xizjdPIsqVu7qA
Bcc1YMd7/5C3vaKuS21DxBOs7nAHbO9ZZtGlpUAnJwM/P09nMb3yG6tR9LF3AQmu
Kr2KShQB0FlSgvcCDTX7g8eJ/UuIWo6wX4hSdHDhBB4CHAdVVg1m5ikOICUBo37Y
/TqkTaCFsMDwcDc20Jg=
-----END PRIVATE KEY-----

PrivateKey = DSA-2048-160
-----BEGIN PRIVATE KEY-----

r/MlbdGMvcA7l0XmzzY85w==
-----END PRIVATE KEY-----

PrivateKey = DSA-2048-224
-----BEGIN PRIVATE KEY-----

BB4CHBN2hfQxLXg+t/MNcza5M0WoAWna5JzQBAtDzIM=
-----END PRIVATE KEY-----

PrivateKey = DSA-2048-256
-----BEGIN PRIVATE KEY-----

aghyxFAEIgIgK1Ct6iRtcq01mdt4EGRrkiAHBr5zTcAgbv5ZaU99pmQ=
-----END PRIVATE KEY-----

PrivateKey = DSA-3072-256
-----BEGIN PRIVATE KEY-----

o3mO5AXuBuEe2g==
-----END PRIVATE KEY-----

PrivateKey = DSA-3072-224
-----BEGIN PRIVATE KEY-----

-----END PRIVATE KEY-----

PrivateKey = DSA-4096-256
-----BEGIN PRIVATE KEY-----

h2C/91Z0b0Xg4QYNOtVUbfqQTJQAqEpaRg==
-----END PRIVATE KEY-----

Title = FIPS Tests (using different key sizes and digests)

# Test sign with a 2048 bit key with N == 160 is not allowed in fips mode
Availablein = fips
DigestSign = SHA256
Key = DSA-2048-160
Input = "Hello"
Output = 00
Result = DIGESTSIGNINIT_ERROR

# Test sign with a 2048 bit key with N == 224 is allowed in fips mode
DigestSign = SHA256
Key = DSA-2048-224
Input = "Hello"
Output = 00
Result = SIGNATURE_MISMATCH

# Test sign with a 2048 bit key with N == 256 is allowed in fips mode
DigestSign = SHA256
Key = DSA-2048-256
Input = "Hello"
Result = SIGNATURE_MISMATCH

# Test sign with a 3072 bit key with N == 256 is allowed in fips mode
DigestSign = SHA256
Key = DSA-3072-256
Input = "Hello"
Result = SIGNATURE_MISMATCH

# Test sign with a 2048 bit SHA3 is allowed in fips mode
DigestSign = SHA3-224
Key = DSA-2048-256
Input = "Hello"
Result = SIGNATURE_MISMATCH

# Test verify with a 1024 bit key is allowed in fips mode
DigestVerify = SHA256
Key = DSA-1024
Input = "Hello "
Output = 302c02142e32c8a5b0bd19b2ba33fd9c78aad3729dcb1b9e02142c006f7726a9d6833d414865b95167ea5f4f7713

# Test verify with SHA1 is allowed in fips mode
DigestVerify = SHA1
Key = DSA-1024
Input = "Hello "
Output = 302c0214602d21ed37e46051bb3d06cc002adddeb4cdb3bd02144f39f75587b286588862d06366b2f29bddaf8cf6

# Test verify with a 2048/160 bit key is allowed in fips mode
FIPSversion = >3.1.1
DigestVerify = SHA256
Key = DSA-2048-160
Input = "Hello"
Output = 302e021500a51ca7f70ae206f221dc9b805bb04bfc07d6e448021500b16e45f9dac8aff04e115f96c00f4237d0fced41

Title = Fips Negative Tests (using different key sizes and digests)

# Test sign with a 1024 bit key is not allowed in fips mode
Availablein = fips
DigestSign = SHA256
Securitycheck = 1
Key = DSA-1024-FIPS186-2
Input = "Hello"
Result = DIGESTSIGNINIT_ERROR

# Test sign with SHA1 is not allowed in fips mode
Availablein = fips
DigestSign = SHA1
Securitycheck = 1
Key = DSA-2048
Input = "Hello"
Result = DIGESTSIGNINIT_ERROR

# Test sign with a 3072 bit key with N == 224 is not allowed in fips mode
Availablein = fips
DigestSign = SHA256
Securitycheck = 1
Key = DSA-3072-224
Input = "Hello"
Result = DIGESTSIGNINIT_ERROR

# Test sign with a 4096 bit key is not allowed in fips mode
Availablein = fips
DigestSign = SHA256
Securitycheck = 1
Key = DSA-4096-256
Input = "Hello"
Result = DIGESTSIGNINIT_ERROR
