Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cloudflare/circl
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.3.3
Choose a base ref
...
head repository: cloudflare/circl
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.3.4
Choose a head ref
Loading
Showing with 4,039 additions and 760 deletions.
  1. +5 −5 .github/workflows/ci-actions.yml
  2. +1 −0 README.md
  3. +265 −0 abe/cpabe/tkn20/bench_test.go
  4. +2 −2 abe/cpabe/tkn20/example_test.go
  5. +1 −1 abe/cpabe/tkn20/internal/tkn/bk.go
  6. +1 −1 abe/cpabe/tkn20/internal/tkn/matrixGT_test.go
  7. +1 −1 abe/cpabe/tkn20/internal/tkn/tk.go
  8. +1 −1 abe/cpabe/tkn20/tkn20_test.go
  9. +892 −0 bbs/bbs.go
  10. +289 −0 bbs/bbs_test.go
  11. +2 −0 bbs/doc.go
  12. +0 −342 blindsign/blindrsa/blindrsa.go
  13. +323 −0 blindsign/blindrsa/brsa.go
  14. +155 −79 blindsign/blindrsa/{blindrsa_test.go → brsa_test.go}
  15. +145 −0 blindsign/blindrsa/internal/common/common.go
  16. +103 −1 blindsign/blindrsa/{ → internal/common}/pss.go
  17. +14 −57 blindsign/blindrsa/{ → internal/common}/rsa.go
  18. +57 −0 blindsign/blindrsa/internal/keys/big_keys.go
  19. +334 −0 blindsign/blindrsa/partiallyblindrsa/pbrsa.go
  20. +356 −0 blindsign/blindrsa/partiallyblindrsa/pbrsa_test.go
  21. +0 −42 blindsign/blindsign.go
  22. +2 −0 blindsign/doc.go
  23. +1 −1 dh/csidh/csidh.go
  24. +2 −2 dh/csidh/curve.go
  25. +3 −3 dh/sidh/internal/p434/core.go
  26. +1 −1 dh/sidh/internal/p434/curve.go
  27. +3 −3 dh/sidh/internal/p503/core.go
  28. +1 −1 dh/sidh/internal/p503/curve.go
  29. +3 −3 dh/sidh/internal/p751/core.go
  30. +1 −1 dh/sidh/internal/p751/curve.go
  31. +3 −3 dh/sidh/internal/templates/core.gotemp
  32. +1 −1 dh/sidh/internal/templates/curve.gotemp
  33. +4 −4 dh/sidh/sidh_test.go
  34. +6 −6 dh/sidh/sike_test.go
  35. +1 −1 ecc/bls12381/doc.go
  36. +1 −1 ecc/bls12381/ff/doc.go
  37. +1 −1 ecc/bls12381/g1Isog.go
  38. +1 −1 ecc/bls12381/g2Isog.go
  39. +1 −1 ecc/goldilocks/twist.go
  40. +0 −2 go.sum
  41. +1 −1 group/group.go
  42. +1 −1 group/ristretto255.go
  43. +1 −1 hpke/hybridkem.go
  44. +1 −1 hpke/shortkem.go
  45. +1 −1 hpke/xkem.go
  46. +10 −2 internal/sha3/keccakf.go
  47. +8 −3 internal/sha3/sha3.go
  48. +37 −1 internal/sha3/sha3_test.go
  49. +40 −0 internal/sha3/shake.go
  50. +1 −1 kem/kem.go
  51. +34 −0 math/primes.go
  52. +46 −0 math/primes_test.go
  53. +1 −1 oprf/oprf.go
  54. +1 −1 pke/kyber/internal/common/amd64.go
  55. +5 −5 pke/kyber/internal/common/amd64.s
  56. +9 −3 pke/kyber/internal/common/asm/go.mod
  57. +33 −17 pke/kyber/internal/common/asm/go.sum
  58. +2 −2 pke/kyber/internal/common/asm/src.go
  59. +1 −1 pke/kyber/internal/common/field.go
  60. +1 −1 pke/kyber/internal/common/ntt.go
  61. +1 −1 pke/kyber/internal/common/poly.go
  62. +1 −1 pke/kyber/internal/common/sample.go
  63. +0 −1 pke/kyber/internal/common/stubs_amd64.go
  64. +1 −1 pke/kyber/kyber.go
  65. +1 −1 pke/kyber/kyber1024/internal/mat.go
  66. +1 −1 pke/kyber/kyber512/internal/mat.go
  67. +1 −1 pke/kyber/kyber768/internal/mat.go
  68. +1 −1 sign/dilithium/internal/common/amd64.s
  69. +9 −3 sign/dilithium/internal/common/asm/go.mod
  70. +27 −41 sign/dilithium/internal/common/asm/go.sum
  71. +0 −1 sign/dilithium/internal/common/stubs_amd64.go
  72. +3 −3 sign/dilithium/mode2/internal/sample.go
  73. +3 −3 sign/dilithium/mode2aes/internal/sample.go
  74. +3 −3 sign/dilithium/mode3/internal/sample.go
  75. +3 −3 sign/dilithium/mode3aes/internal/sample.go
  76. +3 −3 sign/dilithium/mode5/internal/sample.go
  77. +3 −3 sign/dilithium/mode5aes/internal/sample.go
  78. +1 −1 sign/ed25519/ed25519.go
  79. +1 −1 simd/keccakf1600/example_test.go
  80. +28 −14 simd/keccakf1600/f1600x.go
  81. +3 −3 simd/keccakf1600/f1600x2_arm64.go
  82. +8 −2 simd/keccakf1600/f1600x2_arm64.s
  83. +2 −2 simd/keccakf1600/f1600x4_amd64.go
  84. +11 −6 simd/keccakf1600/f1600x4_amd64.s
  85. +1 −2 simd/keccakf1600/f1600x4stubs_amd64.go
  86. +60 −25 simd/keccakf1600/f1600x_test.go
  87. +2 −2 simd/keccakf1600/fallback.go
  88. +4 −1 simd/keccakf1600/internal/asm/go.mod
  89. +43 −16 simd/keccakf1600/internal/asm/go.sum
  90. +8 −1 simd/keccakf1600/internal/asm/src.go
  91. +1 −0 tss/doc.go
  92. +2 −2 tss/rsa/keyshare.go
  93. +60 −0 tss/rsa/rsa_threshold.go
  94. +11 −0 tss/rsa/rsa_threshold_test.go
  95. +400 −0 xof/k12/k12.go
  96. +96 −0 xof/k12/k12_test.go
  97. +13 −0 xof/xof.go
  98. +6 −0 xof/xof_test.go
