-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #542 from intel-go/develop
Release 0.7.3
- Loading branch information
Showing
58 changed files
with
4,181 additions
and
1,266 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright 2019 Intel Corporation. | ||
# Use of this source code is governed by a BSD-style | ||
# license that can be found in the LICENSE file. | ||
|
||
PATH_TO_MK = ../../mk | ||
SUBDIRS = stability perf | ||
|
||
include $(PATH_TO_MK)/intermediate.mk |
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,122 @@ | ||
// Copyright 2019 Intel Corporation. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Only IPv4, Only tunnel, Only ESP, Only AES-128-CBC | ||
package ipsec | ||
|
||
import "github.com/intel-go/nff-go/examples/ipsec/crypto_mb" | ||
|
||
import "crypto/aes" | ||
import "crypto/cipher" | ||
import "crypto/hmac" | ||
import "crypto/sha1" | ||
import "hash" | ||
|
||
const VECTOR = 8 | ||
|
||
type SContext struct { | ||
mac123 hash.Hash | ||
modeEnc cipher.BlockMode | ||
modeDec cipher.BlockMode | ||
} | ||
|
||
type VContext struct { | ||
mac123 crypto_mb.MultiHash | ||
modeEnc crypto_mb.MultiBlockMode | ||
modeDec crypto_mb.MultiBlockMode | ||
|
||
vectorEncryptionPart [][]byte | ||
vectorIV [][]byte | ||
vectorAuthPart [][]byte | ||
vectorAuthPlace [][]byte | ||
|
||
s SContext | ||
} | ||
|
||
type SetIVerM interface { | ||
SetIV([][]byte) | ||
} | ||
|
||
type SetIVer interface { | ||
SetIV([]byte) | ||
} | ||
|
||
func InitSContext() interface{} { | ||
var auth123Key = []byte("qqqqqqqqqqqqqqqqqqqq") | ||
var crypt123Key = []byte("AES128Key-16Char") | ||
block123, _ := aes.NewCipher(crypt123Key) | ||
|
||
tempScalarIV := make([]byte, 16) | ||
|
||
n := new(SContext) | ||
n.mac123 = hmac.New(sha1.New, auth123Key) | ||
n.modeEnc = cipher.NewCBCEncrypter(block123, tempScalarIV) | ||
n.modeDec = cipher.NewCBCDecrypter(block123, tempScalarIV) | ||
return n | ||
} | ||
|
||
func InitVContext() interface{} { | ||
var auth123Key = []byte("qqqqqqqqqqqqqqqqqqqq") | ||
var crypt123Key = []byte("AES128Key-16Char") | ||
block123 := crypto_mb.NewAESMultiBlock(crypt123Key) | ||
|
||
tempVectorIV := make([][]byte, VECTOR, VECTOR) | ||
for i := 0; i < VECTOR; i++ { | ||
tempVectorIV[i] = make([]byte, 16) | ||
} | ||
|
||
n := new(VContext) | ||
n.mac123 = crypto_mb.NewHmac(crypto_mb.New, auth123Key) | ||
n.modeEnc = crypto_mb.NewMultiCBCEncrypter(block123, tempVectorIV) | ||
n.modeDec = crypto_mb.NewMultiCBCDecrypter(block123, tempVectorIV) | ||
n.vectorEncryptionPart = make([][]byte, VECTOR, VECTOR) | ||
n.vectorIV = make([][]byte, VECTOR, VECTOR) | ||
n.vectorAuthPart = make([][]byte, VECTOR, VECTOR) | ||
n.vectorAuthPlace = make([][]byte, VECTOR, VECTOR) | ||
n.s = *InitSContext().(*SContext) | ||
return n | ||
} | ||
|
||
func (c SContext) Copy() interface{} { | ||
return InitSContext() | ||
} | ||
|
||
func (c VContext) Copy() interface{} { | ||
return InitVContext() | ||
} | ||
|
||
func (c SContext) Delete() { | ||
} | ||
|
||
func (c VContext) Delete() { | ||
} | ||
|
||
func Encrypt(EncryptionPart [][]byte, where [][]byte, IV [][]byte, Z uint, context *VContext) { | ||
if Z != VECTOR { | ||
for t := uint(0); t < Z; t++ { | ||
context.s.modeEnc.(SetIVer).SetIV(IV[t]) | ||
context.s.modeEnc.CryptBlocks(EncryptionPart[t], where[t]) | ||
} | ||
} else { | ||
context.modeEnc.(SetIVerM).SetIV(IV[:]) | ||
context.modeEnc.CryptManyBlocks(EncryptionPart, where) | ||
} | ||
} | ||
|
||
func Authenticate(AuthenticationPart [][]byte, where [][]byte, Z uint, context *VContext) { | ||
if Z != VECTOR { | ||
for t := uint(0); t < Z; t++ { | ||
context.s.mac123.Reset() | ||
context.s.mac123.Write(where[t]) | ||
copy(where[t], context.s.mac123.Sum(nil)) | ||
} | ||
} else { | ||
context.mac123.Reset() | ||
context.mac123.Write(context.vectorAuthPart) | ||
temp := context.mac123.Sum(nil) | ||
for t := uint(0); t < VECTOR; t++ { | ||
copy(where[t], temp[t]) | ||
} | ||
} | ||
} |
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,42 @@ | ||
// Copyright 2019 Intel Corporation. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package crypto_mb | ||
|
||
//TODO check cpuid | ||
|
||
type aes_x8 struct { | ||
blockSize int | ||
enc []uint32 | ||
dec []uint32 | ||
} | ||
|
||
func (this *aes_x8) BlockSize() int { | ||
return this.blockSize | ||
} | ||
|
||
func (this *aes_x8) VecSize() int { | ||
return 8 | ||
} | ||
|
||
//TODO accept number of blocks | ||
func NewAESMultiBlock(key []byte) MultiBlock { | ||
if len(key) != 16 { | ||
// TODO return error? | ||
panic("For now only 16-byte keys are supported") | ||
} | ||
n := len(key) + 28 | ||
rounds := 10 | ||
c := aes_x8{len(key), make([]uint32, n), make([]uint32, n)} | ||
expandKeyAsm(rounds, &key[0], &c.enc[0], &c.dec[0]) | ||
return &c | ||
} | ||
|
||
// in aes.s | ||
//go:noescape | ||
func encrypt8BlocksAsm(xk *uint32, dst, src [][]byte) | ||
|
||
func (this *aes_x8) DecryptMany(dst, src [][]byte) { | ||
panic("Not implemented yet") | ||
} |
Oops, something went wrong.