]>
Commit | Line | Data |
---|---|---|
15c0b25d AP |
1 | // Copyright 2014-2017 Ulrich Kunitz. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style | |
3 | // license that can be found in the LICENSE file. | |
4 | ||
5 | package xz | |
6 | ||
7 | import ( | |
8 | "hash" | |
9 | "hash/crc32" | |
10 | "hash/crc64" | |
11 | ) | |
12 | ||
13 | // crc32Hash implements the hash.Hash32 interface with Sum returning the | |
14 | // crc32 value in little-endian encoding. | |
15 | type crc32Hash struct { | |
16 | hash.Hash32 | |
17 | } | |
18 | ||
19 | // Sum returns the crc32 value as little endian. | |
20 | func (h crc32Hash) Sum(b []byte) []byte { | |
21 | p := make([]byte, 4) | |
22 | putUint32LE(p, h.Hash32.Sum32()) | |
23 | b = append(b, p...) | |
24 | return b | |
25 | } | |
26 | ||
27 | // newCRC32 returns a CRC-32 hash that returns the 64-bit value in | |
28 | // little-endian encoding using the IEEE polynomial. | |
29 | func newCRC32() hash.Hash { | |
30 | return crc32Hash{Hash32: crc32.NewIEEE()} | |
31 | } | |
32 | ||
33 | // crc64Hash implements the Hash64 interface with Sum returning the | |
34 | // CRC-64 value in little-endian encoding. | |
35 | type crc64Hash struct { | |
36 | hash.Hash64 | |
37 | } | |
38 | ||
39 | // Sum returns the CRC-64 value in little-endian encoding. | |
40 | func (h crc64Hash) Sum(b []byte) []byte { | |
41 | p := make([]byte, 8) | |
42 | putUint64LE(p, h.Hash64.Sum64()) | |
43 | b = append(b, p...) | |
44 | return b | |
45 | } | |
46 | ||
47 | // crc64Table is used to create a CRC-64 hash. | |
48 | var crc64Table = crc64.MakeTable(crc64.ECMA) | |
49 | ||
50 | // newCRC64 returns a CRC-64 hash that returns the 64-bit value in | |
51 | // little-endian encoding using the ECMA polynomial. | |
52 | func newCRC64() hash.Hash { | |
53 | return crc64Hash{Hash64: crc64.New(crc64Table)} | |
54 | } |