Documentation ¶
Overview ¶
Package rsa pem.go imports and exports to pem files.
Package rsa includes wrappers to sign and verify the signatures of messages with the PKCS#1 RSASSA-PSS signature algorithm:
https://tools.ietf.org/html/rfc3447#page-29
We use this because of the "tighter" security proof and regression to full domain hashing in cases where good RNG is unavailable.
The primary reason for wrapping is to interface with the large Int api used by cMix.
Index ¶
- Constants
- Variables
- func CreatePrivateKeyPem(k *PrivateKey) []byte
- func CreatePublicKeyPem(k *PublicKey) []byte
- func IsValidSignature(pubKey *PublicKey, signature []byte) bool
- func Sign(rand io.Reader, priv *PrivateKey, hash crypto.Hash, hashed []byte, ...) ([]byte, error)
- func Verify(pub *PublicKey, hash crypto.Hash, hashed []byte, sig []byte, opts *Options) error
- type Options
- type PrivateKey
- func (p *PrivateKey) GetD() *large.Int
- func (p *PrivateKey) GetDp() *large.Int
- func (p *PrivateKey) GetDq() *large.Int
- func (p *PrivateKey) GetE() int
- func (p *PrivateKey) GetN() *large.Int
- func (p *PrivateKey) GetPrimes() []*large.Int
- func (p *PrivateKey) GetPublic() *PublicKey
- func (p *PrivateKey) Public() crypto.PublicKey
- type PublicKey
Constants ¶
const (
ELength = 4
)
Variables ¶
var DefaultRSABitLen = 4096
DefaultRSABitLen is the RSA key length used in the system, in bits.
Functions ¶
func CreatePrivateKeyPem ¶
func CreatePrivateKeyPem(k *PrivateKey) []byte
CreatePrivateKeyPem creates a PEM file from a private key
func CreatePublicKeyPem ¶
CreatePrivateKeyPem creates a PEM file from a private key
func IsValidSignature ¶
IsValidSignature approximates whether the signature looks valid by comparing the length of the signature to the length of the public key
func Sign ¶
func Sign(rand io.Reader, priv *PrivateKey, hash crypto.Hash, hashed []byte, opts *Options) ([]byte, error)
Sign uses RSASSA-PSS to calculate the signature of hashed. Note that hashed must be the result of hashing the input message using the given hash function. The opts argument may be nil, in which case the default cMix hash and salt length == size of the hash are used.
func Verify ¶
Verify verifies a PSS signature. hashed is the result of hashing the input message using the given hash function and sig is the signature. A valid signature is indicated by returning a nil error. The opts argument may be nil, in which case the default cMix hash and salt length == size of the hash are used.
Types ¶
type Options ¶
type Options struct {
gorsa.PSSOptions
}
Options is a direct wrapper for PSSOptions
func NewDefaultOptions ¶
func NewDefaultOptions() *Options
NewDefaultOptions returns signing options that set the salt length equal to the length of the hash and uses the default cMix Hash algorithm.
type PrivateKey ¶
type PrivateKey struct {
gorsa.PrivateKey
}
PrivateKey is identical to the rsa private key, with additional big int accessors functions.
func GenerateKey ¶
func GenerateKey(random io.Reader, bits int) (*PrivateKey, error)
GenerateKey generates an RSA keypair of the given bit size using the random source random (for example, crypto/rand.Reader).
func LoadPrivateKeyFromPem ¶
func LoadPrivateKeyFromPem(pemBytes []byte) (*PrivateKey, error)
LoadPrivateKeyFromPem decodes and produces an RSA PrivateKey in PKCS#1 PEM format Usage:
pem := ioutil.ReadFile("pemfile.pem") privateKey, err := LoadPrivateKeyFromPem(pem)
func (*PrivateKey) GetD ¶
func (p *PrivateKey) GetD() *large.Int
GetD returns the private exponent of the RSA Private Key as a large.Int
func (*PrivateKey) GetDp ¶
func (p *PrivateKey) GetDp() *large.Int
GetDp returns D mod (P - 1), or nil if unavailable
func (*PrivateKey) GetDq ¶
func (p *PrivateKey) GetDq() *large.Int
GetDq returns D mod (Q - 1), or nil if unavailable
func (*PrivateKey) GetN ¶
func (p *PrivateKey) GetN() *large.Int
GetN returns the RSA Public Key modulus
func (*PrivateKey) GetPrimes ¶
func (p *PrivateKey) GetPrimes() []*large.Int
GetPrimes returns the prime factors of N, which has >= 2 elements
func (*PrivateKey) GetPublic ¶
func (p *PrivateKey) GetPublic() *PublicKey
GetPublic returns the public key in *rsa.PublicKey format.
func (*PrivateKey) Public ¶
func (p *PrivateKey) Public() crypto.PublicKey
Public returns the public key corresponding to priv.
type PublicKey ¶
PublicKey is identical to the rsa public key, with additonal big int access functions.
func LoadPublicKeyFromPem ¶
LoadPublicKeyFromPem decodes and produces an RSA PublicKey in PKCS#1 PEM format
func (*PublicKey) Bytes ¶
Bytes returns the PublicKey as a byte slice. The first 4 bytes are the exponent (E) as a 4 byte big endian integer, followed by the modulus (N) as a big.Int in Bytes format. We chose the 32 bit integer for E because it should be big enough.