arnaucube
arnaucube/cryptofunPublic Self-hosted repository
cryptofun/rsa/README.md
rsa/README.mdRaw
 1## RSA cryptosystem & Blind signature & Homomorphic Multiplication
 2- https://en.wikipedia.org/wiki/RSA_(cryptosystem)#
 3- https://en.wikipedia.org/wiki/Blind_signature
 4- https://en.wikipedia.org/wiki/Homomorphic_encryption
 5
 6- [x] GenerateKeyPair
 7- [x] Encrypt
 8- [x] Decrypt
 9- [x] Blind
10- [x] Blind Signature
11- [x] Unblind Signature
12- [x] Verify Signature
13- [x] Homomorphic Multiplication
14
15
16#### Usage
17- Key generation, Encryption, Decryption
18```go
19// generate key pair
20key, err := GenerateKeyPair()
21if err!=nil {
22	fmt.Println(err)
23}
24mBytes := []byte("Hi")
25m := new(big.Int).SetBytes(mBytes)
26
27// encrypt message
28c := Encrypt(m, key.PubK)
29
30// decrypt ciphertext
31d := Decrypt(c, key.PrivK)
32if m == d {
33	fmt.Println("correctly decrypted")
34}
35```
36
37- Blind signatures
38```go
39// key generation [Alice]
40key, err := GenerateKeyPair()
41if err!=nil {
42	fmt.Println(err)
43}
44
45// create new message [Alice]
46mBytes := []byte("Hi")
47m := new(big.Int).SetBytes(mBytes)
48
49// define r value [Alice]
50rVal := big.NewInt(int64(101))
51
52// blind message [Alice]
53mBlinded := Blind(m, rVal, key.PubK)
54
55// Blind Sign the blinded message [Bob]
56sigma := BlindSign(mBlinded, key.PrivK)
57
58// unblind the blinded signed message, and get the signature of the message [Alice]
59mSigned := Unblind(sigma, rVal, key.PubK)
60
61// verify the signature [Alice/Bob/Trudy]
62verified := Verify(m, mSigned, key.PubK)
63if !verified {
64	fmt.Println("signature could not be verified")
65}
66```
67
68- Homomorphic Multiplication
69```go
70// key generation [Alice]
71key, err := GenerateKeyPair()
72if err!=nil {
73	fmt.Println(err)
74}
75
76// define values [Alice]
77n1 := big.NewInt(int64(11))
78n2 := big.NewInt(int64(15))
79
80// encrypt the values [Alice]
81c1 := Encrypt(n1, key.PubK)
82c2 := Encrypt(n2, key.PubK)
83
84// compute homomorphic multiplication with the encrypted values [Bob]
85c3c4 := HomomorphicMul(c1, c2, key.PubK)
86
87// decrypt the result [Alice]
88d := Decrypt(c3c4, key.PrivK)
89
90// check that the result is the expected
91if !bytes.Equal(new(big.Int).Mul(n1, n2).Bytes(), d.Bytes()) {
92	fmt.Println("decrypted result not equal to expected result")
93}
94```