10 changes: 5 additions & 5 deletions .github/workflows/ci-actions.yml
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
GOVER: ['1.20', '1.19']
GOVER: ['1.21.1', '1.20.8']
steps:
- name: Setup Go-${{ matrix.GOVER }}
uses: actions/setup-go@v3
@@ -47,7 +47,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
CFG: [[arm64, arm64v8, '1.20']]
CFG: [[arm64, arm64v8, '1.21.1']]
steps:
- uses: actions/checkout@v3
- name: Enabling Docker Experimental
@@ -72,7 +72,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.20'
go-version: '1.21.1'
- name: Build as Static
run: make circl_static
- name: Build as Plugin
@@ -88,7 +88,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.20'
go-version: '1.21.1'
- name: Produce Coverage
run: go test -coverprofile=./coverage.txt ./...
- name: Upload Codecov
@@ -108,7 +108,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.20'
go-version: '1.21.1'
- name: Building
run: go build -v ./...
- name: Testing
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -74,6 +74,7 @@ go get -u github.com/cloudflare/circl
#### XOF: eXtendable Output Functions
- [FIPS 202](https://doi.org/10.6028/NIST.FIPS.202): SHAKE128 and SHAKE256
- [BLAKE2X](https://www.blake2.net/blake2x.pdf): BLAKE2XB and BLAKE2XS
- [KangarooTwelve](https://keccak.team/kangarootwelve.html): KangarooTwelve

#### Zero-knowledge Proofs
- [Schnorr](./zk/dl): Prove knowledge of the Discrete Logarithm.
265 changes: 265 additions & 0 deletions abe/cpabe/tkn20/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
package tkn20

import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"fmt"
"strconv"
"strings"
"testing"

"golang.org/x/crypto/nacl/box"
)

type abeTestCase struct {
desc string
attrs Attributes
policy Policy
msk SystemSecretKey
pk PublicKey
}

var testCases []abeTestCase

var (
msg = []byte("drink your ovaltine now")
longMsg = []byte(strings.Repeat("a", 10000))
)

func generateAttrs() Attributes {
benchableAttrs := make(map[string]string, 50)
for i := 0; i < 50; i++ {
benchableAttrs["k"+strconv.Itoa(i)] = "v" + strconv.Itoa(i)
}
attrs := Attributes{}
attrs.FromMap(benchableAttrs)
return attrs
}

func generatePolicy() string {
var policyBuilder strings.Builder
for i := 0; i < 50; i++ {
policyBuilder.WriteString("k")
policyBuilder.WriteString(strconv.Itoa(i))
policyBuilder.WriteString(":v")
policyBuilder.WriteString(strconv.Itoa(i))
if i != 49 {
if i%2 == 0 {
policyBuilder.WriteString(" and ")
} else {
policyBuilder.WriteString(" or ")
}
}
}
return policyBuilder.String()
}

func init() {
smallPolicy := Policy{}
_ = smallPolicy.FromString("(k1:v1 or k1:v2) and not k2:v3")
smallAttrs := Attributes{}
smallAttrs.FromMap(map[string]string{"k1": "v2", "k2": "v4"})
longPolicy := Policy{}
_ = longPolicy.FromString(generatePolicy())
testCases = []abeTestCase{
{
desc: "smallPolicy/Attrs",
attrs: smallAttrs,
policy: smallPolicy,
},
{
desc: "longPolicy/Attrs",
attrs: generateAttrs(),
policy: longPolicy,
},
}
var err error
for i := range testCases {
testCases[i].pk, testCases[i].msk, err = Setup(rand.Reader)
if err != nil {
panic(err)
}
}
}

func BenchmarkTKN20KeyGen(b *testing.B) {
for _, tc := range testCases {
b.Run(fmt.Sprintf("keygen:%s", tc.desc), func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := tc.msk.KeyGen(rand.Reader, tc.attrs)
if err != nil {
b.Fatal(err)
}
}
})
}
}

