Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed May 12, 2024
1 parent d4f9276 commit ee2625e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 42 deletions.
42 changes: 10 additions & 32 deletions cipher/ascon/ascon.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ const (
iv128a uint64 = 0x80800c0800000000 // Ascon-128a
)

var errOpen = errors.New("ascon: message authentication failed")

const (
// BlockSize128a is the size in bytes of an ASCON-128a block.
BlockSize128a = 16

// BlockSize128 is the size in bytes of an ASCON-128 block.
BlockSize128 = 8

// KeySize is the size in bytes of ASCON-128 and ASCON-128a
// keys.
KeySize = 16

// NonceSize is the size in bytes of ASCON-128 and ASCON-128a
// nonces.
NonceSize = 16

// TagSize is the size in bytes of ASCON-128 and ASCON-128a
// authenticators.
TagSize = 16
)

var errOpen = errors.New("cryptobin/ascon: message authentication failed")

type ascon struct {
k0, k1 uint64
iv uint64
Expand All @@ -45,21 +49,8 @@ type ascon struct {
// [ascon]: https://ascon.iaik.tugraz.at
//

// New128 creates a 128-bit ASCON-128 AEAD.
//
// ASCON-128 provides lower throughput but increased robustness
// against partial or full state recovery compared to ASCON-128a.
//
// Each unique key can encrypt a maximum 2^68 bytes (i.e., 2^64
// plaintext and associated data blocks). Nonces must never be
// reused with the same key. Violating either of these
// constraints compromises the security of the algorithm.
//
// There are no other constraints on the composition of the
// nonce. For example, the nonce can be a counter.
//
// Refer to ASCON's documentation for more information.
func New128(key []byte) (cipher.AEAD, error) {
// NewCipher creates a 128-bit ASCON-128 AEAD.
func NewCipher(key []byte) (cipher.AEAD, error) {
if len(key) != KeySize {
return nil, errors.New("cryptobin/ascon: bad key length")
}
Expand All @@ -71,21 +62,8 @@ func New128(key []byte) (cipher.AEAD, error) {
}, nil
}

// New128a creates a 128-bit ASCON-128a AEAD.
//
// ASCON-128a provides higher throughput but reduced robustness
// against partial or full state recovery compared to ASCON-128.
//
// Each unique key can encrypt a maximum 2^68 bytes (i.e., 2^64
// plaintext and associated data blocks). Nonces must never be
// reused with the same key. Violating either of these
// constraints compromises the security of the algorithm.
//
// There are no other constraints on the composition of the
// nonce. For example, the nonce can be a counter.
//
// Refer to ASCON's documentation for more information.
func New128a(key []byte) (cipher.AEAD, error) {
// NewCiphera creates a 128-bit ASCON-128a AEAD.
func NewCiphera(key []byte) (cipher.AEAD, error) {
if len(key) != KeySize {
return nil, errors.New("cryptobin/ascon: bad key length")
}
Expand Down
20 changes: 10 additions & 10 deletions cipher/ascon/ascon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ func TestPermute(t *testing.T) {
}

func TestVectors128(t *testing.T) {
testVectors(t, New128, filepath.Join("testdata", "vectors_128.txt"))
testVectors(t, NewCipher, filepath.Join("testdata", "vectors_128.txt"))
}

func TestVectors128a(t *testing.T) {
testVectors(t, New128a, filepath.Join("testdata", "vectors_128a.txt"))
testVectors(t, NewCiphera, filepath.Join("testdata", "vectors_128a.txt"))
}

func testVectors(t *testing.T, fn func([]byte) (cipher.AEAD, error), path string) {
Expand Down Expand Up @@ -108,35 +108,35 @@ func testVectors(t *testing.T, fn func([]byte) (cipher.AEAD, error), path string
}

func BenchmarkSeal1K_128a(b *testing.B) {
benchmarkSeal(b, New128a, make([]byte, 1024))
benchmarkSeal(b, NewCiphera, make([]byte, 1024))
}

func BenchmarkOpen1K_128a(b *testing.B) {
benchmarkOpen(b, New128a, make([]byte, 1024))
benchmarkOpen(b, NewCiphera, make([]byte, 1024))
}

func BenchmarkSeal8K_128a(b *testing.B) {
benchmarkSeal(b, New128a, make([]byte, 8*1024))
benchmarkSeal(b, NewCiphera, make([]byte, 8*1024))
}

func BenchmarkOpen8K_128a(b *testing.B) {
benchmarkOpen(b, New128a, make([]byte, 8*1024))
benchmarkOpen(b, NewCiphera, make([]byte, 8*1024))
}

func BenchmarkSeal1K_128(b *testing.B) {
benchmarkSeal(b, New128, make([]byte, 1024))
benchmarkSeal(b, NewCipher, make([]byte, 1024))
}

func BenchmarkOpen1K_128(b *testing.B) {
benchmarkOpen(b, New128, make([]byte, 1024))
benchmarkOpen(b, NewCipher, make([]byte, 1024))
}

func BenchmarkSeal8K_128(b *testing.B) {
benchmarkSeal(b, New128, make([]byte, 8*1024))
benchmarkSeal(b, NewCipher, make([]byte, 8*1024))
}

func BenchmarkOpen8K_128(b *testing.B) {
benchmarkOpen(b, New128, make([]byte, 8*1024))
benchmarkOpen(b, NewCipher, make([]byte, 8*1024))
}

func benchmarkSeal(b *testing.B, fn func([]byte) (cipher.AEAD, error), buf []byte) {
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit ee2625e

Please sign in to comment.