...

Source file src/github.com/cloudflare/circl/sign/dilithium/mode3aes.go

Documentation: github.com/cloudflare/circl/sign/dilithium

     1  // Code generated from mode.templ.go. DO NOT EDIT.
     2  
     3  package dilithium
     4  
     5  import (
     6  	"fmt"
     7  	"io"
     8  
     9  	"github.com/cloudflare/circl/sign/dilithium/internal/common"
    10  	"github.com/cloudflare/circl/sign/dilithium/mode3aes"
    11  )
    12  
    13  // implMode3AES implements the mode.Mode interface for Dilithium3-AES.
    14  type implMode3AES struct{}
    15  
    16  // Mode3AES is Dilithium in mode "Dilithium3-AES".
    17  var Mode3AES Mode = &implMode3AES{}
    18  
    19  func (m *implMode3AES) GenerateKey(rand io.Reader) (
    20  	PublicKey, PrivateKey, error) {
    21  	return mode3aes.GenerateKey(rand)
    22  }
    23  
    24  func (m *implMode3AES) NewKeyFromSeed(seed []byte) (PublicKey,
    25  	PrivateKey) {
    26  	if len(seed) != common.SeedSize {
    27  		panic(fmt.Sprintf("seed must be of length %d", common.SeedSize))
    28  	}
    29  	seedBuf := [common.SeedSize]byte{}
    30  	copy(seedBuf[:], seed)
    31  	return mode3aes.NewKeyFromSeed(&seedBuf)
    32  }
    33  
    34  func (m *implMode3AES) Sign(sk PrivateKey, msg []byte) []byte {
    35  	isk := sk.(*mode3aes.PrivateKey)
    36  	ret := [mode3aes.SignatureSize]byte{}
    37  	mode3aes.SignTo(isk, msg, ret[:])
    38  	return ret[:]
    39  }
    40  
    41  func (m *implMode3AES) Verify(pk PublicKey, msg []byte, signature []byte) bool {
    42  	ipk := pk.(*mode3aes.PublicKey)
    43  	return mode3aes.Verify(ipk, msg, signature)
    44  }
    45  
    46  func (m *implMode3AES) PublicKeyFromBytes(data []byte) PublicKey {
    47  	var ret mode3aes.PublicKey
    48  	if len(data) != mode3aes.PublicKeySize {
    49  		panic("packed public key must be of mode3aes.PublicKeySize bytes")
    50  	}
    51  	var buf [mode3aes.PublicKeySize]byte
    52  	copy(buf[:], data)
    53  	ret.Unpack(&buf)
    54  	return &ret
    55  }
    56  
    57  func (m *implMode3AES) PrivateKeyFromBytes(data []byte) PrivateKey {
    58  	var ret mode3aes.PrivateKey
    59  	if len(data) != mode3aes.PrivateKeySize {
    60  		panic("packed public key must be of mode3aes.PrivateKeySize bytes")
    61  	}
    62  	var buf [mode3aes.PrivateKeySize]byte
    63  	copy(buf[:], data)
    64  	ret.Unpack(&buf)
    65  	return &ret
    66  }
    67  
    68  func (m *implMode3AES) SeedSize() int {
    69  	return common.SeedSize
    70  }
    71  
    72  func (m *implMode3AES) PublicKeySize() int {
    73  	return mode3aes.PublicKeySize
    74  }
    75  
    76  func (m *implMode3AES) PrivateKeySize() int {
    77  	return mode3aes.PrivateKeySize
    78  }
    79  
    80  func (m *implMode3AES) SignatureSize() int {
    81  	return mode3aes.SignatureSize
    82  }
    83  
    84  func (m *implMode3AES) Name() string {
    85  	return "Dilithium3-AES"
    86  }
    87  
    88  func init() {
    89  	modes["Dilithium3-AES"] = Mode3AES
    90  }
    91  

View as plain text