diff options
Diffstat (limited to 'docs/development')
-rw-r--r-- | docs/development/custom-vectors/cast5/verify_cast5.go | 44 | ||||
-rw-r--r-- | docs/development/test-vectors.rst | 25 |
2 files changed, 40 insertions, 29 deletions
diff --git a/docs/development/custom-vectors/cast5/verify_cast5.go b/docs/development/custom-vectors/cast5/verify_cast5.go index f735d989..cbc89a03 100644 --- a/docs/development/custom-vectors/cast5/verify_cast5.go +++ b/docs/development/custom-vectors/cast5/verify_cast5.go @@ -19,7 +19,7 @@ func unhexlify(s string) []byte { return bytes } -type VectorArgs struct { +type vectorArgs struct { count string key string iv string @@ -27,13 +27,13 @@ type VectorArgs struct { ciphertext string } -type VectorVerifier interface { - validate(count string, key, iv, plaintext, expected_ciphertext []byte) +type vectorVerifier interface { + validate(count string, key, iv, plaintext, expectedCiphertext []byte) } type ofbVerifier struct{} -func (o ofbVerifier) validate(count string, key, iv, plaintext, expected_ciphertext []byte) { +func (o ofbVerifier) validate(count string, key, iv, plaintext, expectedCiphertext []byte) { block, err := cast5.NewCipher(key) if err != nil { panic(err) @@ -43,17 +43,17 @@ func (o ofbVerifier) validate(count string, key, iv, plaintext, expected_ciphert stream := cipher.NewOFB(block, iv) stream.XORKeyStream(ciphertext, plaintext) - if !bytes.Equal(ciphertext, expected_ciphertext) { + if !bytes.Equal(ciphertext, expectedCiphertext) { panic(fmt.Errorf("vector mismatch @ COUNT = %s:\n %s != %s\n", count, - hex.EncodeToString(expected_ciphertext), + hex.EncodeToString(expectedCiphertext), hex.EncodeToString(ciphertext))) } } type cbcVerifier struct{} -func (o cbcVerifier) validate(count string, key, iv, plaintext, expected_ciphertext []byte) { +func (o cbcVerifier) validate(count string, key, iv, plaintext, expectedCiphertext []byte) { block, err := cast5.NewCipher(key) if err != nil { panic(err) @@ -63,17 +63,17 @@ func (o cbcVerifier) validate(count string, key, iv, plaintext, expected_ciphert mode := cipher.NewCBCEncrypter(block, iv) mode.CryptBlocks(ciphertext, plaintext) - if !bytes.Equal(ciphertext, expected_ciphertext) { + if !bytes.Equal(ciphertext, expectedCiphertext) { panic(fmt.Errorf("vector mismatch @ COUNT = %s:\n %s != %s\n", count, - hex.EncodeToString(expected_ciphertext), + hex.EncodeToString(expectedCiphertext), hex.EncodeToString(ciphertext))) } } type cfbVerifier struct{} -func (o cfbVerifier) validate(count string, key, iv, plaintext, expected_ciphertext []byte) { +func (o cfbVerifier) validate(count string, key, iv, plaintext, expectedCiphertext []byte) { block, err := cast5.NewCipher(key) if err != nil { panic(err) @@ -83,17 +83,17 @@ func (o cfbVerifier) validate(count string, key, iv, plaintext, expected_ciphert stream := cipher.NewCFBEncrypter(block, iv) stream.XORKeyStream(ciphertext, plaintext) - if !bytes.Equal(ciphertext, expected_ciphertext) { + if !bytes.Equal(ciphertext, expectedCiphertext) { panic(fmt.Errorf("vector mismatch @ COUNT = %s:\n %s != %s\n", count, - hex.EncodeToString(expected_ciphertext), + hex.EncodeToString(expectedCiphertext), hex.EncodeToString(ciphertext))) } } type ctrVerifier struct{} -func (o ctrVerifier) validate(count string, key, iv, plaintext, expected_ciphertext []byte) { +func (o ctrVerifier) validate(count string, key, iv, plaintext, expectedCiphertext []byte) { block, err := cast5.NewCipher(key) if err != nil { panic(err) @@ -103,15 +103,15 @@ func (o ctrVerifier) validate(count string, key, iv, plaintext, expected_ciphert stream := cipher.NewCTR(block, iv) stream.XORKeyStream(ciphertext, plaintext) - if !bytes.Equal(ciphertext, expected_ciphertext) { + if !bytes.Equal(ciphertext, expectedCiphertext) { panic(fmt.Errorf("vector mismatch @ COUNT = %s:\n %s != %s\n", count, - hex.EncodeToString(expected_ciphertext), + hex.EncodeToString(expectedCiphertext), hex.EncodeToString(ciphertext))) } } -func validateVectors(verifier VectorVerifier, filename string) { +func validateVectors(verifier vectorVerifier, filename string) { vectors, err := os.Open(filename) if err != nil { panic(err) @@ -119,7 +119,7 @@ func validateVectors(verifier VectorVerifier, filename string) { defer vectors.Close() var segments []string - var vector *VectorArgs + var vector *vectorArgs scanner := bufio.NewScanner(vectors) for scanner.Scan() { @@ -134,7 +134,7 @@ func validateVectors(verifier VectorVerifier, filename string) { unhexlify(vector.plaintext), unhexlify(vector.ciphertext)) } - vector = &VectorArgs{count: segments[1]} + vector = &vectorArgs{count: segments[1]} case strings.ToUpper(segments[0]) == "IV": vector.iv = segments[1][:16] case strings.ToUpper(segments[0]) == "KEY": @@ -150,15 +150,15 @@ func validateVectors(verifier VectorVerifier, filename string) { func main() { validateVectors(ofbVerifier{}, - "tests/hazmat/primitives/vectors/ciphers/CAST5/cast5-ofb.txt") + "vectors/cryptography_vectors/ciphers/CAST5/cast5-ofb.txt") fmt.Println("OFB OK.") validateVectors(cfbVerifier{}, - "tests/hazmat/primitives/vectors/ciphers/CAST5/cast5-cfb.txt") + "vectors/cryptography_vectors/ciphers/CAST5/cast5-cfb.txt") fmt.Println("CFB OK.") validateVectors(cbcVerifier{}, - "tests/hazmat/primitives/vectors/ciphers/CAST5/cast5-cbc.txt") + "vectors/cryptography_vectors/ciphers/CAST5/cast5-cbc.txt") fmt.Println("CBC OK.") validateVectors(ctrVerifier{}, - "tests/hazmat/primitives/vectors/ciphers/CAST5/cast5-ctr.txt") + "vectors/cryptography_vectors/ciphers/CAST5/cast5-ctr.txt") fmt.Println("CTR OK.") } diff --git a/docs/development/test-vectors.rst b/docs/development/test-vectors.rst index f59a3552..2edf1fbb 100644 --- a/docs/development/test-vectors.rst +++ b/docs/development/test-vectors.rst @@ -37,29 +37,40 @@ Asymmetric ciphers Custom Asymmetric Vectors ~~~~~~~~~~~~~~~~~~~~~~~~~ -* ``asymmetric/PEM_Serialization/ec_private_key.pem`` - Contains an Elliptic +* ``asymmetric/PEM_Serialization/ec_private_key.pem`` and + ``asymmetric/DER_Serialization/ec_private_key.der`` - Contains an Elliptic Curve key generated by OpenSSL from the curve ``secp256r1``. -* ``asymmetric/PEM_Serialization/ec_private_key_encrypted.pem`` - Contains the +* ``asymmetric/PEM_Serialization/ec_private_key_encrypted.pem`` and + ``asymmetric/DER_Serialization/ec_private_key_encrypted.der``- Contains the same Elliptic Curve key as ``ec_private_key.pem``, except that it is encrypted with AES-128 with the password "123456". -* ``asymmetric/PEM_Serialization/ec_public_key.pem`` - Contains the public key +* ``asymmetric/PEM_Serialization/ec_public_key.pem`` and + ``asymmetric/DER_Serialization/ec_public_key.der``- Contains the public key corresponding to ``ec_private_key.pem``, generated using OpenSSL. * ``asymmetric/PEM_Serialization/rsa_private_key.pem`` - Contains an RSA 2048 bit key generated using OpenSSL, protected by the secret "123456" with DES3 encryption. -* ``asymmetric/PEM_Serialization/rsa_public_key.pem`` - Contains an RSA 2048 +* ``asymmetric/PEM_Serialization/rsa_public_key.pem`` and + ``asymmetric/DER_Serialization/rsa_public_key.der``- Contains an RSA 2048 bit public generated using OpenSSL from ``rsa_private_key.pem``. * ``asymmetric/PEM_Serialization/dsaparam.pem`` - Contains 2048-bit DSA parameters generated using OpenSSL; contains no keys. * ``asymmetric/PEM_Serialization/dsa_private_key.pem`` - Contains a DSA 2048 bit key generated using OpenSSL from the parameters in ``dsaparam.pem``, protected by the secret "123456" with DES3 encryption. -* ``asymmetric/PEM_Serialization/dsa_public_key.pem`` - Contains a DSA 2048 bit +* ``asymmetric/PEM_Serialization/dsa_public_key.pem`` and + ``asymmetric/DER_Serialization/dsa_public_key.der`` - Contains a DSA 2048 bit key generated using OpenSSL from ``dsa_private_key.pem``. -* ``asymmetric/PEM_Serialization/unenc-dsa-pkcs8.pem`` - Contains a DSA 1024 +* ``asymmetric/PKCS8/unenc-dsa-pkcs8.pem`` and + ``asymmetric/DER_Serialization/unenc-dsa-pkcs8.der`` - Contains a DSA 1024 bit key generated using OpenSSL. -* ``asymmetric/PEM_Serialization/unenc-dsa-pkcs8.pub.pem`` - Contains a DSA +* ``asymmetric/PKCS8/unenc-dsa-pkcs8.pub.pem`` and + ``asymmetric/DER_Serialization/unenc-dsa-pkcs8.pub.der`` - Contains a DSA 2048 bit public key generated using OpenSSL from ``unenc-dsa-pkcs8.pem``. +* DER conversions of the `GnuTLS example keys`_ for DSA as well as the + `OpenSSL example key`_ for RSA. +* DER conversions of `enc-rsa-pkcs8.pem`_, `enc2-rsa-pkcs8.pem`_, and + `unenc-rsa-pkcs8.pem`_. X.509 |