2016-10-29 15:11:37 +03:00
|
|
|
// Copyright 2016 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package whisperv5
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2017-03-22 21:48:51 +03:00
|
|
|
mrand "math/rand"
|
2016-10-29 15:11:37 +03:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2017-01-31 13:16:20 +03:00
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
2016-10-29 15:11:37 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func generateMessageParams() (*MessageParams, error) {
|
2017-04-26 22:05:48 +03:00
|
|
|
// set all the parameters except p.Dst and p.Padding
|
2016-12-20 02:58:01 +03:00
|
|
|
|
2017-04-26 22:05:48 +03:00
|
|
|
buf := make([]byte, 4)
|
2017-03-22 21:48:51 +03:00
|
|
|
mrand.Read(buf)
|
|
|
|
sz := mrand.Intn(400)
|
2016-10-29 15:11:37 +03:00
|
|
|
|
|
|
|
var p MessageParams
|
2016-12-20 02:58:01 +03:00
|
|
|
p.PoW = 0.01
|
|
|
|
p.WorkTime = 1
|
2017-03-22 21:48:51 +03:00
|
|
|
p.TTL = uint32(mrand.Intn(1024))
|
2016-10-29 15:11:37 +03:00
|
|
|
p.Payload = make([]byte, sz)
|
|
|
|
p.KeySym = make([]byte, aesKeyLength)
|
2017-04-26 22:05:48 +03:00
|
|
|
mrand.Read(p.Payload)
|
|
|
|
mrand.Read(p.KeySym)
|
|
|
|
p.Topic = BytesToTopic(buf)
|
2016-10-29 15:11:37 +03:00
|
|
|
|
|
|
|
var err error
|
|
|
|
p.Src, err = crypto.GenerateKey()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &p, nil
|
|
|
|
}
|
|
|
|
|
2016-12-01 22:09:22 +03:00
|
|
|
func singleMessageTest(t *testing.T, symmetric bool) {
|
2016-10-29 15:11:37 +03:00
|
|
|
params, err := generateMessageParams()
|
|
|
|
if err != nil {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
key, err := crypto.GenerateKey()
|
|
|
|
if err != nil {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !symmetric {
|
|
|
|
params.KeySym = nil
|
|
|
|
params.Dst = &key.PublicKey
|
|
|
|
}
|
|
|
|
|
|
|
|
text := make([]byte, 0, 512)
|
|
|
|
text = append(text, params.Payload...)
|
|
|
|
|
2017-04-26 22:05:48 +03:00
|
|
|
msg, err := NewSentMessage(params)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
|
|
|
|
}
|
2016-10-29 15:11:37 +03:00
|
|
|
env, err := msg.Wrap(params)
|
|
|
|
if err != nil {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var decrypted *ReceivedMessage
|
|
|
|
if symmetric {
|
|
|
|
decrypted, err = env.OpenSymmetric(params.KeySym)
|
|
|
|
} else {
|
|
|
|
decrypted, err = env.OpenAsymmetric(key)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed to encrypt with seed %d: %s.", seed, err)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !decrypted.Validate() {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed to validate with seed %d.", seed)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
|
2017-01-06 18:44:20 +03:00
|
|
|
if !bytes.Equal(text, decrypted.Payload) {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed with seed %d: compare payload.", seed)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
if !isMessageSigned(decrypted.Raw[0]) {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed with seed %d: unsigned.", seed)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
if len(decrypted.Signature) != signatureLength {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed with seed %d: signature len %d.", seed, len(decrypted.Signature))
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
2016-12-20 02:58:01 +03:00
|
|
|
if !IsPubKeyEqual(decrypted.Src, ¶ms.Src.PublicKey) {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed with seed %d: signature mismatch.", seed)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-01 22:09:22 +03:00
|
|
|
func TestMessageEncryption(t *testing.T) {
|
2016-10-29 15:11:37 +03:00
|
|
|
InitSingleTest()
|
|
|
|
|
|
|
|
var symmetric bool
|
|
|
|
for i := 0; i < 256; i++ {
|
2016-12-01 22:09:22 +03:00
|
|
|
singleMessageTest(t, symmetric)
|
2016-10-29 15:11:37 +03:00
|
|
|
symmetric = !symmetric
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-01 22:09:22 +03:00
|
|
|
func TestMessageWrap(t *testing.T) {
|
2016-10-29 15:11:37 +03:00
|
|
|
seed = int64(1777444222)
|
2017-03-22 21:48:51 +03:00
|
|
|
mrand.Seed(seed)
|
2016-10-29 15:11:37 +03:00
|
|
|
target := 128.0
|
|
|
|
|
|
|
|
params, err := generateMessageParams()
|
|
|
|
if err != nil {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
|
2017-04-26 22:05:48 +03:00
|
|
|
msg, err := NewSentMessage(params)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
|
|
|
|
}
|
2016-10-29 15:11:37 +03:00
|
|
|
params.TTL = 1
|
|
|
|
params.WorkTime = 12
|
|
|
|
params.PoW = target
|
|
|
|
env, err := msg.Wrap(params)
|
|
|
|
if err != nil {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pow := env.PoW()
|
|
|
|
if pow < target {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed Wrap with seed %d: pow < target (%f vs. %f).", seed, pow, target)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
2016-12-20 02:58:01 +03:00
|
|
|
|
|
|
|
// set PoW target too high, expect error
|
2017-04-26 22:05:48 +03:00
|
|
|
msg2, err := NewSentMessage(params)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
|
|
|
|
}
|
2016-12-20 02:58:01 +03:00
|
|
|
params.TTL = 1000000
|
|
|
|
params.WorkTime = 1
|
|
|
|
params.PoW = 10000000.0
|
2017-08-08 14:48:06 +03:00
|
|
|
_, err = msg2.Wrap(params)
|
2016-12-20 02:58:01 +03:00
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("unexpectedly reached the PoW target with seed %d.", seed)
|
|
|
|
}
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
|
2016-12-01 22:09:22 +03:00
|
|
|
func TestMessageSeal(t *testing.T) {
|
2016-10-29 15:11:37 +03:00
|
|
|
// this test depends on deterministic choice of seed (1976726903)
|
|
|
|
seed = int64(1976726903)
|
2017-03-22 21:48:51 +03:00
|
|
|
mrand.Seed(seed)
|
2016-10-29 15:11:37 +03:00
|
|
|
|
|
|
|
params, err := generateMessageParams()
|
|
|
|
if err != nil {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
|
2017-04-26 22:05:48 +03:00
|
|
|
msg, err := NewSentMessage(params)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
|
|
|
|
}
|
2016-10-29 15:11:37 +03:00
|
|
|
params.TTL = 1
|
|
|
|
aesnonce := make([]byte, 12)
|
2017-03-22 21:48:51 +03:00
|
|
|
mrand.Read(aesnonce)
|
2016-10-29 15:11:37 +03:00
|
|
|
|
2017-04-26 22:05:48 +03:00
|
|
|
env := NewEnvelope(params.TTL, params.Topic, aesnonce, msg)
|
2016-10-29 15:11:37 +03:00
|
|
|
if err != nil {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
env.Expiry = uint32(seed) // make it deterministic
|
|
|
|
target := 32.0
|
|
|
|
params.WorkTime = 4
|
|
|
|
params.PoW = target
|
|
|
|
env.Seal(params)
|
|
|
|
|
|
|
|
env.calculatePoW(0)
|
|
|
|
pow := env.PoW()
|
|
|
|
if pow < target {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed Wrap with seed %d: pow < target (%f vs. %f).", seed, pow, target)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
params.WorkTime = 1
|
|
|
|
params.PoW = 1000000000.0
|
|
|
|
env.Seal(params)
|
|
|
|
env.calculatePoW(0)
|
|
|
|
pow = env.PoW()
|
|
|
|
if pow < 2*target {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed Wrap with seed %d: pow too small %f.", seed, pow)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-01 22:09:22 +03:00
|
|
|
func TestEnvelopeOpen(t *testing.T) {
|
2016-10-29 15:11:37 +03:00
|
|
|
InitSingleTest()
|
|
|
|
|
|
|
|
var symmetric bool
|
|
|
|
for i := 0; i < 256; i++ {
|
2016-12-01 22:09:22 +03:00
|
|
|
singleEnvelopeOpenTest(t, symmetric)
|
2016-10-29 15:11:37 +03:00
|
|
|
symmetric = !symmetric
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-01 22:09:22 +03:00
|
|
|
func singleEnvelopeOpenTest(t *testing.T, symmetric bool) {
|
2016-10-29 15:11:37 +03:00
|
|
|
params, err := generateMessageParams()
|
|
|
|
if err != nil {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
key, err := crypto.GenerateKey()
|
|
|
|
if err != nil {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed GenerateKey with seed %d: %s.", seed, err)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if !symmetric {
|
|
|
|
params.KeySym = nil
|
|
|
|
params.Dst = &key.PublicKey
|
|
|
|
}
|
|
|
|
|
|
|
|
text := make([]byte, 0, 512)
|
|
|
|
text = append(text, params.Payload...)
|
|
|
|
|
2017-04-26 22:05:48 +03:00
|
|
|
msg, err := NewSentMessage(params)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
|
|
|
|
}
|
2016-10-29 15:11:37 +03:00
|
|
|
env, err := msg.Wrap(params)
|
|
|
|
if err != nil {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed Wrap with seed %d: %s.", seed, err)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
f := Filter{KeyAsym: key, KeySym: params.KeySym}
|
|
|
|
decrypted := env.Open(&f)
|
|
|
|
if decrypted == nil {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed to open with seed %d.", seed)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
|
2017-01-06 18:44:20 +03:00
|
|
|
if !bytes.Equal(text, decrypted.Payload) {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed with seed %d: compare payload.", seed)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
if !isMessageSigned(decrypted.Raw[0]) {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed with seed %d: unsigned.", seed)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
if len(decrypted.Signature) != signatureLength {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed with seed %d: signature len %d.", seed, len(decrypted.Signature))
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
2016-12-20 02:58:01 +03:00
|
|
|
if !IsPubKeyEqual(decrypted.Src, ¶ms.Src.PublicKey) {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed with seed %d: signature mismatch.", seed)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
if decrypted.isAsymmetricEncryption() == symmetric {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed with seed %d: asymmetric %v vs. %v.", seed, decrypted.isAsymmetricEncryption(), symmetric)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
if decrypted.isSymmetricEncryption() != symmetric {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed with seed %d: symmetric %v vs. %v.", seed, decrypted.isSymmetricEncryption(), symmetric)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
if !symmetric {
|
|
|
|
if decrypted.Dst == nil {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed with seed %d: dst is nil.", seed)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
2016-12-20 02:58:01 +03:00
|
|
|
if !IsPubKeyEqual(decrypted.Dst, &key.PublicKey) {
|
2016-12-01 22:09:22 +03:00
|
|
|
t.Fatalf("failed with seed %d: Dst.", seed)
|
2016-10-29 15:11:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-20 02:58:01 +03:00
|
|
|
|
|
|
|
func TestEncryptWithZeroKey(t *testing.T) {
|
|
|
|
InitSingleTest()
|
|
|
|
|
|
|
|
params, err := generateMessageParams()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
|
|
|
|
}
|
2017-04-26 22:05:48 +03:00
|
|
|
msg, err := NewSentMessage(params)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
|
|
|
|
}
|
2016-12-20 02:58:01 +03:00
|
|
|
params.KeySym = make([]byte, aesKeyLength)
|
|
|
|
_, err = msg.Wrap(params)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("wrapped with zero key, seed: %d.", seed)
|
|
|
|
}
|
|
|
|
|
2017-04-26 22:05:48 +03:00
|
|
|
params, err = generateMessageParams()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
|
|
|
|
}
|
|
|
|
msg, err = NewSentMessage(params)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
|
|
|
|
}
|
2016-12-20 02:58:01 +03:00
|
|
|
params.KeySym = make([]byte, 0)
|
|
|
|
_, err = msg.Wrap(params)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("wrapped with empty key, seed: %d.", seed)
|
|
|
|
}
|
|
|
|
|
2017-04-26 22:05:48 +03:00
|
|
|
params, err = generateMessageParams()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
|
|
|
|
}
|
|
|
|
msg, err = NewSentMessage(params)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
|
|
|
|
}
|
2016-12-20 02:58:01 +03:00
|
|
|
params.KeySym = nil
|
|
|
|
_, err = msg.Wrap(params)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("wrapped with nil key, seed: %d.", seed)
|
|
|
|
}
|
|
|
|
}
|
2017-01-31 13:16:20 +03:00
|
|
|
|
|
|
|
func TestRlpEncode(t *testing.T) {
|
|
|
|
InitSingleTest()
|
|
|
|
|
|
|
|
params, err := generateMessageParams()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed generateMessageParams with seed %d: %s.", seed, err)
|
|
|
|
}
|
2017-04-26 22:05:48 +03:00
|
|
|
msg, err := NewSentMessage(params)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
|
|
|
|
}
|
2017-01-31 13:16:20 +03:00
|
|
|
env, err := msg.Wrap(params)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("wrapped with zero key, seed: %d.", seed)
|
|
|
|
}
|
|
|
|
|
|
|
|
raw, err := rlp.EncodeToBytes(env)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("RLP encode failed: %s.", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var decoded Envelope
|
|
|
|
rlp.DecodeBytes(raw, &decoded)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("RLP decode failed: %s.", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
he := env.Hash()
|
|
|
|
hd := decoded.Hash()
|
|
|
|
|
|
|
|
if he != hd {
|
|
|
|
t.Fatalf("Hashes are not equal: %x vs. %x", he, hd)
|
|
|
|
}
|
|
|
|
}
|
2017-04-26 22:05:48 +03:00
|
|
|
|
|
|
|
func singlePaddingTest(t *testing.T, padSize int) {
|
|
|
|
params, err := generateMessageParams()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed generateMessageParams with seed %d and sz=%d: %s.", seed, padSize, err)
|
|
|
|
}
|
|
|
|
params.Padding = make([]byte, padSize)
|
|
|
|
params.PoW = 0.0000000001
|
|
|
|
pad := make([]byte, padSize)
|
|
|
|
_, err = mrand.Read(pad)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("padding is not generated (seed %d): %s", seed, err)
|
|
|
|
}
|
|
|
|
n := copy(params.Padding, pad)
|
|
|
|
if n != padSize {
|
|
|
|
t.Fatalf("padding is not copied (seed %d): %s", seed, err)
|
|
|
|
}
|
|
|
|
msg, err := NewSentMessage(params)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create new message with seed %d: %s.", seed, err)
|
|
|
|
}
|
|
|
|
env, err := msg.Wrap(params)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to wrap, seed: %d and sz=%d.", seed, padSize)
|
|
|
|
}
|
|
|
|
f := Filter{KeySym: params.KeySym}
|
|
|
|
decrypted := env.Open(&f)
|
|
|
|
if decrypted == nil {
|
|
|
|
t.Fatalf("failed to open, seed and sz=%d: %d.", seed, padSize)
|
|
|
|
}
|
|
|
|
if !bytes.Equal(pad, decrypted.Padding) {
|
|
|
|
t.Fatalf("padding is not retireved as expected with seed %d and sz=%d:\n[%x]\n[%x].", seed, padSize, pad, decrypted.Padding)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPadding(t *testing.T) {
|
|
|
|
InitSingleTest()
|
|
|
|
|
|
|
|
for i := 1; i < 260; i++ {
|
|
|
|
singlePaddingTest(t, i)
|
|
|
|
}
|
|
|
|
|
|
|
|
lim := 256 * 256
|
|
|
|
for i := lim - 5; i < lim+2; i++ {
|
|
|
|
singlePaddingTest(t, i)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 256; i++ {
|
|
|
|
n := mrand.Intn(256*254) + 256
|
|
|
|
singlePaddingTest(t, n)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 256; i++ {
|
|
|
|
n := mrand.Intn(256*1024) + 256*256
|
|
|
|
singlePaddingTest(t, n)
|
|
|
|
}
|
|
|
|
}
|