本文整理汇总了Golang中golang.org/x/crypto/sha3.New256函数的典型用法代码示例。如果您正苦于以下问题:Golang New256函数的具体用法?Golang New256怎么用?Golang New256使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New256函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ParseBlob
// Initialize manifest from BLOB
func (s *Manifest) ParseBlob(in io.Reader, chunkSize int64) (err error) {
var chunkHasher hash.Hash
var w io.Writer
var chunk Chunk
hasher := sha3.New256()
var written int64
for {
chunk = Chunk{
Offset: s.Size,
}
chunkHasher = sha3.New256()
w = io.MultiWriter(hasher, chunkHasher)
written, err = io.CopyN(w, in, chunkSize)
s.Size += written
chunk.Size = written
chunk.ID = ID(hex.EncodeToString(chunkHasher.Sum(nil)))
s.Chunks = append(s.Chunks, chunk)
if err == io.EOF {
err = nil
break
} else if err != nil {
return
}
}
s.ID = ID(hex.EncodeToString(hasher.Sum(nil)))
return
}
开发者ID:pombredanne,项目名称:bar,代码行数:30,代码来源:manifest.go
示例2: Test_SHA3
func Test_SHA3(t *testing.T) {
hasher1 := sha3.New256()
hasher1.Write([]byte("mama_myla_ramu"))
hasher2 := sha3.New256()
hasher2.Write([]byte("mama_"))
hasher2.Write([]byte("myla_"))
hasher2.Write([]byte("ramu"))
assert.Equal(t, hasher1.Sum(nil), hasher2.Sum(nil))
}
开发者ID:pombredanne,项目名称:bar,代码行数:12,代码来源:manifest_test.go
示例3: getCAFile
func (s *BlockStorage) getCAFile(name string) (w *contentaddressable.File, err error) {
caOpts := contentaddressable.DefaultOptions()
caOpts.Hasher = sha3.New256()
w, err = contentaddressable.NewFileWithOptions(name, caOpts)
return
}
开发者ID:pombredanne,项目名称:bar,代码行数:7,代码来源:block.go
示例4: Checksum
// Checksum returns the checksum of some data, using a specified algorithm.
// It only returns an error when an invalid algorithm is used. The valid ones
// are MD5, SHA1, SHA224, SHA256, SHA384, SHA512, SHA3224, SHA3256, SHA3384,
// and SHA3512.
func Checksum(algorithm string, data []byte) (checksum string, err error) {
// default
var hasher hash.Hash
switch strings.ToUpper(algorithm) {
case "MD5":
hasher = md5.New()
case "SHA1":
hasher = sha1.New()
case "SHA224":
hasher = sha256.New224()
case "SHA256":
hasher = sha256.New()
case "SHA384":
hasher = sha512.New384()
case "SHA512":
hasher = sha512.New()
case "SHA3224":
hasher = sha3.New224()
case "SHA3256":
hasher = sha3.New256()
case "SHA3384":
hasher = sha3.New384()
case "SHA3512":
hasher = sha3.New512()
default:
msg := "Invalid algorithm parameter passed go Checksum: %s"
return checksum, fmt.Errorf(msg, algorithm)
}
hasher.Write(data)
str := hex.EncodeToString(hasher.Sum(nil))
return str, nil
}
开发者ID:allenbhuiyan,项目名称:distributive,代码行数:36,代码来源:fsstatus.go
示例5: PutData3
func (u *U16x16) PutData3(data []byte, key string) (length int64, hash string, err error) {
s := sha3.New256()
s.Write(data)
hash = hex.EncodeToString(s.Sum(nil))
if hash != key {
fmt.Printf("expected data to have key %s, but content key is %s",
key, hash)
err = errors.New("content/key mismatch")
return
}
length = int64(len(data))
topSubDir := hash[0:1]
lowerDir := hash[1:2]
targetDir := filepath.Join(u.path, topSubDir, lowerDir)
found, err := xf.PathExists(targetDir)
if err == nil && !found {
err = os.MkdirAll(targetDir, 0775)
}
fullishPath := filepath.Join(targetDir, key[2:])
found, err = xf.PathExists(fullishPath)
if !found {
var dest *os.File
dest, err = os.Create(fullishPath)
if err == nil {
var count int
defer dest.Close()
count, err = dest.Write(data)
if err == nil {
length = int64(count)
}
}
}
return
}
开发者ID:jddixon,项目名称:xlU_go,代码行数:34,代码来源:u16x16.go
示例6: PutData3
func (u *UFlat) PutData3(data []byte, key string) (length int64, hash string, err error) {
s := sha3.New256()
s.Write(data)
hash = hex.EncodeToString(s.Sum(nil))
if hash != key {
fmt.Printf("expected data to have key %s, but content key is %s",
key, hash)
err = errors.New("content/key mismatch")
return
}
length = int64(len(data))
fullishPath := filepath.Join(u.path, key)
found, err := xf.PathExists(fullishPath)
if !found {
var dest *os.File
dest, err = os.Create(fullishPath)
if err == nil {
var count int
defer dest.Close()
count, err = dest.Write(data)
if err == nil {
length = int64(count)
}
}
}
return
}
开发者ID:jddixon,项目名称:xlU_go,代码行数:27,代码来源:uFlat.go
示例7: Test_Assembler_StoreChunk
func Test_Assembler_StoreChunk(t *testing.T) {
wd, _ := os.Getwd()
wd = filepath.Join(wd, "testdata", "assembler-StoreChunk")
m, err := model.New(wd, false, proto.CHUNK_SIZE, 128)
assert.NoError(t, err)
data := []byte("mama myla ramu")
hasher := sha3.New256()
_, err = hasher.Write([]byte(data))
id := proto.ID(hex.EncodeToString(hasher.Sum(nil)))
a, err := model.NewAssembler(m)
assert.NoError(t, err)
defer a.Close()
err = a.StoreChunk(bytes.NewReader(data), id)
assert.NoError(t, err)
// check stored chunk
f, err := os.Open(filepath.Join(a.Where, id.String()))
assert.NoError(t, err)
defer f.Close()
defer os.Remove(filepath.Join(a.Where, id.String()))
r2, err := ioutil.ReadAll(f)
assert.NoError(t, err)
assert.Equal(t, data, r2)
}
开发者ID:pombredanne,项目名称:bar,代码行数:29,代码来源:assembler_test.go
示例8: verifyLeafSHA
func (s *XLSuite) verifyLeafSHA(c *C, rng *xr.PRNG,
node MerkleNodeI, pathToFile string, whichSHA int) {
c.Assert(node.IsLeaf(), Equals, true)
found, err := xf.PathExists(pathToFile)
c.Assert(err, IsNil)
c.Assert(found, Equals, true)
data, err := ioutil.ReadFile(pathToFile)
c.Assert(err, IsNil)
c.Assert(data, NotNil)
var sha hash.Hash
switch whichSHA {
case xu.USING_SHA1:
sha = sha1.New()
case xu.USING_SHA2:
sha = sha256.New()
case xu.USING_SHA3:
sha = sha3.New256()
// XXX DEFAULT = ERROR
}
sha.Write(data)
sum := sha.Sum(nil)
c.Assert(node.GetHash(), DeepEquals, sum)
}
开发者ID:jddixon,项目名称:xlUtil_go,代码行数:25,代码来源:merkle_tree_test.go
示例9: StoreChunk
// Store chunk in assemble
func (a *Assembler) StoreChunk(r io.Reader, id proto.ID) (err error) {
lock, err := a.model.FdLocks.Take()
if err != nil {
return
}
defer lock.Release()
caOpts := contentaddressable.DefaultOptions()
caOpts.Hasher = sha3.New256()
w, err := contentaddressable.NewFileWithOptions(
filepath.Join(a.Where, id.String()), caOpts)
if os.IsExist(err) {
err = nil
return
}
if err != nil {
return
}
defer w.Close()
if _, err = io.Copy(w, r); err != nil {
return
}
err = w.Accept()
return
}
开发者ID:pombredanne,项目名称:bar,代码行数:28,代码来源:assembler.go
示例10: SchnorrVerify
// Checks the signature against
// the message
func SchnorrVerify(suite abstract.Suite,
kp SchnorrPublicKey,
msg []byte, sig []byte) (bool, error) {
buf := bytes.NewBuffer(sig)
signature := SchnorrSignature{}
err := abstract.Read(buf, &signature, suite)
if err != nil {
return false, err
}
s := signature.S
e := signature.E
var gs, ye, r abstract.Point
gs = suite.Point().Mul(nil, s) // g^s
ye = suite.Point().Mul(kp.Y, e) // y^e
r = suite.Point().Add(gs, ye) // g^xy^e
r_bin, _ := r.MarshalBinary()
msg_and_r := append(msg, r_bin...)
hasher := sha3.New256()
hasher.Write(msg_and_r)
h := hasher.Sum(nil)
// again I'm hoping this just reads the state out
// and doesn't actually perform any ops
lct := suite.Cipher(h)
ev := suite.Secret().Pick(lct)
return ev.Equal(e), nil
}
开发者ID:diagprov,项目名称:interview-go-multisigs,代码行数:34,代码来源:schnorr.go
示例11: GenerateZ
/* GenerateZ takes some random agreed information and creates
Z the "public-only" key that is witness-independent as per
the paper. We've probably broken that slightly in this implementation
because I could not pick a point without generating it
via a Secret, instead of directly via a Point - that is, even as a
32-byte string, we cannot decode on C25519 (and this wouldn't work
for abstract suites anyway).
However, it demonstrates the idea.
*/
func GenerateZ(suite abstract.Suite, info []byte) (abstract.Point, error) {
hasher := sha3.New256()
hasher.Write(info)
zraw := hasher.Sum(nil)
//I think this might be cheating
zrawCt := suite.Cipher(zraw)
zfactor := suite.Secret().Pick(zrawCt)
Z := suite.Point()
Z.Mul(nil, zfactor)
// every 32-bit integer exists on Curve25519 only if we have the fullgroup
// this should work, but doesn't.
/*var Z abstract.Point
zrawBuf := bytes.NewBuffer(zraw)
err := abstract.Read(zrawBuf, &Z, suite);
if err != nil {
return nil, err
}*/
return Z, nil
}
开发者ID:diagprov,项目名称:interview-go-multisigs,代码行数:35,代码来源:partialBlind.go
示例12: TestHashOpts
func TestHashOpts(t *testing.T) {
msg := []byte("abcd")
// SHA256
digest1, err := currentBCCSP.Hash(msg, &bccsp.SHA256Opts{})
if err != nil {
t.Fatalf("Failed computing SHA256 [%s]", err)
}
h := sha256.New()
h.Write(msg)
digest2 := h.Sum(nil)
if !bytes.Equal(digest1, digest2) {
t.Fatalf("Different SHA256 computed. [%x][%x]", digest1, digest2)
}
// SHA384
digest1, err = currentBCCSP.Hash(msg, &bccsp.SHA384Opts{})
if err != nil {
t.Fatalf("Failed computing SHA384 [%s]", err)
}
h = sha512.New384()
h.Write(msg)
digest2 = h.Sum(nil)
if !bytes.Equal(digest1, digest2) {
t.Fatalf("Different SHA384 computed. [%x][%x]", digest1, digest2)
}
// SHA3_256O
digest1, err = currentBCCSP.Hash(msg, &bccsp.SHA3_256Opts{})
if err != nil {
t.Fatalf("Failed computing SHA3_256 [%s]", err)
}
h = sha3.New256()
h.Write(msg)
digest2 = h.Sum(nil)
if !bytes.Equal(digest1, digest2) {
t.Fatalf("Different SHA3_256 computed. [%x][%x]", digest1, digest2)
}
// SHA3_384
digest1, err = currentBCCSP.Hash(msg, &bccsp.SHA3_384Opts{})
if err != nil {
t.Fatalf("Failed computing SHA3_384 [%s]", err)
}
h = sha3.New384()
h.Write(msg)
digest2 = h.Sum(nil)
if !bytes.Equal(digest1, digest2) {
t.Fatalf("Different SHA3_384 computed. [%x][%x]", digest1, digest2)
}
}
开发者ID:hyperledger,项目名称:fabric,代码行数:59,代码来源:impl_test.go
示例13: TestXLatticePkt
func (d *XLSuite) TestXLatticePkt(c *C) {
if VERBOSITY > 0 {
fmt.Println("TEST_XLATTICE_PKT")
}
rng := xr.MakeSimpleRNG()
myMsgN := uint64(rng.Int63())
for myMsgN == 0 { // must not be zero
myMsgN = uint64(rng.Int63())
}
id := make([]byte, 32) // sha3 length
rng.NextBytes(id) // random bytes
seqBuf := new(bytes.Buffer)
binary.Write(seqBuf, binary.LittleEndian, myMsgN)
msgLen := 64 + rng.Intn(64)
msg := make([]byte, msgLen)
rng.NextBytes(msg) // fill with rubbish
salt := make([]byte, 8)
rng.NextBytes(salt) // still more rubbish
digest := sha3.New256()
digest.Write(id)
digest.Write(seqBuf.Bytes())
digest.Write(msg)
digest.Write([]byte(salt))
hash := digest.Sum(nil)
// XXX This does not adhere to the rules: it has no Cmd field;
// since it has a payload it must be a Put, and so the id is
// also required and the Hash field should be a Sig instead, right?
var pkt = XLatticeMsg{
MsgN: &myMsgN,
Payload: msg,
Salt: salt,
Hash: hash,
}
// In each of these cases, the test proves that the field
// was present; otherwise the 'empty' value (zero, nil, etc)
// would have been returned.
msgNOut := pkt.GetMsgN()
c.Assert(msgNOut, Equals, myMsgN)
msgOut := pkt.GetPayload()
d.compareByteSlices(c, msgOut, msg)
saltOut := pkt.GetSalt()
d.compareByteSlices(c, saltOut, salt)
hashOut := pkt.GetHash()
d.compareByteSlices(c, hashOut, hash)
}
开发者ID:jddixon,项目名称:xlattice_go,代码行数:58,代码来源:p_test.go
示例14: createKeyFromPassword
func createKeyFromPassword(pwd string) ([]byte, error) {
if len(pwd) < 8 {
return nil, fmt.Errorf("Password has to be at least 8 characters")
}
h := sha3.New256()
h.Write([]byte(pwd))
return h.Sum(nil), nil
}
开发者ID:0x434D53,项目名称:tools,代码行数:10,代码来源:filecrypt.go
示例15: SchnorrMComputeCollectiveChallenge
// (Either side) This function takes the aggregate public commitment
// r and returns sha3(m||r) for a given message.
func SchnorrMComputeCollectiveChallenge(suite abstract.Suite,
msg []byte,
pubCommit SchnorrMAggregateCommmitment) []byte {
p_bin, _ := pubCommit.P.MarshalBinary()
msg_and_p := append(msg, p_bin...)
hasher := sha3.New256()
hasher.Write(msg_and_p)
h := hasher.Sum(nil)
return h
}
开发者ID:diagprov,项目名称:interview-go-multisigs,代码行数:13,代码来源:multisignatures.go
示例16: ClientSignBlindly
/* This is the function that given the client's challenge and response from the server is able to
compute the final blind signature. This is done on the user side (blindly to the signer). */
func ClientSignBlindly(suite abstract.Suite, clientParameters WISchnorrClientParamersList, responseMsg WISchnorrResponseMessage, pubKey SchnorrPublicKey, msg []byte) (WIBlindSignature, bool) {
rho := suite.Secret()
omega := suite.Secret()
sigma := suite.Secret()
delta := suite.Secret()
rho.Add(responseMsg.R, clientParameters.T1)
omega.Add(responseMsg.C, clientParameters.T2)
sigma.Add(responseMsg.S, clientParameters.T3)
delta.Add(responseMsg.D, clientParameters.T4)
gp := suite.Point()
gp.Mul(nil, rho)
yw := suite.Point()
yw.Mul(pubKey.Y, omega)
gpyw := suite.Point()
gpyw.Add(gp, yw)
bGpyw, _ := gpyw.MarshalBinary()
gs := suite.Point()
gs.Mul(nil, sigma)
zd := suite.Point()
zd.Mul(clientParameters.Z, delta)
gszd := suite.Point()
gszd.Add(gs, zd)
bGszd, _ := gszd.MarshalBinary()
bZ, _ := clientParameters.Z.MarshalBinary()
var combinedmsg []byte
combinedmsg = append(combinedmsg, bGpyw...)
combinedmsg = append(combinedmsg, bGszd...)
combinedmsg = append(combinedmsg, bZ...)
combinedmsg = append(combinedmsg, msg...)
hasher := sha3.New256()
hasher.Write(combinedmsg)
bSig := hasher.Sum(nil)
bSigCt := suite.Cipher(bSig)
sig := suite.Secret().Pick(bSigCt)
vsig := suite.Secret()
vsig.Add(omega, delta)
//fmt.Println(sig)
//fmt.Println(vsig)
return WIBlindSignature{rho, omega, sigma, delta}, sig.Equal(vsig)
}
开发者ID:diagprov,项目名称:interview-go-multisigs,代码行数:56,代码来源:partialBlind.go
示例17: HashSHA3Data
func HashSHA3Data(input []byte) (out []byte, err error) {
//sha3hash := sha3.NewKeccak256()
sha3hash := sha3.New256()
_, err = sha3hash.Write(input)
if err != nil {
//return nil, acprotoError(-1, "HashSHA3Data().Write(): ", err)
//return nil, &protoError{value: -1, msg: "HashSHA3Data().Write(): ", err: err}
return nil, &AcError{Value: -1, Msg: "HashSHA3Data().Write(): ", Err: err}
}
out = sha3hash.Sum(nil)
return
}
开发者ID:unix4fun,项目名称:ac,代码行数:12,代码来源:utils.go
示例18: makeHash
func makeHash(name string) hash.Hash {
switch strings.ToLower(name) {
case "ripemd160":
return ripemd160.New()
case "md4":
return md4.New()
case "md5":
return md5.New()
case "sha1":
return sha1.New()
case "sha256":
return sha256.New()
case "sha384":
return sha512.New384()
case "sha3-224":
return sha3.New224()
case "sha3-256":
return sha3.New256()
case "sha3-384":
return sha3.New384()
case "sha3-512":
return sha3.New512()
case "sha512":
return sha512.New()
case "sha512-224":
return sha512.New512_224()
case "sha512-256":
return sha512.New512_256()
case "crc32-ieee":
return crc32.NewIEEE()
case "crc64-iso":
return crc64.New(crc64.MakeTable(crc64.ISO))
case "crc64-ecma":
return crc64.New(crc64.MakeTable(crc64.ECMA))
case "adler32":
return adler32.New()
case "fnv32":
return fnv.New32()
case "fnv32a":
return fnv.New32a()
case "fnv64":
return fnv.New64()
case "fnv64a":
return fnv.New64a()
case "xor8":
return new(xor8)
case "fletch16":
return &fletch16{}
}
return nil
}
开发者ID:qeedquan,项目名称:misc_utilities,代码行数:51,代码来源:checksum.go
示例19: Test_Proto_Spec1
func Test_Proto_Spec1(t *testing.T) {
m1, err := proto.NewFromManifest(fixtures.CleanInput(`BAR:MANIFEST
id ac934d9a88b42aa3b40ef7c81a9dee1aad5a2cddccb00ae6abab9c38095fc15c
size 1234
id ac934d9a88b42aa3b40ef7c81a9dee1aad5a2cddccb00ae6abab9c38095fc15c
size 1234
offset 0
`))
assert.NoError(t, err)
m2, err := proto.NewFromManifest(fixtures.CleanInput(`BAR:MANIFEST
id ac934d9a88b42aa3b40ef7c81a9dee1aad5a2cddccb00ae6abab9c38095fc15c
size 1234
id ac934d9a88b42aa3b40ef7c81a9dee1aad5a2cddccb00ae6abab9c38095fc15c
size 1234
offset 0
`))
assert.NoError(t, err)
spec, err := proto.NewSpec(time.Now().UnixNano(), map[string]proto.ID{
"file/1": m1.ID,
"file/2": m2.ID,
}, []string{})
// hand-made fixture
var sorted sort.StringSlice
sorted = append(sorted, "file/2")
sorted = append(sorted, "file/1")
sorted.Sort()
hasher := sha3.New256()
var id []byte
err = m1.ID.Decode(id)
assert.NoError(t, err)
_, err = hasher.Write([]byte(sorted[0]))
_, err = hasher.Write(id)
_, err = hasher.Write([]byte(sorted[1]))
_, err = hasher.Write(id)
assert.Equal(t, spec.ID, proto.ID(hex.EncodeToString(hasher.Sum(nil))))
}
开发者ID:pombredanne,项目名称:bar,代码行数:49,代码来源:spec_test.go
示例20: main
func main() {
flag.Parse()
hashAlgorithm := sha1.New()
if *sha1Flag {
hashAlgorithm = sha1.New()
}
if *md5Flag {
hashAlgorithm = md5.New()
}
if *sha256Flag {
hashAlgorithm = sha256.New()
}
if *sha384Flag {
hashAlgorithm = sha512.New384()
}
if *sha3256Flag {
hashAlgorithm = sha3.New256()
}
if *sha3384Flag {
hashAlgorithm = sha3.New384()
}
if *sha3512Flag {
hashAlgorithm = sha3.New512()
}
if *whirlpoolFlag {
hashAlgorithm = whirlpool.New()
}
if *blakeFlag {
hashAlgorithm = blake2.NewBlake2B()
}
if *ripemd160Flag {
hashAlgorithm = ripemd160.New()
}
for _, fileName := range flag.Args() {
f, _ := os.Open(fileName)
defer f.Close()
hashAlgorithm.Reset()
output := genericHashFile(f, hashAlgorithm)
if *b64Flag {
r64Output := base64.StdEncoding.EncodeToString(output)
fmt.Printf("%s %s\n", r64Output, fileName)
} else {
fmt.Printf("%x %s\n", output, fileName)
}
}
}
开发者ID:Nelson69,项目名称:hashsum,代码行数:49,代码来源:hashsum.go
注:本文中的golang.org/x/crypto/sha3.New256函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论