func BenchmarkRSAKeyGen(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
b.Fatal(err)
}
}
}

func BenchmarkX25519KeyGen(b *testing.B) {
for i := 0; i < b.N; i++ {
_, _, err := box.GenerateKey(rand.Reader)
if err != nil {
b.Fatal(err)
}
}
}

func BenchmarkTKN20Encrypt(b *testing.B) {
for _, tc := range testCases {
b.Run(fmt.Sprintf("encrypt:%s", tc.desc), func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := tc.pk.Encrypt(rand.Reader, tc.policy, msg)
if err != nil {
b.Fatal(err)
}
}
})
}
}

func BenchmarkRSAEncrypt(b *testing.B) {
privKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
b.Fatal(err)
}
pubKey := privKey.PublicKey
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := rsa.EncryptPKCS1v15(rand.Reader, &pubKey, msg)
if err != nil {
b.Fatal(err)
}
}
}

func BenchmarkX25519Encrypt(b *testing.B) {
pubKey, _, err := box.GenerateKey(rand.Reader)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := box.SealAnonymous(nil, msg, pubKey, rand.Reader)
if err != nil {
b.Fatal(err)
}
}
}

func BenchmarkTKN20Decrypt(b *testing.B) {
for _, tc := range testCases {
b.Run(fmt.Sprintf("decrypt:%s", tc.desc), func(b *testing.B) {
userKey, err := tc.msk.KeyGen(rand.Reader, tc.attrs)
if err != nil {
b.Fatal(err)
}
ciphertext, err := tc.pk.Encrypt(rand.Reader, tc.policy, msg)
if err != nil {
b.Fatal(err)
}
keyBytes, _ := userKey.MarshalBinary()
pubKeyBytes, _ := tc.pk.MarshalBinary()
// longCt is only benchmarked to measure size overhead
longCt, err := tc.pk.Encrypt(rand.Reader, tc.policy, longMsg)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = userKey.Decrypt(ciphertext)
if err != nil {
b.Fatal(err)
}
}
b.ReportMetric(float64(len(pubKeyBytes)), "public_key_size")
b.ReportMetric(float64(len(keyBytes)), "attribute_secret_key_size")
b.ReportMetric(float64(len(ciphertext)-len(msg)), "ciphertext_bytes_overhead_32b_msg")
b.ReportMetric(float64(len(longCt)-len(longMsg)), "ciphertext_bytes_overhead_10kb_msg")
})
}
}

func BenchmarkRSADecrypt(b *testing.B) {
privKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
b.Fatal(err)
}
pubKey := privKey.PublicKey
ct, err := rsa.EncryptPKCS1v15(rand.Reader, &pubKey, msg)
if err != nil {
b.Fatal(err)
}
// longCt is only benchmarked to measure size overhead
longCt, err := rsaEncrypt(longMsg, &privKey.PublicKey)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := rsa.DecryptPKCS1v15(rand.Reader, privKey, ct)
if err != nil {
b.Fatal(err)
}
}
b.ReportMetric(float64(privKey.PublicKey.Size()), "public_key_size")
b.ReportMetric(float64(len(x509.MarshalPKCS1PrivateKey(privKey))), "secret_key_size")
b.ReportMetric(float64(len(ct)-len(msg)), "ciphertext_bytes_overhead")
b.ReportMetric(float64(len(longCt)-len(longMsg)), "ciphertext_bytes_overhead_10kb_msg")
}

