本文整理汇总了Golang中golang.org/x/crypto/sha3.ShakeSum256函数的典型用法代码示例。如果您正苦于以下问题:Golang ShakeSum256函数的具体用法?Golang ShakeSum256怎么用?Golang ShakeSum256使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ShakeSum256函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ShareMask
func (s *Server) ShareMask(clientDH *ClientDH, serverPub *[]byte) error {
pub, shared := s.shareSecret(UnmarshalPoint(s.suite, clientDH.Public))
mask := MarshalPoint(shared)
for r := 0; r < MaxRounds; r++ {
if r == 0 {
sha3.ShakeSum256(s.maskss[r][clientDH.Id], mask)
} else {
sha3.ShakeSum256(s.maskss[r][clientDH.Id], s.maskss[r-1][clientDH.Id])
}
}
*serverPub = MarshalPoint(pub)
return nil
}
示例2: ShareSecret
func (s *Server) ShareSecret(clientDH *ClientDH, serverPub *[]byte) error {
pub, shared := s.shareSecret(UnmarshalPoint(s.suite, clientDH.Public))
secret := MarshalPoint(shared)
for r := 0; r < MaxRounds; r++ {
if r == 0 {
sha3.ShakeSum256(s.secretss[r][clientDH.Id], secret)
} else {
sha3.ShakeSum256(s.secretss[r][clientDH.Id], s.secretss[r-1][clientDH.Id])
}
}
//s.secretss[clientDH.Id] = make([]byte, len(MarshalPoint(shared)))
*serverPub = MarshalPoint(pub)
return nil
}
示例3: CheckCommitment
func CheckCommitment(commitment []byte, profile *proto.EncodedProfile) bool {
// The hash used here is modeled as a random oracle. This means that SHA3
// is fine but SHA2 is not (consider HMAC-SHA2 instead).
var commitmentCheck [64]byte
sha3.ShakeSum256(commitmentCheck[:], profile.Encoding) // the profile includes a nonce
return bytes.Equal(commitment[:], commitmentCheck[:])
}
示例4: ServeIzkp
// ServeIzkp returns an http.Handler that reads an input file and
// computes an interactive zero-knowledge proof-of-posession protocol.
// (This is completely unused, but isn't it cool?)
func ServeIzkp(fn string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadFile(fn)
if err != nil {
glog.Errorf("error reading file %s: %s", fn, err)
w.WriteHeader(http.StatusInternalServerError)
return
}
chalString := r.Header.Get("x-izkp-challenge")
if chalString == "" {
glog.Infof("didn't receive a challenge, so using a raw hash")
d := make([]byte, 64)
sha3.ShakeSum256(d, b)
w.Write(d)
return
}
challenge := []byte(chalString)
glog.Infof("received a challenge of length %d", len(challenge))
h := sha3.New512()
h.Write(challenge)
h.Write(b)
d := make([]byte, 64)
h.Sum(d)
w.Write(d)
return
}
}
示例5: GetResponse
/////////////////////////////////
//Download
////////////////////////////////
func (s *Server) GetResponse(cmask ClientMask, response *[]byte) error {
t := time.Now()
round := cmask.Round % MaxRounds
otherBlocks := make([][]byte, len(s.servers))
var wg sync.WaitGroup
for i := range otherBlocks {
if i == s.id {
otherBlocks[i] = make([]byte, BlockSize)
} else {
wg.Add(1)
go func(i int, cmask ClientMask) {
defer wg.Done()
curBlock := <-s.rounds[round].xorsChan[i][cmask.Id]
otherBlocks[i] = curBlock.Block
}(i, cmask)
}
}
wg.Wait()
<-s.rounds[round].blocksRdy[cmask.Id]
if cmask.Id == 0 && profile {
fmt.Println(cmask.Id, "down_network:", time.Since(t))
}
r := ComputeResponse(s.rounds[round].allBlocks, cmask.Mask, s.secretss[round][cmask.Id])
sha3.ShakeSum256(s.secretss[round][cmask.Id], s.secretss[round][cmask.Id])
Xor(Xors(otherBlocks), r)
*response = r
return nil
}
示例6: ShakeSum256
func ShakeSum256(password string) []byte {
buf := []byte(password)
// A hash needs to be 64 bytes long to have 256-bit collision resistance.
h := make([]byte, 64)
// Compute a 64-byte hash of buf and put it in h.
sha3.ShakeSum256(h, buf)
return h
}
示例7: NewSHA3Shake256
func NewSHA3Shake256(payloadLen int) func() {
input := NewRand(payloadLen)
var hash = make([]byte, 64)
return func() {
sha3.ShakeSum256(hash, input)
}
}
示例8: hashToCurve
func hashToCurve(m []byte) *edwards25519.ExtendedGroupElement {
// H(n) = (f(h(n))^8)
var hmb [32]byte
sha3.ShakeSum256(hmb[:], m)
var hm edwards25519.ExtendedGroupElement
extra25519.HashToEdwards(&hm, &hmb)
edwards25519.GeDouble(&hm, &hm)
edwards25519.GeDouble(&hm, &hm)
edwards25519.GeDouble(&hm, &hm)
return &hm
}
示例9: SelectChallenges
//TODO: need to select based on some pseudorandomness/gamma function?
// Note that these challenges are different from those of cryptocurrency
func (v *Verifier) SelectChallenges(seed []byte) []int64 {
challenges := make([]int64, v.beta*int(v.log2))
rands := make([]byte, v.beta*int(v.log2)*8)
sha3.ShakeSum256(rands, seed) //PRNG
for i := range challenges {
val, num := binary.Uvarint(rands[i*8 : (i+1)*8])
if num < 0 {
panic("Couldn't read PRNG")
}
challenges[i] = int64(val % uint64(v.size))
}
return challenges
}
示例10: DownloadSlot
func (c *Client) DownloadSlot(slot int, rnd uint64) []byte {
//all but one server uses the prng technique
round := rnd % MaxRounds
maskSize := len(c.maskss[round][0])
finalMask := make([]byte, maskSize)
SetBit(slot, true, finalMask)
mask := Xors(c.maskss[round])
Xor(c.maskss[round][c.myServer], mask)
Xor(finalMask, mask)
//one response includes all the secrets
response := make([]byte, BlockSize)
secretsXor := Xors(c.secretss[round])
cMask := ClientMask{Mask: mask, Id: c.id, Round: rnd}
t := time.Now()
err := c.rpcServers[c.myServer].Call("Server.GetResponse", cMask, &response)
if err != nil {
log.Fatal("Could not get response: ", err)
}
if c.id == 0 && profile {
fmt.Println(c.id, "down_network_total:", time.Since(t))
}
Xor(secretsXor, response)
for i := range c.secretss[round] {
sha3.ShakeSum256(c.secretss[round][i], c.secretss[round][i])
}
for i := range c.maskss[round] {
sha3.ShakeSum256(c.maskss[round][i], c.maskss[round][i])
}
return response
}
示例11: TestKeyserverRejectsMissignedUpdate
func TestKeyserverRejectsMissignedUpdate(t *testing.T) {
dieOnCtrlC()
kss, caPool, clks, _, ck, clientConfig, teardown := setupRealm(t, 3, 3)
defer teardown()
stop := stoppableSyncedClocks(clks)
defer close(stop)
waitForFirstEpoch(kss[0], clientConfig.Realms[0].VerificationPolicy.GetQuorum())
clientTLS, err := clientConfig.Realms[0].ClientTLS.Config(ck)
if err != nil {
t.Fatal(err)
}
_, alicePk, aliceEntry, aliceProfile := doRegister(t, kss[0], clientConfig, clientTLS, caPool, clks[0].Now(), alice, 0, proto.Profile{
Nonce: []byte("noncenoncenonceNONCE"),
Keys: map[string][]byte{"abc": []byte{1, 2, 3}, "xyz": []byte("TEST 456")},
})
var aliceKeyIdBytes [8]byte
sha3.ShakeSum256(aliceKeyIdBytes[:], proto.MustMarshal(alicePk))
aliceKeyid := binary.BigEndian.Uint64(aliceKeyIdBytes[:8])
_, badSk, _ := ed25519.GenerateKey(rand.Reader)
conn, err := grpc.Dial(kss[1].publicListen.Addr().String(), grpc.WithTransportCredentials(credentials.NewTLS(clientTLS)))
if err != nil {
t.Fatal(err)
}
updateC := proto.NewE2EKSPublicClient(conn)
_, err = updateC.Update(context.Background(), &proto.UpdateRequest{
Update: &proto.SignedEntryUpdate{
NewEntry: *aliceEntry,
Signatures: map[uint64][]byte{aliceKeyid: ed25519.Sign(badSk, aliceEntry.Encoding)[:]},
},
Profile: *aliceProfile,
LookupParameters: &proto.LookupRequest{
UserId: alice,
QuorumRequirement: clientConfig.Realms[0].VerificationPolicy.GetQuorum(),
},
})
if err == nil {
t.Fatalf("update went through even though it was signed with the wrong key")
}
}
示例12: VerifyLookup
func VerifyLookup(cfg *proto.Config, user string, pf *proto.LookupProof, now time.Time) (keys map[string][]byte, err error) {
if pf.UserId != "" && pf.UserId != user {
return nil, fmt.Errorf("VerifyLookup: proof specifies different user ID: %q != %q", pf.UserId, user)
}
realm, err := GetRealmByUser(cfg, user)
if err != nil {
return nil, err
}
if !vrf.Verify(realm.VRFPublic, []byte(user), pf.Index, pf.IndexProof) {
return nil, fmt.Errorf("VerifyLookup: VRF verification failed")
}
root, err := VerifyConsensus(realm, pf.Ratifications, now)
if err != nil {
return
}
verifiedEntryHash, err := reconstructTreeAndLookup(realm.TreeNonce, root, pf.Index, pf.TreeProof)
if err != nil {
return nil, fmt.Errorf("VerifyLookup: failed to verify the lookup: %v", err)
}
if verifiedEntryHash == nil {
if pf.Entry != nil {
return nil, fmt.Errorf("VerifyLookup: non-empty entry %x did not match verified lookup result <nil>", pf.Entry)
}
if pf.Profile != nil {
return nil, fmt.Errorf("VerifyLookup: non-empty profile %x did not match verified lookup result <nil>", pf.Profile)
}
return nil, nil
} else {
var entryHash [32]byte
sha3.ShakeSum256(entryHash[:], pf.Entry.Encoding)
if !bytes.Equal(entryHash[:], verifiedEntryHash) {
return nil, fmt.Errorf("VerifyLookup: entry hash %x did not match verified lookup result %x", entryHash, verifiedEntryHash)
}
if !CheckCommitment(pf.Entry.ProfileCommitment, pf.Profile) {
return nil, fmt.Errorf("VerifyLookup: profile does not match the hash in the entry")
}
return pf.Profile.Keys, nil
}
}
示例13: verifyUpdateEdge
func (ks *Keyserver) verifyUpdateEdge(req *proto.UpdateRequest) error {
if len(req.Update.NewEntry.Index) != vrf.Size {
return fmt.Errorf("index '%x' has wrong length (expected %d)", req.Update.NewEntry.Index, vrf.Size)
}
prevUpdate, err := ks.getUpdate(req.Update.NewEntry.Index, math.MaxUint64)
if err != nil {
log.Print(err)
return fmt.Errorf("internal error")
}
if prevUpdate == nil { // registration: check email proof
if !ks.insecureSkipEmailProof {
email, payload, err := dkim.CheckEmailProof(req.DKIMProof, ks.emailProofToAddr,
ks.emailProofSubjectPrefix, ks.lookupTXT, ks.clk.Now)
if err != nil {
return fmt.Errorf("failed to verify DKIM proof: %s", err)
}
if got, want := email, req.LookupParameters.UserId; got != want {
return fmt.Errorf("requested user ID does not match the email proof: %q != %q", got, want)
}
lastAtIndex := strings.LastIndex(req.LookupParameters.UserId, "@")
if lastAtIndex == -1 {
return fmt.Errorf("requested user id is not a valid email address: %q", req.LookupParameters.UserId)
}
if _, ok := ks.emailProofAllowedDomains[req.LookupParameters.UserId[lastAtIndex+1:]]; !ok {
return fmt.Errorf("domain not in registration whitelist: %q", req.LookupParameters.UserId[lastAtIndex+1:])
}
entryHash, err := base64.StdEncoding.DecodeString(payload)
if err != nil {
return fmt.Errorf("bad base64 in email proof: %q", payload)
}
var entryHashProposed [32]byte
sha3.ShakeSum256(entryHashProposed[:], req.Update.NewEntry.Encoding)
if !bytes.Equal(entryHashProposed[:], entryHash[:]) {
return fmt.Errorf("email proof does not match requested entry: %s vs %s (%x)", base64.StdEncoding.EncodeToString(entryHashProposed[:]), payload, req.Update.NewEntry.Encoding)
}
}
}
return ks.verifyUpdateDeterministic(prevUpdate, req)
}
示例14: KeyID
// KeyID computes the ID of public key.
func KeyID(sv *PublicKey) uint64 {
var h [8]byte
sha3.ShakeSum256(h[:], MustMarshal(sv))
return binary.LittleEndian.Uint64(h[:8])
}
示例15: doUpdate
func doUpdate(
t *testing.T, ks *Keyserver, clientConfig *proto.Config, clientTLS *tls.Config, caPool *x509.CertPool, now time.Time,
name string, sk *[ed25519.PrivateKeySize]byte, pk *proto.PublicKey, version uint64, profileContents proto.Profile,
) (*proto.EncodedEntry, *proto.EncodedProfile) {
conn, err := grpc.Dial(ks.publicListen.Addr().String(), grpc.WithTransportCredentials(credentials.NewTLS(clientTLS)))
if err != nil {
t.Fatal(err)
}
publicC := proto.NewE2EKSPublicClient(conn)
// First, do a lookup to retrieve the index
lookup, err := publicC.Lookup(context.Background(), &proto.LookupRequest{
UserId: name,
// We don't care about any signatures here; the server just needs to tell us the index.
QuorumRequirement: &proto.QuorumExpr{
Threshold: 0,
Candidates: []uint64{},
Subexpressions: []*proto.QuorumExpr{},
},
})
if err != nil {
t.Fatal(err)
}
index := lookup.Index
// Do the update
var keyidBytes [8]byte
sha3.ShakeSum256(keyidBytes[:], proto.MustMarshal(pk))
keyid := binary.BigEndian.Uint64(keyidBytes[:8])
profile := proto.EncodedProfile{
Profile: profileContents,
}
profile.UpdateEncoding()
var commitment [64]byte
sha3.ShakeSum256(commitment[:], profile.Encoding)
entry := proto.EncodedEntry{
Entry: proto.Entry{
Index: index,
Version: version,
UpdatePolicy: &proto.AuthorizationPolicy{
PublicKeys: map[uint64]*proto.PublicKey{keyid: pk},
PolicyType: &proto.AuthorizationPolicy_Quorum{Quorum: &proto.QuorumExpr{
Threshold: 1,
Candidates: []uint64{keyid},
Subexpressions: []*proto.QuorumExpr{},
},
}},
ProfileCommitment: commitment[:],
},
}
entry.UpdateEncoding()
proof, err := publicC.Update(context.Background(), &proto.UpdateRequest{
Update: &proto.SignedEntryUpdate{
NewEntry: entry,
Signatures: map[uint64][]byte{keyid: ed25519.Sign(sk, entry.Encoding)[:]},
},
Profile: profile,
LookupParameters: &proto.LookupRequest{
UserId: name,
QuorumRequirement: clientConfig.Realms[0].VerificationPolicy.GetQuorum(),
},
})
if err != nil {
t.Fatal(err)
}
if got, want := proof.Profile.Encoding, profile.Encoding; !bytes.Equal(got, want) {
t.Errorf("updated profile didn't roundtrip: %x != %x", got, want)
}
_, err = coname.VerifyLookup(clientConfig, name, proof, now)
if err != nil {
t.Fatal(err)
}
return &entry, &profile
}