MCPcopy
hub / github.com/ph4ntonn/Stowaway / KeyPadding

Function KeyPadding

crypto/aes.go:14–28  ·  view source on GitHub ↗

2021.10.1 Switch AES-CBC to AES-GCM Faster(serial computing to parallel computing) and safer(avoid Padding Oracle Attack)

(key []byte)

Source from the content-addressed store, hash-verified

12// Faster(serial computing to parallel computing) and safer(avoid Padding Oracle Attack)
13
14func KeyPadding(key []byte) []byte {
15 // if no key,just return
16 if string(key) == "" {
17 return nil
18 }
19 // if key is set & == 32 bytes, return it
20 keyLength := len(key)
21 if keyLength > 32 {
22 return key[:32]
23 }
24 // if key < 32 bytes, pad it
25 padding := 32 - keyLength
26 padText := bytes.Repeat([]byte{byte(0)}, padding)
27 return append(key, padText...)
28}
29
30func genNonce(nonceSize int) []byte {
31 nonce := make([]byte, nonceSize)

Calls

no outgoing calls

Tested by

no test coverage detected