-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
6,709 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package kryptoutil | ||
|
||
func MemsetByte(a []byte, v byte) { | ||
if len(a) == 0 { | ||
return | ||
} | ||
a[0] = v | ||
for bp := 1; bp < len(a); bp *= 2 { | ||
copy(a[bp:], a[:bp]) | ||
} | ||
} | ||
|
||
func MemsetUint32(a []uint32, v uint32) { | ||
if len(a) == 0 { | ||
return | ||
} | ||
a[0] = v | ||
for bp := 1; bp < len(a); bp *= 2 { | ||
copy(a[bp:], a[:bp]) | ||
} | ||
} | ||
|
||
func MemsetUint64(a []uint64, v uint64) { | ||
if len(a) == 0 { | ||
return | ||
} | ||
a[0] = v | ||
for bp := 1; bp < len(a); bp *= 2 { | ||
copy(a[bp:], a[:bp]) | ||
} | ||
} | ||
|
||
func MemsetInt(a []int, v int) { | ||
if len(a) == 0 { | ||
return | ||
} | ||
a[0] = v | ||
for bp := 1; bp < len(a); bp *= 2 { | ||
copy(a[bp:], a[:bp]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,53 @@ | ||
// Package lea implements LEA encryption, as defined in TTAK.KO-12.0223 | ||
package lea | ||
|
||
import ( | ||
"crypto/cipher" | ||
"fmt" | ||
) | ||
|
||
type funcNew func(key []byte) (cipher.Block, error) | ||
type funcBlock func(ctx *leaContext, dst, src []byte) | ||
|
||
type leaContext struct { | ||
round uint8 | ||
rk [192]uint32 | ||
ecb bool | ||
} | ||
|
||
var ( | ||
leaEnc1 funcBlock = leaEnc1Go | ||
leaEnc4 funcBlock = leaEnc4Go | ||
leaEnc8 funcBlock = leaEnc8Go | ||
|
||
leaDec1 funcBlock = leaDec1Go | ||
leaDec4 funcBlock = leaDec4Go | ||
leaDec8 funcBlock = leaDec8Go | ||
|
||
leaNew funcNew = newCipherGo | ||
leaNewECB funcNew = newCipherECBGo | ||
) | ||
|
||
const ( | ||
// The LEA block size in bytes. | ||
BlockSize = 16 | ||
) | ||
|
||
type KeySizeError int | ||
|
||
func (k KeySizeError) Error() string { | ||
return fmt.Sprintf("krypto/lea: invalid key size %d", int(k)) | ||
} | ||
|
||
// NewCipher creates and returns a new cipher.Block. | ||
// The key argument should be the LEA key, either 16, 24, or 32 bytes to select LEA-128, LEA-192, or LEA-256. | ||
func NewCipher(key []byte) (cipher.Block, error) { | ||
return leaNew(key) | ||
} | ||
|
||
// NewCipherECB creates and returns a new cipher.Block by ECB mode. | ||
// This function can be useful in amd64. | ||
// The key argument should be the LEA key, either 16, 24, or 32 bytes to select LEA-128, LEA-192, or LEA-256. | ||
func NewCipherECB(key []byte) (cipher.Block, error) { | ||
return leaNewECB(key) | ||
} |
Oops, something went wrong.