mirror of
https://github.com/QuilibriumNetwork/ceremonyclient.git
synced 2026-02-21 10:27:26 +08:00
* v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete * 2.1.0 main node rollup
40 lines
706 B
Go
40 lines
706 B
Go
// -*- go -*-
|
|
//
|
|
|
|
// RSA encryption with Montgomery modular multiplication.
|
|
//
|
|
// ./garbled -e -v -i 0x321af130 examples/montgomery.qcl
|
|
// ./garbled -v -i 0x6d7472,9,0xd60b2b09,0x10001 examples/montgomery.qcl
|
|
package main
|
|
|
|
import (
|
|
"math"
|
|
)
|
|
|
|
type Size = uint64
|
|
|
|
type Garbler struct {
|
|
msg Size
|
|
privShare Size
|
|
pubN Size
|
|
pubE Size
|
|
}
|
|
|
|
func main(g Garbler, privShare Size) (uint, uint) {
|
|
|
|
priv := g.privShare + privShare
|
|
|
|
cipher := Encrypt(g.msg, g.pubE, g.pubN)
|
|
plain := Decrypt(cipher, priv, g.pubN)
|
|
|
|
return cipher, plain
|
|
}
|
|
|
|
func Encrypt(msg, e, n uint) uint {
|
|
return math.ExpMontgomery(msg, e, n)
|
|
}
|
|
|
|
func Decrypt(cipher, d, n uint) uint {
|
|
return math.ExpMontgomery(cipher, d, n)
|
|
}
|