github.com/cloudflare/circl@v1.5.0/blindsign/blindrsa/internal/keys/big_keys.go (about) 1 package keys 2 3 import ( 4 "crypto/rsa" 5 "math/big" 6 ) 7 8 // BigPublicKey is the same as an rsa.PublicKey struct, except the public 9 // key is represented as a big integer as opposed to an int. For the partially 10 // blind scheme, this is required since the public key will typically be 11 // any value in the RSA group. 12 type BigPublicKey struct { 13 N *big.Int 14 E *big.Int 15 } 16 17 // Size returns the size of the public key. 18 func (pub *BigPublicKey) Size() int { 19 return (pub.N.BitLen() + 7) / 8 20 } 21 22 // Marshal encodes the public key exponent (e). 23 func (pub *BigPublicKey) Marshal() []byte { 24 buf := make([]byte, (pub.E.BitLen()+7)/8) 25 pub.E.FillBytes(buf) 26 return buf 27 } 28 29 // NewBigPublicKey creates a BigPublicKey from a rsa.PublicKey. 30 func NewBigPublicKey(pk *rsa.PublicKey) *BigPublicKey { 31 return &BigPublicKey{ 32 N: pk.N, 33 E: new(big.Int).SetInt64(int64(pk.E)), 34 } 35 } 36 37 // CustomPublicKey is similar to rsa.PrivateKey, containing information needed 38 // for a private key used in the partially blind signature protocol. 39 type BigPrivateKey struct { 40 Pk *BigPublicKey 41 D *big.Int 42 P *big.Int 43 Q *big.Int 44 } 45 46 // NewBigPrivateKey creates a BigPrivateKey from a rsa.PrivateKey. 47 func NewBigPrivateKey(sk *rsa.PrivateKey) *BigPrivateKey { 48 return &BigPrivateKey{ 49 Pk: &BigPublicKey{ 50 N: sk.N, 51 E: new(big.Int).SetInt64(int64(sk.PublicKey.E)), 52 }, 53 D: sk.D, 54 P: sk.Primes[0], 55 Q: sk.Primes[1], 56 } 57 }