@@ -107,6 +107,28 @@ func TestBadInputs(t *testing.T) {
107107 test .CheckIsErr (t , err , "should panic due to bad ciphertext" )
108108}
109109
110+ func TestOpenClearsOnFailure (t * testing.T ) {
111+ key , _ := hex .DecodeString ("000102030405060708090A0B0C0D0E0F" )
112+ nonce , _ := hex .DecodeString ("000102030405060708090A0B0C0D0E0F" )
113+ c , _ := ascon .New (key , ascon .Ascon128 )
114+
115+ pt := []byte ("helloworld" )
116+ ct := c .Seal (nil , nonce , pt , nil )
117+ ct [len (ct )- 1 ] ^= 0xFF // tamper the tag so authentication fails
118+
119+ dst := make ([]byte , 0 , len (pt ))
120+ out , err := c .Open (dst , nonce , ct , nil )
121+ test .CheckIsErr (t , err , "should fail due to bad tag" )
122+ if out != nil {
123+ test .ReportError (t , out , nil )
124+ }
125+
126+ buf := dst [:len (pt )]
127+ if ! bytes .Equal (buf , make ([]byte , len (pt ))) {
128+ test .ReportError (t , buf , make ([]byte , len (pt )))
129+ }
130+ }
131+
110132func TestAPI (t * testing.T ) {
111133 key , _ := hex .DecodeString ("000102030405060708090A0B0C0D0E0F" )
112134 nonce , _ := hex .DecodeString ("000102030405060708090A0B0C0D0E0F" )
0 commit comments