Debian Codegraph @

skein/skein1024/skein.go

raw symbols SCIP
1 // Use of this source code is governed by a license
2 // that can be found in the LICENSE file
3
4 // Package skein1024 implements the Skein1024 hash function
5 // based on the Threefish1024 tweakable block cipher.
6 package skein1024
7
8 import (
9 "hash"
10
11 "github.com/enceve/crypto/skein"
12 )
13
14 // Sum512 computes the 512 bit Skein1024 checksum (or MAC if key is set) of msg
15 // and writes it to out. The key is optional and can be nil.
16 func Sum512(out *[64]byte, msg, key []byte) {
17 var out1024 [128]byte
18
19 s := new(hashFunc)
20 s.initialize(64, &skein.Config{Key: key})
21
22 s.Write(msg)
23
24 s.finalizeHash()
25
26 s.output(&out1024, 0)
27 copy(out[:], out1024[:64])
28 }
29
30 // Sum384 computes the 384 bit Skein1024 checksum (or MAC if key is set) of msg
31 // and writes it to out. The key is optional and can be nil.
32 func Sum384(out *[48]byte, msg, key []byte) {
33 var out1024 [128]byte
34
35 s := new(hashFunc)
36 s.initialize(48, &skein.Config{Key: key})
37
38 s.Write(msg)
39
40 s.finalizeHash()
41
42 s.output(&out1024, 0)
43 copy(out[:], out1024[:48])
44 }
45
46 // Sum256 computes the 256 bit Skein1024 checksum (or MAC if key is set) of msg
47 // and writes it to out. The key is optional and can be nil.
48 func Sum256(out *[32]byte, msg, key []byte) {
49 var out1024 [128]byte
50
51 s := new(hashFunc)
52 s.initialize(32, &skein.Config{Key: key})
53
54 s.Write(msg)
55
56 s.finalizeHash()
57
58 s.output(&out1024, 0)
59 copy(out[:], out1024[:32])
60 }
61
62 // Sum160 computes the 160 bit Skein1024 checksum (or MAC if key is set) of msg
63 // and writes it to out. The key is optional and can be nil.
64 func Sum160(out *[20]byte, msg, key []byte) {
65 var out1024 [128]byte
66
67 s := new(hashFunc)
68 s.initialize(20, &skein.Config{Key: key})
69
70 s.Write(msg)
71
72 s.finalizeHash()
73
74 s.output(&out1024, 0)
75 copy(out[:], out1024[:20])
76 }
77
78 // Sum returns the Skein1024 checksum with the given hash size of msg using the (optional)
79 // conf for configuration. The hashsize must be > 0.
80 func Sum(msg []byte, hashsize int, conf *skein.Config) []byte {
81 s := New(hashsize, conf)
82 s.Write(msg)
83 return s.Sum(nil)
84 }
85
86 // New512 returns a hash.Hash computing the Skein1024 512 bit checksum.
87 // The key is optional and turns the hash into a MAC.
88 func New512(key []byte) hash.Hash {
89 s := new(hashFunc)
90
91 s.initialize(64, &skein.Config{Key: key})
92
93 return s
94 }
95
96 // New256 returns a hash.Hash computing the Skein1024 256 bit checksum.
97 // The key is optional and turns the hash into a MAC.
98 func New256(key []byte) hash.Hash {
99 s := new(hashFunc)
100
101 s.initialize(32, &skein.Config{Key: key})
102
103 return s
104 }
105
106 // New returns a hash.Hash computing the Skein1024 checksum with the given hash size.
107 // The conf is optional and configurates the hash.Hash
108 func New(hashsize int, conf *skein.Config) hash.Hash {
109 s := new(hashFunc)
110 s.initialize(hashsize, conf)
111 return s
112 }