github.com/emmansun/gmsm@v0.29.1/cipher/ccm_64bit_test.go (about)

     1  //go:build !(arm || mips)
     2  
     3  package cipher_test
     4  
     5  import (
     6  	"crypto/aes"
     7  	"encoding/hex"
     8  	"testing"
     9  
    10  	"github.com/emmansun/gmsm/cipher"
    11  )
    12  
    13  func TestCCMLongAd(t *testing.T) {
    14  	key, _ := hex.DecodeString("ab72c77b97cb5fe9a382d9fe81ffdbed")
    15  	nonce, _ := hex.DecodeString("54cc7dc2c37ec006bcc6d1db")
    16  
    17  	c, _ := aes.NewCipher(key)
    18  	aesccm, _ := cipher.NewCCM(c)
    19  
    20  	ad := make([]byte, 0x10000)
    21  	ct := aesccm.Seal(nil, nonce, nil, ad)
    22  	if hex.EncodeToString(ct) != "e1ad65c3bfaba94b1085aff8c6ea2698" {
    23  		t.Errorf("got %s, want e1ad65c3bfaba94b1085aff8c6ea2698", hex.EncodeToString(ct))
    24  	}
    25  
    26  	ad = make([]byte, 1<<32+1)
    27  	ct = aesccm.Seal(nil, nonce, nil, ad)
    28  	if hex.EncodeToString(ct) != "c1949a661c605ff5640a29dd3e285ddb" {
    29  		t.Errorf("got %s, want c1949a661c605ff5640a29dd3e285ddb", hex.EncodeToString(ct))
    30  	}
    31  }