Debian Codegraph @

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