本文整理汇总了Golang中crypto/sha512.New384函数的典型用法代码示例。如果您正苦于以下问题:Golang New384函数的具体用法?Golang New384怎么用?Golang New384使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New384函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Sign
// Sign is used to certify a message with the key pair passed in. It returns a
// boolean indicating success; on success, the signature value returned will
// contain the signature.
func Sign(message []byte, key PrivateKey, pub PublicKey) (signature []byte, ok bool) {
if message == nil {
return nil, false
} else if !KeyIsSuitable(key, pub) {
return nil, false
}
h := sha512.New384()
h.Write(message)
hash := h.Sum(nil)
skey, ok := ecdsa_private(key, pub)
if !ok {
return
}
r, s, err := ecdsa.Sign(PRNG, skey, hash)
if err != nil {
ok = false
} else {
signature = marshalSignature(r, s)
if signature == nil {
ok = false
}
}
return
}
示例2: EndBackup
func (b *BackupSet) EndBackup() error {
if b.records == nil {
return fmt.Errorf("Cannot end unstarted backup run")
}
start, ok := b.records[b.lastStartIndex].(startRecord)
if !ok {
return fmt.Errorf("Corrupted backup set: purported last start record is not a start record")
}
start.length = 0
digester := sha512.New384()
for i := b.lastStartIndex; i < len(b.records); i++ {
start.length += b.records[i].Len()
recordType, data := b.records[i].Record()
err := binary.Write(digester, binary.BigEndian, uint8(0))
if err != nil {
return err
}
err = binary.Write(digester, binary.BigEndian, recordType)
if err != nil {
return err
}
digester.Write(data)
}
end := endRecord{digester.Sum(nil)}
start.length += end.Len()
b.records[b.lastStartIndex] = start
b.records = append(b.records, end)
return nil
}
示例3: process_file
func process_file(filename string, complete chan Sumlist) {
sumlist := Sumlist{}
sumlist.filename = filename
// Open the file and bail if we fail
infile, err := os.Open(filename)
if err != nil {
log.Printf("Unable to open %s: %s", filename, err)
complete <- sumlist
return
}
defer infile.Close()
// Create the checksum objects
if flag_crc32 {
sumlist.sums = append(sumlist.sums, Checksum{"CRC32", crc32.New(crc32.IEEETable)})
}
if flag_crc64 {
sumlist.sums = append(sumlist.sums, Checksum{"CRC64", crc64.New(crc64.MakeTable(crc64.ISO))})
}
if flag_sha224 {
sumlist.sums = append(sumlist.sums, Checksum{"SHA224", sha256.New224()})
}
if flag_sha256 {
sumlist.sums = append(sumlist.sums, Checksum{"SHA256", sha256.New()})
}
if flag_sha384 {
sumlist.sums = append(sumlist.sums, Checksum{"SHA384", sha512.New384()})
}
if flag_sha512 {
sumlist.sums = append(sumlist.sums, Checksum{"SHA512", sha512.New()})
}
// Create our file reader
reader := bufio.NewReader(infile)
// Start a buffer and loop to read the entire file
buf := make([]byte, 4096)
for {
read_count, err := reader.Read(buf)
// If we get an error that is not EOF, then we have a problem
if err != nil && err != io.EOF {
log.Printf("Unable to open %s: %s", filename, err)
complete <- sumlist
return
}
// If the returned size is zero, we're at the end of the file
if read_count == 0 {
break
}
// Add the buffer contents to the checksum calculation
for _, sum := range sumlist.sums {
sum.hashFunc.Write(buf[:read_count])
}
}
complete <- sumlist
}
示例4: calcHash
func calcHash(pass, salt []byte) []byte {
h := sha512.New384()
h.Write(hashVersion)
h.Write(salt)
h.Write(pass)
return h.Sum(nil)
}
示例5: checkGetArchive
func (s *suite) checkGetArchive(c *gc.C) string {
ch := charmRepo.CharmArchive(c.MkDir(), "wordpress")
// Open the archive and calculate its hash and size.
r, expectHash, expectSize := archiveHashAndSize(c, ch.Path)
r.Close()
url := charm.MustParseReference("~charmers/utopic/wordpress-42")
err := s.client.UploadCharmWithRevision(url, ch, 42)
c.Assert(err, gc.IsNil)
rb, id, hash, size, err := s.client.GetArchive(url)
c.Assert(err, gc.IsNil)
defer rb.Close()
c.Assert(id, jc.DeepEquals, url)
c.Assert(hash, gc.Equals, expectHash)
c.Assert(size, gc.Equals, expectSize)
h := sha512.New384()
size, err = io.Copy(h, rb)
c.Assert(err, gc.IsNil)
c.Assert(size, gc.Equals, expectSize)
c.Assert(fmt.Sprintf("%x", h.Sum(nil)), gc.Equals, expectHash)
// Return the stats key for the archive download.
keys := []string{params.StatsArchiveDownload, "utopic", "wordpress", "charmers", "42"}
return strings.Join(keys, ":")
}
示例6: 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
}
示例7: main
func main() {
for _, h := range []hash.Hash{md4.New(), md5.New(), sha1.New(),
sha256.New224(), sha256.New(), sha512.New384(), sha512.New(),
ripemd160.New()} {
fmt.Printf("%x\n\n", h.Sum())
}
}
示例8: sha384
func (e *Engine) sha384() error {
data, err := computeHash(sha512.New384(), e.stack.Pop())
if err == nil {
e.stack.Push(data)
}
return err
}
示例9: calc_checksum
/*
read from os.File and return the whole file's checksum
*/
func calc_checksum(fp io.Reader, t string) string {
var m hash.Hash
switch t {
case "md5":
m = md5.New()
case "sha1":
m = sha1.New()
case "sha512":
m = sha512.New()
case "sha256":
m = sha256.New()
case "sha224":
m = sha256.New224()
case "sha384":
m = sha512.New384()
default:
output_e("unknown type: %s\n", t)
return ""
}
/* issue:
if fp is os.Stdin, there is no way to trigger EOF
*/
_, err := io.Copy(m, fp)
if err != nil {
output_e("%ssum: %s\n", t, err.Error())
return ""
}
return fmt.Sprintf("%x", m.Sum(nil))
}
示例10: 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)
}
}
示例11: ToDS
// ToDS converts a DNSKEY record to a DS record.
func (k *RR_DNSKEY) ToDS(h int) *RR_DS {
if k == nil {
return nil
}
ds := new(RR_DS)
ds.Hdr.Name = k.Hdr.Name
ds.Hdr.Class = k.Hdr.Class
ds.Hdr.Rrtype = TypeDS
ds.Hdr.Ttl = k.Hdr.Ttl
ds.Algorithm = k.Algorithm
ds.DigestType = uint8(h)
ds.KeyTag = k.KeyTag()
keywire := new(dnskeyWireFmt)
keywire.Flags = k.Flags
keywire.Protocol = k.Protocol
keywire.Algorithm = k.Algorithm
keywire.PublicKey = k.PublicKey
wire := make([]byte, DefaultMsgSize)
n, ok := PackStruct(keywire, wire, 0)
if !ok {
return nil
}
wire = wire[:n]
owner := make([]byte, 255)
off, ok1 := PackDomainName(k.Hdr.Name, owner, 0, nil, false)
if !ok1 {
return nil
}
owner = owner[:off]
// RFC4034:
// digest = digest_algorithm( DNSKEY owner name | DNSKEY RDATA);
// "|" denotes concatenation
// DNSKEY RDATA = Flags | Protocol | Algorithm | Public Key.
// digest buffer
digest := append(owner, wire...) // another copy
switch h {
case SHA1:
s := sha1.New()
io.WriteString(s, string(digest))
ds.Digest = hex.EncodeToString(s.Sum(nil))
case SHA256:
s := sha256.New()
io.WriteString(s, string(digest))
ds.Digest = hex.EncodeToString(s.Sum(nil))
case SHA384:
s := sha512.New384()
io.WriteString(s, string(digest))
ds.Digest = hex.EncodeToString(s.Sum(nil))
case GOST94:
/* I have no clue */
default:
return nil
}
return ds
}
示例12: calculateCheckSum
func calculateCheckSum(c *gc.C, start, length int64, blob []byte) (sha384HashHex string) {
data := blob[start : start+length]
sha384Hash := sha512.New384()
_, err := sha384Hash.Write(data)
c.Assert(err, gc.IsNil)
sha384HashHex = fmt.Sprintf("%x", sha384Hash.Sum(nil))
return sha384HashHex
}
示例13: newFingerprint
func newFingerprint(c *gc.C, data string) ([]byte, string) {
hash := sha512.New384()
_, err := hash.Write([]byte(data))
c.Assert(err, jc.ErrorIsNil)
sum := hash.Sum(nil)
hexStr := hex.EncodeToString(sum)
return sum, hexStr
}
示例14: archiveHashAndSize
func archiveHashAndSize(c *gc.C, path string) (r csclient.ReadSeekCloser, hash string, size int64) {
f, err := os.Open(path)
c.Assert(err, gc.IsNil)
h := sha512.New384()
size, err = io.Copy(h, f)
c.Assert(err, gc.IsNil)
_, err = f.Seek(0, 0)
c.Assert(err, gc.IsNil)
return f, fmt.Sprintf("%x", h.Sum(nil)), size
}
示例15: hashAlg
func hashAlg(keySizeBits int) hash.Hash {
switch keySizeBits {
case 256:
return sha256.New()
case 384:
return sha512.New384()
default:
return sha512.New()
}
}