github.com/mad-day/Yawning-crypto@v0.0.0-20190711051033-5a5f8cca32ec/bcns/rlwe_kex.go (about) 1 // 2 // Ring LWE Key Exchange 3 // 4 // To the extent possible under law, Yawning Angel waived all copyright 5 // and related or neighboring rights to bcns, using the Creative 6 // Commons "CC0" public domain dedication. See LICENSE or 7 // <http://creativecommons.org/publicdomain/zero/1.0/> for full details. 8 9 package bcns 10 11 import ( 12 "io" 13 ) 14 15 // Generate keypair for RLWE KEX 16 // - input: parameters: a 17 // - output: private key s, public key b 18 func kexGenerateKeypair(r io.Reader, a *[1024]uint32, s *[1024]uint32, b *[1024]uint32) error { 19 var e [1024]uint32 20 var fft fftCtx 21 22 rand, err := newRandCtx(r) 23 if err != nil { 24 return err 25 } 26 27 sample(s, rand) 28 sample(&e, rand) 29 keyGen(b, a, s, &e, &fft) 30 // Scrub e, fft, rand? 31 return nil 32 } 33 34 // Alice's shared key computation for RLWE KEX 35 // - input: Bob's public key b, Alice's private key s, reconciliation data c 36 // - output: shared secret k 37 func kexComputeKeyAlice(b, s *[1024]uint32, c *[16]uint64, k *[16]uint64) { 38 var w [1024]uint32 39 var fft fftCtx 40 41 fft.multiply(&w, b, s) 42 rec(k, &w, c) 43 // Scrub w, fft? 44 } 45 46 // Bob's shared key computation for RLWE KEX 47 // - input: Alice's public key b, Bob's private key s 48 // - output: reconciliation data c, shared secret k 49 func kexComputeKeyBob(r io.Reader, b, s *[1024]uint32, c, k *[16]uint64) error { 50 var v [1024]uint32 51 var eprimeprime [1024]uint32 52 var fft fftCtx 53 54 rand, err := newRandCtx(r) 55 if err != nil { 56 return err 57 } 58 59 sample(&eprimeprime, rand) 60 keyGen(&v, b, s, &eprimeprime, &fft) 61 crossround2(c, &v, rand) 62 round2(k, &v) 63 // Scrub v, eprimeprime, fft, rand? 64 return nil 65 }