...

Source file src/github.com/cloudflare/circl/sign/dilithium/mode5aes.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/mode5aes"
    11  )
    12  
    13  // implMode5AES implements the mode.Mode interface for Dilithium5-AES.
    14  type implMode5AES struct{}
    15  
    16  // Mode5AES is Dilithium in mode "Dilithium5-AES".
    17  var Mode5AES Mode = &implMode5AES{}
    18  
    19  func (m *implMode5AES) GenerateKey(rand io.Reader) (
    20  	PublicKey, PrivateKey, error) {
    21  	return mode5aes.GenerateKey(rand)
    22  }
    23  
    24  func (m *implMode5AES) 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 mode5aes.NewKeyFromSeed(&seedBuf)
    32  }
    33  
    34  func (m *implMode5AES) Sign(sk PrivateKey, msg []byte) []byte {
    35  	isk := sk.(*mode5aes.PrivateKey)
    36  	ret := [mode5aes.SignatureSize]byte{}
    37  	mode5aes.SignTo(isk, msg, ret[:])
    38  	return ret[:]
    39  }
    40  
    41  func (m *implMode5AES) Verify(pk PublicKey, msg []byte, signature []byte) bool {
    42  	ipk := pk.(*mode5aes.PublicKey)
    43  	return mode5aes.Verify(ipk, msg, signature)
    44  }
    45  
    46  func (m *implMode5AES) PublicKeyFromBytes(data []byte) PublicKey {
    47  	var ret mode5aes.PublicKey
    48  	if len(data) != mode5aes.PublicKeySize {
    49  		panic("packed public key must be of mode5aes.PublicKeySize bytes")
    50  	}
    51  	var buf [mode5aes.PublicKeySize]byte
    52  	copy(buf[:], data)
    53  	ret.Unpack(&buf)
    54  	return &ret
    55  }
    56  
    57  func (m *implMode5AES) PrivateKeyFromBytes(data []byte) PrivateKey {
    58  	var ret mode5aes.PrivateKey
    59  	if len(data) != mode5aes.PrivateKeySize {
    60  		panic("packed public key must be of mode5aes.PrivateKeySize bytes")
    61  	}
    62  	var buf [mode5aes.PrivateKeySize]byte
    63  	copy(buf[:], data)
    64  	ret.Unpack(&buf)
    65  	return &ret
    66  }
    67  
    68  func (m *implMode5AES) SeedSize() int {
    69  	return common.SeedSize
    70  }
    71  
    72  func (m *implMode5AES) PublicKeySize() int {
    73  	return mode5aes.PublicKeySize
    74  }
    75  
    76  func (m *implMode5AES) PrivateKeySize() int {
    77  	return mode5aes.PrivateKeySize
    78  }
    79  
    80  func (m *implMode5AES) SignatureSize() int {
    81  	return mode5aes.SignatureSize
    82  }
    83  
    84  func (m *implMode5AES) Name() string {
    85  	return "Dilithium5-AES"
    86  }
    87  
    88  func init() {
    89  	modes["Dilithium5-AES"] = Mode5AES
    90  }
    91  

View as plain text