Documentation
¶
Overview ¶
Package key_certificate implements the I2P KeyCertificate common data structure
Package key_certificate implements the I2P KeyCertificate common data structure
Package key_certificate implements the I2P KeyCertificate common data structure
Package key_certificate implements the I2P KeyCertificate common data structure
Package key_certificate implements the I2P KeyCertificate common data structure
Package key_certificate implements the I2P KeyCertificate common data structure
Package key_certificate implements the I2P KeyCertificate common data structure
Index ¶
- Constants
- Variables
- func ConstructSigningPublicKeyByType(data []byte, sigType int) (types.SigningPublicKey, error)
- func GetCryptoKeySize(cryptoType int) (int, error)
- func GetMLKEMHybridKeySize(cryptoType int) (int, error)
- func GetSignatureSize(signingType int) (int, error)
- func GetSigningKeySize(signingType int) (int, error)
- type KeyCertificate
- func KeyCertificateFromCertificate(cert *certificate.Certificate) (*KeyCertificate, error)
- func NewDSAElGamalKeyCertificate() (*KeyCertificate, error)
- func NewECDSAP256KeyCertificate() (*KeyCertificate, error)
- func NewECDSAP384KeyCertificate() (*KeyCertificate, error)
- func NewEd25519X25519KeyCertificate() (*KeyCertificate, error)
- func NewKeyCertificate(bytes []byte) (key_certificate *KeyCertificate, remainder []byte, err error)
- func NewKeyCertificateWithTypes(signingType, cryptoType int) (*KeyCertificate, error)
- func NewRedDSAX25519KeyCertificate() (*KeyCertificate, error)
- func (keyCertificate KeyCertificate) ConstructPublicKey(data []byte) (public_key types.ReceivingPublicKey, err error)
- func (keyCertificate KeyCertificate) ConstructSigningPublicKey(data []byte) (signing_public_key types.SigningPublicKey, err error)
- func (keyCertificate KeyCertificate) CryptoPublicKeySize() (int, error)
- func (keyCertificate KeyCertificate) CryptoSize() (size int)
- func (keyCertificate KeyCertificate) CryptoSizeOrError() (int, error)
- func (keyCertificate KeyCertificate) Data() ([]byte, error)
- func (keyCertificate KeyCertificate) PublicKeyType() (pubkey_type int)
- func (keyCertificate KeyCertificate) SignatureSize() (size int)
- func (keyCertificate KeyCertificate) SignatureSizeOrError() (int, error)
- func (keyCertificate KeyCertificate) SigningPublicKeySize() int
- func (keyCertificate KeyCertificate) SigningPublicKeySizeOrError() (int, error)
- func (keyCertificate KeyCertificate) SigningPublicKeyType() (signing_pubkey_type int)
- type KeySizeInfo
Constants ¶
const ( // KEYCERT_SIGN_DSA_SHA1 identifies DSA with SHA-1 signature algorithm (type 0). // This is the legacy signature type used in early I2P implementations. // // DEPRECATED: This algorithm is deprecated for new router identities as of I2P 0.9.58. // Use KEYCERT_SIGN_ED25519 (type 7) for new implementations. // SHA-1 is cryptographically weak and DSA keys provide insufficient security for modern standards. // Maintained only for backward compatibility with legacy destinations and router identities. KEYCERT_SIGN_DSA_SHA1 = 0 // KEYCERT_SIGN_P256 identifies ECDSA-SHA256-P256 signature algorithm (type 1). // Uses NIST P-256 elliptic curve with SHA-256 hash function. // Provides 128-bit security level with 64-byte signatures. // // DEPRECATED: This algorithm is deprecated for new implementations. // Use KEYCERT_SIGN_ED25519 (type 7) for better performance and security. // Maintained for compatibility with older destinations only. KEYCERT_SIGN_P256 = 1 // KEYCERT_SIGN_P384 identifies ECDSA-SHA384-P384 signature algorithm (type 2). // Uses NIST P-384 elliptic curve with SHA-384 hash function. // Provides 192-bit security level with 96-byte signatures. // // DEPRECATED: This algorithm is deprecated for new implementations. // Use KEYCERT_SIGN_ED25519 (type 7) for better performance. // Rarely used; maintained for compatibility with legacy systems only. KEYCERT_SIGN_P384 = 2 // KEYCERT_SIGN_P521 identifies ECDSA-SHA512-P521 signature algorithm (type 3). // Uses NIST P-521 elliptic curve with SHA-512 hash function. // Provides 256-bit security level with 132-byte signatures. // // DEPRECATED: This algorithm is deprecated for new implementations. // Use KEYCERT_SIGN_ED25519 (type 7) for better performance. // Rarely used; maintained for compatibility with legacy systems only. KEYCERT_SIGN_P521 = 3 // KEYCERT_SIGN_RSA2048 identifies RSA-SHA256-2048 signature algorithm (type 4). // Uses 2048-bit RSA keys with SHA-256 hash function. // // DEPRECATED: This algorithm is deprecated for new implementations. // Use KEYCERT_SIGN_ED25519 (type 7) for better performance and smaller signatures. // Primarily used for offline signing operations, rarely for router identities. KEYCERT_SIGN_RSA2048 = 4 // KEYCERT_SIGN_RSA3072 identifies RSA-SHA384-3072 signature algorithm (type 5). // Uses 3072-bit RSA keys with SHA-384 hash function. // // DEPRECATED: This algorithm is deprecated for new implementations. // Use KEYCERT_SIGN_ED25519 (type 7) for better performance and smaller signatures. // Enhanced security variant for offline signing operations. KEYCERT_SIGN_RSA3072 = 5 // KEYCERT_SIGN_RSA4096 identifies RSA-SHA512-4096 signature algorithm (type 6). // Uses 4096-bit RSA keys with SHA-512 hash function. // Maximum security RSA variant for offline signing operations. KEYCERT_SIGN_RSA4096 = 6 // KEYCERT_SIGN_ED25519 identifies EdDSA-SHA512-Ed25519 signature algorithm (type 7). // Uses Ed25519 Edwards curve with SHA-512 for high-performance signatures. // Current standard for router identities and destinations since I2P 0.9.15. KEYCERT_SIGN_ED25519 = 7 // KEYCERT_SIGN_ED25519PH identifies EdDSA-SHA512-Ed25519ph signature algorithm (type 8). // Uses Ed25519ph (pre-hashed) variant with SHA-512 for large message efficiency. // Optimized for offline signing of large datasets. KEYCERT_SIGN_ED25519PH = 8 // KEYCERT_SIGN_REDDSA_ED25519 identifies RedDSA-SHA512-Ed25519 signature algorithm (type 11). // Uses RedDSA (randomized EdDSA) variant with SHA-512 for enhanced security. // Supported for Destinations and EncryptedLeaseSets only, not Router Identities. // Added in I2P specification 0.9.39. KEYCERT_SIGN_REDDSA_ED25519 = 11 // KEYCERT_SIGN_MLDSA_RESERVED_START marks the beginning of the MLDSA reserved range (type 12). KEYCERT_SIGN_MLDSA_RESERVED_START = 12 // KEYCERT_SIGN_MLDSA_RESERVED_END marks the end of the MLDSA reserved range (type 20). KEYCERT_SIGN_MLDSA_RESERVED_END = 20 // KEYCERT_SIGN_EXPERIMENTAL_START marks the beginning of the experimental signature type range (type 65280). // This range (65280-65534) is reserved for testing and experimental signature algorithms. KEYCERT_SIGN_EXPERIMENTAL_START = 65280 // KEYCERT_SIGN_EXPERIMENTAL_END marks the end of the experimental signature type range (type 65534). // Experimental types should not be used in production I2P networks. KEYCERT_SIGN_EXPERIMENTAL_END = 65534 // KEYCERT_SIGN_FUTURE_EXPANSION is reserved for future signature algorithm expansion (type 65535). // This type is reserved but not currently defined in the I2P specification. KEYCERT_SIGN_FUTURE_EXPANSION = 65535 )
Key Certificate Signing Key Types
const ( // KEYCERT_CRYPTO_ELG identifies ElGamal encryption algorithm (type 0). // Traditional I2P encryption using 2048-bit ElGamal keys. // // DEPRECATED: This algorithm is deprecated for Router Identities as of I2P 0.9.58. // Use KEYCERT_CRYPTO_X25519 (type 4) for new router identities. // ElGamal is computationally expensive and provides weaker security than modern alternatives. // Still used for legacy compatibility and Destination encryption, but should be avoided for new RIs. KEYCERT_CRYPTO_ELG = 0 // KEYCERT_CRYPTO_P256 identifies ECDH-P256 encryption algorithm (type 1). // Uses NIST P-256 elliptic curve for Elliptic Curve Diffie-Hellman key exchange. // Provides 128-bit security level with improved performance over ElGamal. KEYCERT_CRYPTO_P256 = 1 // KEYCERT_CRYPTO_P384 identifies ECDH-P384 encryption algorithm (type 2). // Uses NIST P-384 elliptic curve for enhanced security key exchange. // Provides 192-bit security level for high-security applications. KEYCERT_CRYPTO_P384 = 2 // KEYCERT_CRYPTO_P521 identifies ECDH-P521 encryption algorithm (type 3). // Uses NIST P-521 elliptic curve for maximum security key exchange. // Provides 256-bit security level for the most sensitive operations. KEYCERT_CRYPTO_P521 = 3 // KEYCERT_CRYPTO_X25519 identifies X25519 encryption algorithm (type 4). // Uses Curve25519 for high-performance Elliptic Curve Diffie-Hellman. // Modern standard offering excellent security with optimized implementation. KEYCERT_CRYPTO_X25519 = 4 // KEYCERT_CRYPTO_MLKEM512_X25519 identifies MLKEM512+X25519 hybrid encryption (type 5). // Combines MLKEM-512 post-quantum KEM with X25519 for quantum-resistant encryption. // Provides NIST security level 1 (equivalent to AES-128) with 32-byte public keys. // Only supported for LeaseSet encryption as of I2P 0.9.67. // // NOTE: This type is defined by I2P Proposal 169 (Post-Quantum Cryptography) // and is not yet in the mainline common structures spec as of 0.9.67. KEYCERT_CRYPTO_MLKEM512_X25519 = 5 // KEYCERT_CRYPTO_MLKEM768_X25519 identifies MLKEM768+X25519 hybrid encryption (type 6). // Combines MLKEM-768 post-quantum KEM with X25519 for enhanced quantum resistance. // Provides NIST security level 3 (equivalent to AES-192) with 32-byte public keys. // Only supported for LeaseSet encryption as of I2P 0.9.67. // // NOTE: This type is defined by I2P Proposal 169 (Post-Quantum Cryptography) // and is not yet in the mainline common structures spec as of 0.9.67. KEYCERT_CRYPTO_MLKEM768_X25519 = 6 // KEYCERT_CRYPTO_MLKEM1024_X25519 identifies MLKEM1024+X25519 hybrid encryption (type 7). // Combines MLKEM-1024 post-quantum KEM with X25519 for maximum quantum resistance. // Provides NIST security level 5 (equivalent to AES-256) with 32-byte public keys. // Only supported for LeaseSet encryption as of I2P 0.9.67. // // NOTE: This type is defined by I2P Proposal 169 (Post-Quantum Cryptography) // and is not yet in the mainline common structures spec as of 0.9.67. KEYCERT_CRYPTO_MLKEM1024_X25519 = 7 // KEYCERT_CRYPTO_RESERVED_NONE is reserved for future use (type 255). // Reserved by Proposal 169 for potential "no encryption" designation. // Not currently implemented in any I2P version. KEYCERT_CRYPTO_RESERVED_NONE = 255 // KEYCERT_CRYPTO_EXPERIMENTAL_START marks the beginning of the experimental encryption type range (type 65280). // This range (65280-65534) is reserved for testing and experimental encryption algorithms. KEYCERT_CRYPTO_EXPERIMENTAL_START = 65280 // KEYCERT_CRYPTO_EXPERIMENTAL_END marks the end of the experimental encryption type range (type 65534). // Experimental types should not be used in production I2P networks. KEYCERT_CRYPTO_EXPERIMENTAL_END = 65534 // KEYCERT_CRYPTO_FUTURE_EXPANSION is reserved for future encryption algorithm expansion (type 65535). // This type is reserved but not currently defined in the I2P specification. // Symmetric with KEYCERT_SIGN_FUTURE_EXPANSION. KEYCERT_CRYPTO_FUTURE_EXPANSION = 65535 )
Key Certificate Public Key Types
const ( // KEYCERT_SIGN_DSA_SHA1_SIZE defines the size of DSA-SHA1 signing public keys (128 bytes). // Traditional DSA public key size for legacy signature verification. KEYCERT_SIGN_DSA_SHA1_SIZE = 128 // KEYCERT_SIGN_P256_SIZE defines the size of ECDSA-P256 signing public keys (64 bytes). // Compact elliptic curve public key for efficient signature operations. KEYCERT_SIGN_P256_SIZE = 64 // KEYCERT_SIGN_P384_SIZE defines the size of ECDSA-P384 signing public keys (96 bytes). // Enhanced security elliptic curve public key with larger key size. KEYCERT_SIGN_P384_SIZE = 96 // KEYCERT_SIGN_P521_SIZE defines the size of ECDSA-P521 signing public keys (132 bytes). // Maximum security elliptic curve public key for highest protection level. KEYCERT_SIGN_P521_SIZE = 132 // KEYCERT_SIGN_RSA2048_SIZE defines the size of RSA-2048 signing public keys (256 bytes). // Standard RSA public key size for offline signing operations. KEYCERT_SIGN_RSA2048_SIZE = 256 // KEYCERT_SIGN_RSA3072_SIZE defines the size of RSA-3072 signing public keys (384 bytes). // Enhanced RSA public key size for improved security in offline operations. KEYCERT_SIGN_RSA3072_SIZE = 384 // KEYCERT_SIGN_RSA4096_SIZE defines the size of RSA-4096 signing public keys (512 bytes). // Maximum RSA public key size for highest security offline signing. KEYCERT_SIGN_RSA4096_SIZE = 512 // KEYCERT_SIGN_ED25519_SIZE defines the size of Ed25519 signing public keys (32 bytes). // Compact Edwards curve public key for high-performance signature verification. KEYCERT_SIGN_ED25519_SIZE = 32 // KEYCERT_SIGN_ED25519PH_SIZE defines the size of Ed25519ph signing public keys (32 bytes). // Pre-hashed Ed25519 variant with same key size but optimized for large messages. KEYCERT_SIGN_ED25519PH_SIZE = 32 // KEYCERT_SIGN_REDDSA_ED25519_SIZE defines the size of RedDSA-Ed25519 signing public keys (32 bytes). // RedDSA uses the same 32-byte key format as Ed25519. KEYCERT_SIGN_REDDSA_ED25519_SIZE = 32 )
signingPublicKey sizes for Signing Key Types
const ( // KEYCERT_CRYPTO_ELG_SIZE defines the size of ElGamal public keys (256 bytes). // Traditional I2P encryption key size for ElGamal asymmetric encryption. KEYCERT_CRYPTO_ELG_SIZE = 256 // KEYCERT_CRYPTO_P256_SIZE defines the size of ECDH-P256 public keys (64 bytes). // NIST P-256 elliptic curve public key for efficient key exchange operations. KEYCERT_CRYPTO_P256_SIZE = 64 // KEYCERT_CRYPTO_P384_SIZE defines the size of ECDH-P384 public keys (96 bytes). // NIST P-384 elliptic curve public key for enhanced security key exchange. KEYCERT_CRYPTO_P384_SIZE = 96 // KEYCERT_CRYPTO_P521_SIZE defines the size of ECDH-P521 public keys (132 bytes). // NIST P-521 elliptic curve public key for maximum security key exchange. KEYCERT_CRYPTO_P521_SIZE = 132 // KEYCERT_CRYPTO_X25519_SIZE defines the size of X25519 public keys (32 bytes). // Curve25519 public key for high-performance Diffie-Hellman key exchange. KEYCERT_CRYPTO_X25519_SIZE = 32 // KEYCERT_CRYPTO_MLKEM512_X25519_SIZE is the X25519-component size stored in the standard // KeysAndCert public key field for MLKEM-512+X25519 hybrid encryption (32 bytes). // The full hybrid key (MLKEM-512 PK + X25519 PK) is 832 bytes; use // GetMLKEMHybridKeySize(KEYCERT_CRYPTO_MLKEM512_X25519) to obtain the full size. KEYCERT_CRYPTO_MLKEM512_X25519_SIZE = 32 // KEYCERT_CRYPTO_MLKEM768_X25519_SIZE is the X25519-component size stored in the standard // KeysAndCert public key field for MLKEM-768+X25519 hybrid encryption (32 bytes). // The full hybrid key (MLKEM-768 PK + X25519 PK) is 1216 bytes; use // GetMLKEMHybridKeySize(KEYCERT_CRYPTO_MLKEM768_X25519) to obtain the full size. KEYCERT_CRYPTO_MLKEM768_X25519_SIZE = 32 // KEYCERT_CRYPTO_MLKEM1024_X25519_SIZE is the X25519-component size stored in the standard // KeysAndCert public key field for MLKEM-1024+X25519 hybrid encryption (32 bytes). // The full hybrid key (MLKEM-1024 PK + X25519 PK) is 1600 bytes; use // GetMLKEMHybridKeySize(KEYCERT_CRYPTO_MLKEM1024_X25519) to obtain the full size. KEYCERT_CRYPTO_MLKEM1024_X25519_SIZE = 32 )
publicKey sizes for Public Key Types
const ( // KEYCERT_PUBKEY_SIZE defines the standard public key field size in Key Certificates (256 bytes). // This is the legacy size used for ElGamal keys and maintained for compatibility. // Modern algorithms may use smaller keys but are padded to this size. KEYCERT_PUBKEY_SIZE = 256 // KEYCERT_SPK_SIZE defines the standard signing public key field size in Key Certificates (128 bytes). // This is the legacy size used for DSA keys and maintained for compatibility. // Modern algorithms may use smaller keys but are padded to this size. KEYCERT_SPK_SIZE = 128 )
Sizes of structures in KeyCertificates
const ( // CRYPTO_KEY_TYPE_ELGAMAL identifies ElGamal encryption for legacy compatibility (type 0). // This constant maintains compatibility with older certificate parsing code // that may reference the ElGamal algorithm by this alternative name. // // DEPRECATED alias: prefer KEYCERT_CRYPTO_ELG (= 0) to avoid duplicate-constant drift. CRYPTO_KEY_TYPE_ELGAMAL = 0 // ElGamal // Signature Types // SIGNATURE_TYPE_DSA_SHA1 identifies DSA-SHA1 signatures for legacy compatibility (type 0). // Alternative constant name for DSA-SHA1 algorithm used in signature verification. // // DEPRECATED alias: prefer KEYCERT_SIGN_DSA_SHA1 (= 0) to avoid duplicate-constant drift. SIGNATURE_TYPE_DSA_SHA1 = 0 // DSA-SHA1 // SIGNATURE_TYPE_ED25519_SHA512 identifies Ed25519-SHA512 signatures (type 7). // Alternative constant name for Ed25519 algorithm used in modern I2P implementations. // // DEPRECATED alias: prefer KEYCERT_SIGN_ED25519 (= 7) to avoid duplicate-constant drift. SIGNATURE_TYPE_ED25519_SHA512 = 7 // Ed25519 )
Additional crypto and signature type constants
const ( // MLKEM512_X25519_HYBRID_SIZE is the full MLKEM-512+X25519 public key size (800 + 32 bytes). MLKEM512_X25519_HYBRID_SIZE = 832 // MLKEM768_X25519_HYBRID_SIZE is the full MLKEM-768+X25519 public key size (1184 + 32 bytes). MLKEM768_X25519_HYBRID_SIZE = 1216 // MLKEM1024_X25519_HYBRID_SIZE is the full MLKEM-1024+X25519 public key size (1568 + 32 bytes). MLKEM1024_X25519_HYBRID_SIZE = 1600 )
MLKEM+X25519 hybrid public key total sizes (MLKEM component + 32-byte X25519 component). These sizes apply to the full hybrid key material used outside the standard KeysAndCert structure (e.g. in LeaseSet2 / EncryptedLeaseSet blocks). Source: I2P Proposal 169 (Post-Quantum Cryptography).
const ( // KEYCERT_MIN_SIZE defines the minimum size in bytes for a valid Key Certificate. // This includes the certificate header, type fields, and minimal payload data. // Used for validation during certificate parsing to prevent buffer underruns. KEYCERT_MIN_SIZE = 7 )
Minimum size constants
Variables ¶
var CryptoKeySizes = map[int]KeySizeInfo{
KEYCERT_CRYPTO_ELG: {
CryptoPublicKeySize: 256,
CryptoPrivateKeySize: 256,
},
KEYCERT_CRYPTO_P256: {
CryptoPublicKeySize: 64,
CryptoPrivateKeySize: 32,
},
KEYCERT_CRYPTO_P384: {
CryptoPublicKeySize: 96,
CryptoPrivateKeySize: 48,
},
KEYCERT_CRYPTO_P521: {
CryptoPublicKeySize: 132,
CryptoPrivateKeySize: 66,
},
KEYCERT_CRYPTO_X25519: {
CryptoPublicKeySize: 32,
CryptoPrivateKeySize: 32,
},
KEYCERT_CRYPTO_MLKEM512_X25519: {
CryptoPublicKeySize: 32,
CryptoPrivateKeySize: 32,
},
KEYCERT_CRYPTO_MLKEM768_X25519: {
CryptoPublicKeySize: 32,
CryptoPrivateKeySize: 32,
},
KEYCERT_CRYPTO_MLKEM1024_X25519: {
CryptoPublicKeySize: 32,
CryptoPrivateKeySize: 32,
},
}
CryptoKeySizes maps crypto key types to their size information. This provides compile-time constant lookups without requiring object creation.
Sizes are based on I2P specification 0.9.67: https://geti2p.net/spec/common-structures#certificate
var CryptoPublicKeySizes map[uint16]int
CryptoPublicKeySizes maps crypto key types to their sizes in bytes. This map is derived from the canonical CryptoKeySizes map to avoid duplicate data and manual synchronization.
Deprecated: Prefer CryptoKeySizes (map[int]KeySizeInfo) for complete key size information including private key sizes.
var SignaturePublicKeySizes map[uint16]int
SignaturePublicKeySizes maps signature types to their public key sizes in bytes. This map is derived from the canonical SigningKeySizes map to avoid duplicate data and manual synchronization.
Deprecated: Prefer SigningKeySizes (map[int]KeySizeInfo) for complete key size information including signature and private key sizes.
var SigningKeySizes = map[int]KeySizeInfo{
KEYCERT_SIGN_DSA_SHA1: {
SignatureSize: 40,
SigningPublicKeySize: 128,
SigningPrivateKeySize: 20,
},
KEYCERT_SIGN_P256: {
SignatureSize: 64,
SigningPublicKeySize: 64,
SigningPrivateKeySize: 32,
},
KEYCERT_SIGN_P384: {
SignatureSize: 96,
SigningPublicKeySize: 96,
SigningPrivateKeySize: 48,
},
KEYCERT_SIGN_P521: {
SignatureSize: 132,
SigningPublicKeySize: 132,
SigningPrivateKeySize: 66,
},
KEYCERT_SIGN_RSA2048: {
SignatureSize: 256,
SigningPublicKeySize: 256,
SigningPrivateKeySize: 512,
},
KEYCERT_SIGN_RSA3072: {
SignatureSize: 384,
SigningPublicKeySize: 384,
SigningPrivateKeySize: 768,
},
KEYCERT_SIGN_RSA4096: {
SignatureSize: 512,
SigningPublicKeySize: 512,
SigningPrivateKeySize: 1024,
},
KEYCERT_SIGN_ED25519: {
SignatureSize: 64,
SigningPublicKeySize: 32,
SigningPrivateKeySize: 32,
},
KEYCERT_SIGN_ED25519PH: {
SignatureSize: 64,
SigningPublicKeySize: 32,
SigningPrivateKeySize: 32,
},
KEYCERT_SIGN_REDDSA_ED25519: {
SignatureSize: 64,
SigningPublicKeySize: 32,
SigningPrivateKeySize: 32,
},
}
SigningKeySizes maps signing key types to their size information. This provides compile-time constant lookups without requiring object creation.
Sizes are based on I2P specification 0.9.67: https://geti2p.net/spec/common-structures#certificate
Functions ¶
func ConstructSigningPublicKeyByType ¶ added in v0.1.5
func ConstructSigningPublicKeyByType(data []byte, sigType int) (types.SigningPublicKey, error)
ConstructSigningPublicKeyByType constructs a SigningPublicKey from raw bytes and a signature type identifier. This is useful when creating a verifier for an offline transient signing key whose type may differ from the destination's key certificate.
Parameters:
- data: Raw public key bytes (length must match expected size for sigType)
- sigType: Signature type identifier (e.g., KEYCERT_SIGN_ED25519)
Returns the constructed SigningPublicKey or an error if the type is unsupported.
func GetCryptoKeySize ¶ added in v0.0.6
GetCryptoKeySize returns the crypto public key size for the given crypto type. Returns error if the crypto type is unknown.
func GetMLKEMHybridKeySize ¶ added in v0.1.5
GetMLKEMHybridKeySize returns the total combined public key size (MLKEM + X25519) for the given MLKEM+X25519 hybrid crypto type.
Unlike CryptoKeySizes[type].CryptoPublicKeySize (which returns 32 bytes – the X25519 component stored in the fixed KeysAndCert public key field), this function returns the full hybrid size needed when allocating buffers for MLKEM key-encapsulation operations.
Returns an error for any non-MLKEM crypto type.
func GetSignatureSize ¶ added in v0.0.6
GetSignatureSize returns the signature size for the given signing type. Returns error if the signing type is unknown.
func GetSigningKeySize ¶ added in v0.0.6
GetSigningKeySize returns the signing public key size for the given signing type. Returns error if the signing type is unknown.
Types ¶
type KeyCertificate ¶
type KeyCertificate struct {
certificate.Certificate
SpkType data.Integer
CpkType data.Integer
}
KeyCertificate represents an I2P Key Certificate structure https://geti2p.net/spec/common-structures#certificate Accurate for version 0.9.67
+----+----+----+----+----+-// |type| length | payload +----+----+----+----+----+-//
type :: Integer
length -> 1 byte case 0 -> NULL case 1 -> HASHCASH case 2 -> HIDDEN case 3 -> SIGNED case 4 -> MULTIPLE case 5 -> KEY
length :: Integer
length -> 2 bytes
payload :: data
length -> $length bytes
func KeyCertificateFromCertificate ¶
func KeyCertificateFromCertificate(cert *certificate.Certificate) (*KeyCertificate, error)
KeyCertificateFromCertificate creates a KeyCertificate from an existing Certificate
func NewDSAElGamalKeyCertificate ¶ added in v0.0.6
func NewDSAElGamalKeyCertificate() (*KeyCertificate, error)
NewDSAElGamalKeyCertificate creates a key certificate with DSA-SHA1 signing and ElGamal crypto keys. This is the legacy key type combination from early I2P implementations.
DEPRECATED: This algorithm is deprecated as of I2P 0.9.58. Use NewEd25519X25519KeyCertificate for new implementations. SHA-1 is cryptographically weak and DSA keys provide insufficient security. Maintained only for backward compatibility with legacy destinations.
func NewECDSAP256KeyCertificate ¶ added in v0.0.6
func NewECDSAP256KeyCertificate() (*KeyCertificate, error)
NewECDSAP256KeyCertificate creates a key certificate with ECDSA P-256 signing and ElGamal crypto keys. This combination provides 128-bit security level.
DEPRECATED: Use NewEd25519X25519KeyCertificate for better performance. This is maintained for compatibility with legacy destinations.
func NewECDSAP384KeyCertificate ¶ added in v0.0.6
func NewECDSAP384KeyCertificate() (*KeyCertificate, error)
NewECDSAP384KeyCertificate creates a key certificate with ECDSA P-384 signing and ElGamal crypto keys. This combination provides 192-bit security level.
DEPRECATED: Use NewEd25519X25519KeyCertificate for better performance. This is maintained for compatibility with legacy destinations.
func NewEd25519X25519KeyCertificate ¶ added in v0.0.6
func NewEd25519X25519KeyCertificate() (*KeyCertificate, error)
NewEd25519X25519KeyCertificate creates a key certificate with Ed25519 signing and X25519 crypto keys. This is the recommended key type combination for modern I2P applications.
Ed25519 provides:
- High-performance signature verification
- 32-byte compact public keys
- 64-byte signatures
- 128-bit security level
X25519 provides:
- High-performance key exchange
- 32-byte compact public keys
- 128-bit security level
This combination is the current standard for router identities and destinations since I2P 0.9.15.
func NewKeyCertificate ¶
func NewKeyCertificate(bytes []byte) (key_certificate *KeyCertificate, remainder []byte, err error)
NewKeyCertificate creates a new *KeyCertificate from []byte using ReadCertificate. The remaining bytes after the specified length are also returned. Returns a list of errors that occurred during parsing.
func NewKeyCertificateWithTypes ¶ added in v0.0.6
func NewKeyCertificateWithTypes(signingType, cryptoType int) (*KeyCertificate, error)
NewKeyCertificateWithTypes creates a key certificate with the specified signing and crypto key types. This is the recommended way to create key certificates.
Parameters:
- signingType: The signing key type (e.g., KEYCERT_SIGN_ED25519)
- cryptoType: The crypto key type (e.g., KEYCERT_CRYPTO_X25519)
Returns:
- *KeyCertificate: The newly created key certificate
- error: Any error encountered during creation
Example:
keyCert, err := key_certificate.NewKeyCertificateWithTypes(
key_certificate.KEYCERT_SIGN_ED25519,
key_certificate.KEYCERT_CRYPTO_X25519,
)
func NewRedDSAX25519KeyCertificate ¶ added in v0.0.6
func NewRedDSAX25519KeyCertificate() (*KeyCertificate, error)
NewRedDSAX25519KeyCertificate creates a key certificate with RedDSA-Ed25519 signing and X25519 crypto keys. RedDSA (randomized EdDSA) provides enhanced security over standard Ed25519.
Supported for Destinations and EncryptedLeaseSets only, not Router Identities. Added in I2P specification 0.9.39.
func (KeyCertificate) ConstructPublicKey ¶
func (keyCertificate KeyCertificate) ConstructPublicKey(data []byte) (public_key types.ReceivingPublicKey, err error)
ConstructPublicKey returns a publicKey constructed using any excess data that may be stored in the KeyCertificate. The data parameter must be the full 256-byte public key field from the KeysAndCert structure. Per the I2P spec, the crypto public key is start-aligned (bytes 0..keySize-1) within the field. Returns any errors encountered while parsing.
func (KeyCertificate) ConstructSigningPublicKey ¶
func (keyCertificate KeyCertificate) ConstructSigningPublicKey(data []byte) (signing_public_key types.SigningPublicKey, err error)
ConstructSigningPublicKey returns a SigningPublicKey constructed using any excess data that may be stored in the KeyCertificate. Returns any errors encountered while parsing.
The data parameter must be the combined byte slice used to reconstruct the signing key:
- For types where the signing key fits within KEYCERT_SPK_SIZE (128 bytes) – e.g. Ed25519, DSA, P256, P384 – data is the full 128-byte SPK field from the KeysAndCert structure.
- For types whose signing key exceeds KEYCERT_SPK_SIZE – P521 (132 bytes), RSA-2048 (256 bytes), RSA-3072 (384 bytes), RSA-4096 (512 bytes) – the caller MUST pre-concatenate the excess bytes from the key certificate payload (stored immediately after the 4-byte type fields) FOLLOWED BY the 128-byte inline SPK field from KeysAndCert. Per the I2P spec, signing keys are end-aligned in the SPK field: the inline 128 bytes contain the LAST 128 bytes of the key, while the excess bytes in the certificate payload contain the FIRST (keySize − 128) bytes. Correct order: excess || inline. Failure to include the excess bytes or using the wrong order will result in a truncated / incorrect key.
func (KeyCertificate) CryptoPublicKeySize ¶
func (keyCertificate KeyCertificate) CryptoPublicKeySize() (int, error)
CryptoPublicKeySize returns the size of a public key for the certificate's crypto type
func (KeyCertificate) CryptoSize ¶
func (keyCertificate KeyCertificate) CryptoSize() (size int)
CryptoSize return the size of a Public Key corresponding to the Key Certificate's publicKey type.
func (KeyCertificate) CryptoSizeOrError ¶ added in v0.1.5
func (keyCertificate KeyCertificate) CryptoSizeOrError() (int, error)
CryptoSizeOrError returns the crypto public key size for the certificate's public key type, or an error if the type is unknown. Prefer this over CryptoSize when callers need to distinguish "unknown type" from a hypothetical 0-byte key.
func (KeyCertificate) Data ¶
func (keyCertificate KeyCertificate) Data() ([]byte, error)
Data returns the certificate payload bytes (the key type fields and any excess key data), NOT the full serialized certificate. For the full certificate bytes (type+length+payload), use Certificate.RawBytes() instead.
func (KeyCertificate) PublicKeyType ¶
func (keyCertificate KeyCertificate) PublicKeyType() (pubkey_type int)
PublicKeyType returns the publicKey type as a Go integer.
func (KeyCertificate) SignatureSize ¶
func (keyCertificate KeyCertificate) SignatureSize() (size int)
SignatureSize return the size of a Signature corresponding to the Key Certificate's signingPublicKey type. This returns the actual signature size (not the signing public key size). For signing public key sizes, use SigningPublicKeySize(). Returns 0 for unknown signing types – callers must treat 0 as an error condition.
func (KeyCertificate) SignatureSizeOrError ¶ added in v0.1.5
func (keyCertificate KeyCertificate) SignatureSizeOrError() (int, error)
SignatureSizeOrError returns the signature size for the certificate's signing key type, or an error if the type is unknown. Prefer this over SignatureSize when callers need to distinguish \"unknown type\" from a hypothetical 0-byte signature.
func (KeyCertificate) SigningPublicKeySize ¶
func (keyCertificate KeyCertificate) SigningPublicKeySize() int
SigningPublicKeySize returns the size of a signing public key for the certificate's signing type. Returns 0 for unknown signing types – callers must treat 0 as an error condition because no valid signing key has size 0. For an error-returning variant use SigningPublicKeySizeOrError.
func (KeyCertificate) SigningPublicKeySizeOrError ¶ added in v0.1.5
func (keyCertificate KeyCertificate) SigningPublicKeySizeOrError() (int, error)
SigningPublicKeySizeOrError returns the size of a signing public key for the certificate's signing type, or an error if the type is unknown. Prefer this over SigningPublicKeySize when callers need to distinguish "unknown type" from a hypothetical 0-byte key.
func (KeyCertificate) SigningPublicKeyType ¶
func (keyCertificate KeyCertificate) SigningPublicKeyType() (signing_pubkey_type int)
SigningPublicKeyType returns the signingPublicKey type as a Go integer.
type KeySizeInfo ¶ added in v0.0.6
type KeySizeInfo struct {
// SignatureSize is the size of signatures produced by this signing key type
SignatureSize int
// SigningPublicKeySize is the size of the signing public key
SigningPublicKeySize int
// SigningPrivateKeySize is the size of the signing private key
SigningPrivateKeySize int
// CryptoPublicKeySize is the size of the encryption public key
CryptoPublicKeySize int
// CryptoPrivateKeySize is the size of the encryption private key
CryptoPrivateKeySize int
}
KeySizeInfo contains size information for cryptographic keys. All sizes are in bytes.
func GetKeySizes ¶ added in v0.0.6
func GetKeySizes(signingType, cryptoType int) (KeySizeInfo, error)
GetKeySizes returns size information for the given signing and crypto key types without requiring object creation.
This function is useful for calculating padding sizes, buffer allocations, and validating data lengths before constructing full key certificates.
Parameters:
- signingType: The signing key type (e.g., KEYCERT_SIGN_ED25519)
- cryptoType: The crypto key type (e.g., KEYCERT_CRYPTO_X25519)
Returns:
- KeySizeInfo: Combined size information for both key types
- error: Error if either key type is unknown
Example:
sizes, err := key_certificate.GetKeySizes(
key_certificate.KEYCERT_SIGN_ED25519,
key_certificate.KEYCERT_CRYPTO_X25519,
)
if err != nil {
return err
}
paddingSize := keys_and_cert.KEYS_AND_CERT_DATA_SIZE -
(sizes.CryptoPublicKeySize + sizes.SigningPublicKeySize)