github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/hash/crc64/crc64.go (about) 1 // Copyright 2009 The Go Authors. 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 crc64は64ビットの巡回冗長検査(CRC-64)チェックサムを実装しています。 6 // 詳細はhttps://en.wikipedia.org/wiki/Cyclic_redundancy_checkを参照してください。 7 package crc64 8 9 import ( 10 "github.com/shogo82148/std/hash" 11 ) 12 13 // CRC-64のチェックサムのバイト単位のサイズ。 14 const Size = 8 15 16 // 事前定義された多項式。 17 const ( 18 // ISO 3309で定義され、HDLCで使用されるISOポリノミアル。 19 ISO = 0xD800000000000000 20 21 // ECMA 182で定義されたECMA多項式。 22 ECMA = 0xC96C5795D7870F42 23 ) 24 25 // Table は効率的な処理のための多項式を表す256単語のテーブルです。 26 type Table [256]uint64 27 28 // MakeTable は指定された多項式から構築された [Table] を返します。 29 // このTableの内容は変更してはなりません。 30 func MakeTable(poly uint64) *Table 31 32 // Newは [Table] で表される多項式を使用してCRC-64チェックサムを計算する新しいhash.Hash64を作成します。Sumメソッドは値をビッグエンディアンのバイト順で並べます。返されるHash64は、内部状態をmarshalおよびunmarshalするための [encoding.BinaryMarshaler] および [encoding.BinaryUnmarshaler] も実装しています。 33 func New(tab *Table) hash.Hash64 34 35 // Updateはpのバイトをcrcに追加した結果を返します。 36 func Update(crc uint64, tab *Table, p []byte) uint64 37 38 // Checksum 関数は、 [Table] が表す多項式を使って、データの CRC-64 チェックサムを返します。 39 func Checksum(data []byte, tab *Table) uint64