func BenchmarkX25519Decrypt(b *testing.B) {
pubKey, privKey, err := box.GenerateKey(rand.Reader)
if err != nil {
b.Fatal(err)
}
ct, err := box.SealAnonymous(nil, msg, pubKey, rand.Reader)
if err != nil {
b.Fatal(err)
}
// longCt is only benchmarked to measure size overhead
longCt, err := box.SealAnonymous(nil, longMsg, pubKey, rand.Reader)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, ok := box.OpenAnonymous(nil, ct, pubKey, privKey)
if !ok {
b.Fatal(err)
}
}
b.ReportMetric(float64(len(pubKey)), "public_key_size")
b.ReportMetric(float64(len(privKey)), "secret_key_size")
b.ReportMetric(float64(len(ct)-len(msg)), "ciphertext_bytes_overhead_32b_msg")
b.ReportMetric(float64(len(longCt)-len(longMsg)), "ciphertext_bytes_overhead_10kb_msg")
}

func rsaEncrypt(data []byte, pubKey *rsa.PublicKey) ([]byte, error) {
chunkSize := 245 // Max chunk size for 2048 bit key with PKCS1v15 padding
var ct []byte
for len(data) > 0 {
if len(data) < chunkSize {
chunkSize = len(data)
}
chunk := data[:chunkSize]
data = data[chunkSize:]
encryptedChunk, err := rsa.EncryptPKCS1v15(rand.Reader, pubKey, chunk)
if err != nil {
return nil, err
}
ct = append(ct, encryptedChunk...)
}
return ct, nil
}
4 changes: 2 additions & 2 deletions abe/cpabe/tkn20/example_test.go
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ func checkPolicy(in map[string][]string) bool {

func Example() {
policyStr := `(occupation: doctor) and (country: US)`
invalidPolicyStr := `(ocupation: doctor) and (country: pacific)`
invalidPolicyStr := `(title: doctor) and (country: pacific)`
msgStr := `must have the precious 🎃`
wrongAttrsMap := map[string]string{"occupation": "doctor", "country": "croatia"}
rightAttrsMap := map[string]string{"occupation": "doctor", "country": "US", "age": "16"}
@@ -124,7 +124,7 @@ func Example() {
log.Fatalf("decryption using right attrs should have succeeded, plaintext: %s", pt)
}
if !bytes.Equal(pt, []byte(msgStr)) {
log.Fatalf("recoverd plaintext: %s is not equal to original msg: %s", pt, msgStr)
log.Fatalf("recovered plaintext: %s is not equal to original msg: %s", pt, msgStr)
}
fmt.Println("Successfully recovered plaintext")
// Output: (occupation:doctor and country:US)
2 changes: 1 addition & 1 deletion abe/cpabe/tkn20/internal/tkn/bk.go
Original file line number Diff line number Diff line change
@@ -243,7 +243,7 @@ func (p *Policy) ExtractFromCiphertext(ct []byte) error {
}
macData, _, err := removeLenPrefixed(rest)
if err != nil {
return fmt.Errorf("invalid ciphetext")
return fmt.Errorf("invalid ciphertext")
}
C1, _, err := removeLenPrefixed(macData)
if err != nil {
2 changes: 1 addition & 1 deletion abe/cpabe/tkn20/internal/tkn/matrixGT_test.go
Original file line number Diff line number Diff line change
@@ -157,7 +157,7 @@ func TestExpGTLinearity(t *testing.T) {
absum.add(aexp, bexp)
abexp.exp(ab)
if !abexp.Equal(absum) {
t.Fatal("linearity of exponentation broken")
t.Fatal("linearity of exponentiation broken")
}
}

2 changes: 1 addition & 1 deletion abe/cpabe/tkn20/internal/tkn/tk.go
Original file line number Diff line number Diff line change
@@ -352,7 +352,7 @@ func (hdr *ciphertextHeader) marshalBinary() ([]byte, error) {
ret = appendLenPrefixed(ret, c1Bytes)

// Now we need to indicate how long c2, c3, c3neg are.
// Each array will be the same size (or nil), so with more work we can specalize
// Each array will be the same size (or nil), so with more work we can specialize
// but for now we will ignore that.

c2Len := len(hdr.c2)
2 changes: 1 addition & 1 deletion abe/cpabe/tkn20/tkn20_test.go
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ func TestEndToEndEncryption(t *testing.T) {
t.Fatalf("extracted policy doesn't match original")
}
if sat != npol2.Satisfaction(attrs) {
t.Fatalf("round triped policy doesn't match original")
t.Fatalf("round tripped policy doesn't match original")
}
ctSat := attrs.CouldDecrypt(ct)
pt, err := sk.Decrypt(ct)
Loading