github.com/hyperledger/aries-framework-go@v0.3.2/pkg/internal/cryptoutil/legacy_utils.go (about) 1 /* 2 Copyright SecureKey Technologies Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package cryptoutil 8 9 import "golang.org/x/crypto/blake2b" 10 11 // Nonce makes a nonce using blake2b, to match the format expected by libsodium. 12 func Nonce(pub1, pub2 []byte) (*[NonceSize]byte, error) { 13 var nonce [NonceSize]byte 14 // generate an equivalent nonce to libsodium's (see link above) 15 nonceWriter, err := blake2b.New(NonceSize, nil) 16 if err != nil { 17 return nil, err 18 } 19 20 _, err = nonceWriter.Write(pub1) 21 if err != nil { 22 return nil, err 23 } 24 25 _, err = nonceWriter.Write(pub2) 26 if err != nil { 27 return nil, err 28 } 29 30 nonceOut := nonceWriter.Sum(nil) 31 copy(nonce[:], nonceOut) 32 33 return &nonce, nil 34 }