Documentation
¶
Index ¶
- Constants
- Variables
- func AddPKCS7Padding(w io.Writer, dataSize int64, blockSize int) (int, error)
- func AddX923Padding(w io.Writer, dataSize int64, blockSize int) (int, error)
- func ConcatKDF(sharedSecret []byte, algorithmID []byte, partyUInfo []byte, partyVInfo []byte) ([]byte, error)
- func ConcatKDFWithDigest(sharedSecret []byte, algorithmID []byte, partyUInfo []byte, partyVInfo []byte, ...) ([]byte, error)
- func DecryptAESCBC(ciphertext []byte, key []byte, iv []byte) ([]byte, error)
- func DecryptAESGCM(ciphertext []byte, key []byte, iv []byte) ([]byte, error)
- func DecryptChaCha20Poly1305(ciphertext, key, nonce, aad []byte) ([]byte, error)
- func DecryptRSA(encrypted []byte, privKey *rsa.PrivateKey) ([]byte, error)
- func ECDHKeyAgreement(privKey *ecdsa.PrivateKey, pubKey *ecdsa.PublicKey) ([]byte, error)
- func ECNamedCurveOIDAndDigestURI(curve elliptic.Curve) (namedCurveOID string, digestURI string, err error)
- func EncryptAESCBC(plaintext []byte, key []byte, iv []byte) ([]byte, error)
- func EncryptAESGCM(plaintext []byte, key []byte, iv []byte) ([]byte, error)
- func EncryptAESGCMStream(dst io.Writer, src io.Reader, key []byte, iv []byte) error
- func EncryptChaCha20Poly1305(plaintext, key, nonce, aad []byte) ([]byte, error)
- func EncryptRSA(data []byte, cert *x509.Certificate) ([]byte, error)
- func ExtractECPublicKeyFromCertificate(cert *x509.Certificate) (*ecdsa.PublicKey, error)
- func GenerateDataEncryptionKey(lengthInBytes int) ([]byte, error)
- func GenerateECKeyPair(publicKey *ecdsa.PublicKey) (*ecdsa.PrivateKey, error)
- func GenerateIV(lengthInBytes int) ([]byte, error)
- func HKDFExpand(prk, info []byte, length int) ([]byte, error)
- func HKDFExpandSHA512(prk, info []byte, length int) ([]byte, error)
- func HKDFExtract(salt, ikm []byte) []byte
- func HKDFExtractSHA512(salt, ikm []byte) []byte
- func NewChaCha20Poly1305(key []byte) (cipher.AEAD, error)
- func RemovePKCS7Padding(data []byte) ([]byte, error)
- func RemovePKCS7PaddingFromData(data []byte) ([]byte, error)
- func RemoveX923Padding(data []byte) ([]byte, error)
- func RemoveX923PaddingFromData(data []byte) ([]byte, error)
- func UnwrapAES256(wrappedKey []byte, wrappingKey []byte) ([]byte, error)
- func ValidateECPoint(x, y *big.Int, curve elliptic.Curve) bool
- func ValidateECPublicKey(pubKey *ecdsa.PublicKey) error
- func WrapAES256(keyToWrap []byte, wrappingKey []byte) ([]byte, error)
Constants ¶
const ( // SecP256R1OID is the OID for secp256r1 (aka prime256v1) curve SecP256R1OID = "1.2.840.10045.3.1.7" // SecP384R1OID is the OID for secp384r1 curve SecP384R1OID = "1.3.132.0.34" DigestSHA256URI = "http://www.w3.org/2001/04/xmlenc#sha256" DigestSHA384URI = "http://www.w3.org/2001/04/xmlenc#sha384" DigestSHA512URI = "http://www.w3.org/2001/04/xmlenc#sha512" )
Variables ¶
var ( // P256 is the secp256r1 curve P256 = elliptic.P256() // P384 is the secp384r1 curve P384 = elliptic.P384() )
Functions ¶
func AddPKCS7Padding ¶
AddPKCS7Padding adds PKCS#7 padding to the output stream PKCS#7 padding fills with bytes equal to the padding length
func AddX923Padding ¶
AddX923Padding adds X.923 padding to the output stream X.923 padding fills with zeros and ends with the padding length
func ConcatKDF ¶
func ConcatKDF(sharedSecret []byte, algorithmID []byte, partyUInfo []byte, partyVInfo []byte) ([]byte, error)
ConcatKDF performs XMLENC11 ConcatKDF using SHA-384, deriving a 32-byte KEK for AES-KW-256. For digest selection or non-default key lengths, use ConcatKDFWithDigest.
func ConcatKDFWithDigest ¶ added in v2.0.1
func ConcatKDFWithDigest(sharedSecret []byte, algorithmID []byte, partyUInfo []byte, partyVInfo []byte, digestURI string, keyLen int) ([]byte, error)
ConcatKDFWithDigest performs XMLENC11 ConcatKDF with an explicit digest and output length. It derives keying material from:
Z (ECDH shared secret) and OtherInfo = AlgorithmID || PartyUInfo || PartyVInfo.
Construction (NIST SP 800-56A):
K = H(1 || Z || OtherInfo) || H(2 || Z || OtherInfo) || ...
Output is truncated to keyLen bytes.
func DecryptAESCBC ¶
DecryptAESCBC decrypts data using AES-128-CBC and removes padding
func DecryptAESGCM ¶
DecryptAESGCM decrypts data using AES-256-GCM
func DecryptChaCha20Poly1305 ¶
DecryptChaCha20Poly1305 decrypts ciphertext using ChaCha20-Poly1305 key must be 32 bytes nonce must be 12 bytes aad is additional authenticated data (must match encryption, can be nil) ciphertext includes the 16-byte authentication tag at the end Returns plaintext if authentication succeeds
func DecryptRSA ¶
func DecryptRSA(encrypted []byte, privKey *rsa.PrivateKey) ([]byte, error)
DecryptRSA decrypts data using RSA PKCS#1 v1.5 decryption
func ECDHKeyAgreement ¶
ECDHKeyAgreement performs ECDH key agreement and returns the shared secret
func ECNamedCurveOIDAndDigestURI ¶ added in v2.0.2
func ECNamedCurveOIDAndDigestURI(curve elliptic.Curve) (namedCurveOID string, digestURI string, err error)
ECNamedCurveOIDAndDigestURI returns the XMLENC11 NamedCurve OID and ConcatKDF digest URI for the given curve.
func EncryptAESCBC ¶
EncryptAESCBC encrypts data using AES-128-CBC with X.923 + PKCS#7 padding
func EncryptAESGCM ¶
EncryptAESGCM encrypts data using AES-256-GCM
func EncryptAESGCMStream ¶
EncryptAESGCMStream encrypts data stream using AES-256-GCM
func EncryptChaCha20Poly1305 ¶
EncryptChaCha20Poly1305 encrypts plaintext using ChaCha20-Poly1305 key must be 32 bytes (ChaCha20-Poly1305 key length) nonce must be 12 bytes (ChaCha20-Poly1305 nonce length) aad is additional authenticated data (can be nil) Returns ciphertext with authentication tag appended (16 bytes tag)
func EncryptRSA ¶
func EncryptRSA(data []byte, cert *x509.Certificate) ([]byte, error)
EncryptRSA encrypts data using RSA PKCS#1 v1.5 encryption
func ExtractECPublicKeyFromCertificate ¶
func ExtractECPublicKeyFromCertificate(cert *x509.Certificate) (*ecdsa.PublicKey, error)
ExtractECPublicKeyFromCertificate extracts the EC public key from a certificate
func GenerateDataEncryptionKey ¶
GenerateDataEncryptionKey generates a random AES key of specified length in bytes
func GenerateECKeyPair ¶
func GenerateECKeyPair(publicKey *ecdsa.PublicKey) (*ecdsa.PrivateKey, error)
GenerateECKeyPair generates an ephemeral EC key pair on the same curve as the given public key
func GenerateIV ¶
GenerateIV generates a random IV/nonce of specified length in bytes
func HKDFExpand ¶
HKDFExpand performs HKDF Expand operation (RFC 5869) Expand(PRK, info, L) -> OKM (Output Keying Material) PRK is the pseudo-random key from Extract info is optional context/application-specific information L is the desired output length in bytes
func HKDFExpandSHA512 ¶
HKDFExpandSHA512 performs HKDF Expand with SHA-512 Used for CDOC2 ECC key derivation
func HKDFExtract ¶
HKDFExtract performs HKDF Extract operation (RFC 5869) Extract(salt, IKM) -> PRK (Pseudo-Random Key) If salt is empty or nil, it uses a zero-filled salt of hash length
func HKDFExtractSHA512 ¶
HKDFExtractSHA512 performs HKDF Extract with SHA-512 Used for CDOC2 ECC key derivation
func NewChaCha20Poly1305 ¶
NewChaCha20Poly1305 creates a new ChaCha20-Poly1305 AEAD cipher This can be used for streaming encryption/decryption if needed
func RemovePKCS7Padding ¶
RemovePKCS7Padding removes PKCS#7 padding (internal helper)
func RemovePKCS7PaddingFromData ¶
RemovePKCS7PaddingFromData removes PKCS#7 padding from the data This is a separate function to avoid conflict with the internal helper in aes.go
func RemoveX923Padding ¶
RemoveX923Padding removes X.923 padding (internal helper)
func RemoveX923PaddingFromData ¶
RemoveX923PaddingFromData removes X.923 padding from the data This is a separate function to avoid conflict with the internal helper in aes.go
func UnwrapAES256 ¶
UnwrapAES256 unwraps a wrapped key using AES-KW-256 (RFC 3394)
func ValidateECPoint ¶
ValidateECPoint validates that an EC point is on the given curve
func ValidateECPublicKey ¶
ValidateECPublicKey validates an EC public key point
Types ¶
This section is empty.