256 lines
8.3 KiB
Plaintext
256 lines
8.3 KiB
Plaintext
##############################################
|
|
#### Tests for ECB Mode
|
|
##############################################
|
|
SET @IV='abcd1234efgh5678';
|
|
SET @KEYS=REPEAT('c', 16);
|
|
SET @ENCSTR=REPEAT('d', 256);
|
|
"--------------------------------------------"
|
|
##################### Testing with mode : aes-128-ecb
|
|
SET SESSION block_encryption_mode="aes-128-ecb";
|
|
SELECT @@global.block_encryption_mode;
|
|
@@global.block_encryption_mode
|
|
aes-128-ecb
|
|
SELECT @@session.block_encryption_mode;
|
|
@@session.block_encryption_mode
|
|
aes-128-ecb
|
|
####Test without tables
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR
|
|
1
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR
|
|
1
|
|
Warnings:
|
|
Warning 1618 <IV> option ignored
|
|
Warning 1618 <IV> option ignored
|
|
####Test with InnoDB tables
|
|
DROP TABLE IF EXISTS t1;
|
|
Warnings:
|
|
Note 1051 Unknown table 'test.t1'
|
|
CREATE TABLE t1(f1 varchar(256));
|
|
INSERT INTO t1 values(@ENCSTR);
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR
|
|
1
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR
|
|
1
|
|
Warnings:
|
|
Warning 1618 <IV> option ignored
|
|
Warning 1618 <IV> option ignored
|
|
####Test with Innodb tables
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1(f1 varchar(256)) engine=InnoDB;
|
|
INSERT INTO t1 values(@ENCSTR);
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR
|
|
1
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR
|
|
1
|
|
Warnings:
|
|
Warning 1618 <IV> option ignored
|
|
Warning 1618 <IV> option ignored
|
|
"--------------------------------------------"
|
|
##################### Testing with mode : aes-192-ecb
|
|
SET SESSION block_encryption_mode="aes-192-ecb";
|
|
SELECT @@global.block_encryption_mode;
|
|
@@global.block_encryption_mode
|
|
aes-128-ecb
|
|
SELECT @@session.block_encryption_mode;
|
|
@@session.block_encryption_mode
|
|
aes-192-ecb
|
|
####Test without tables
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR
|
|
1
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR
|
|
1
|
|
Warnings:
|
|
Warning 1618 <IV> option ignored
|
|
Warning 1618 <IV> option ignored
|
|
####Test with InnoDB tables
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1(f1 varchar(256));
|
|
INSERT INTO t1 values(@ENCSTR);
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR
|
|
1
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR
|
|
1
|
|
Warnings:
|
|
Warning 1618 <IV> option ignored
|
|
Warning 1618 <IV> option ignored
|
|
####Test with Innodb tables
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1(f1 varchar(256)) engine=InnoDB;
|
|
INSERT INTO t1 values(@ENCSTR);
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR
|
|
1
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR
|
|
1
|
|
Warnings:
|
|
Warning 1618 <IV> option ignored
|
|
Warning 1618 <IV> option ignored
|
|
"--------------------------------------------"
|
|
##################### Testing with mode : aes-256-ecb
|
|
SET SESSION block_encryption_mode="aes-256-ecb";
|
|
should return 1
|
|
SELECT @@global.block_encryption_mode;
|
|
@@global.block_encryption_mode
|
|
aes-128-ecb
|
|
should return 1
|
|
SELECT @@session.block_encryption_mode;
|
|
@@session.block_encryption_mode
|
|
aes-256-ecb
|
|
####Test without tables
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR
|
|
1
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR
|
|
1
|
|
Warnings:
|
|
Warning 1618 <IV> option ignored
|
|
Warning 1618 <IV> option ignored
|
|
####Test with InnoDB tables
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1(f1 varchar(256));
|
|
INSERT INTO t1 values(@ENCSTR);
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR
|
|
1
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR
|
|
1
|
|
Warnings:
|
|
Warning 1618 <IV> option ignored
|
|
Warning 1618 <IV> option ignored
|
|
####Test with innodb tables
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1(f1 varchar(256)) engine=InnoDB;
|
|
INSERT INTO t1 values(@ENCSTR);
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS), @KEYS)=@ENCSTR
|
|
1
|
|
should return 1
|
|
SELECT AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @KEYS, @IV), @KEYS, @IV)=@ENCSTR
|
|
1
|
|
Warnings:
|
|
Warning 1618 <IV> option ignored
|
|
Warning 1618 <IV> option ignored
|
|
DROP TABLE IF EXISTS t1;
|
|
"--------------------------------------------"
|
|
##############################################
|
|
"Tests related to RANDOM_BYTES()"
|
|
##############################################
|
|
should return 1
|
|
select LENGTH(RANDOM_BYTES(1))=1;
|
|
LENGTH(RANDOM_BYTES(1))=1
|
|
1
|
|
should return 1
|
|
select LENGTH(RANDOM_BYTES(1024))=1024;
|
|
LENGTH(RANDOM_BYTES(1024))=1024
|
|
1
|
|
SET @KEYS=RANDOM_BYTES(1);
|
|
SET @KEYS=RANDOM_BYTES(1024);
|
|
select RANDOM_BYTES(0);
|
|
ERROR 22003: length value is out of range in 'random_bytes'
|
|
select RANDOM_BYTES(1025);
|
|
ERROR 22003: length value is out of range in 'random_bytes'
|
|
##############################################
|
|
"Tests related to boundary values of IV"
|
|
##############################################
|
|
SET @IV='abcdefghijklmnophelloworldworldisgreat';
|
|
SET @IV1='abcdefghijklmnopqrstuvwxyz';
|
|
SET @KEYS='helloworld';
|
|
SET @ENCSTR=REPEAT('K',100);
|
|
SET @@session.block_encryption_mode = 'aes-256-cbc';
|
|
should return 1
|
|
select AES_ENCRYPT(@ENCSTR, @KEYS, @IV)=AES_ENCRYPT(@ENCSTR, @KEYS, @IV1);
|
|
AES_ENCRYPT(@ENCSTR, @KEYS, @IV)=AES_ENCRYPT(@ENCSTR, @KEYS, @IV1)
|
|
1
|
|
##############################################
|
|
"Few negative tests with invalid/different keys and IV"
|
|
##############################################
|
|
SET @IV='ijkl8765mnop2345';
|
|
SET @KEYS='helloworld1234567890';
|
|
SET @ENCSTR=REPEAT('J',255);
|
|
SET @@session.block_encryption_mode = 'aes-128-ecb';
|
|
DROP TABLE IF EXISTS t1;
|
|
Warnings:
|
|
Note 1051 Unknown table 'test.t1'
|
|
CREATE TABLE t1(f1 varchar(256)) charset latin1;
|
|
INSERT INTO t1 values(AES_ENCRYPT(@ENCSTR, @KEYS, @IV));
|
|
Warnings:
|
|
Warning 1618 <IV> option ignored
|
|
Combination1..............
|
|
SET @@session.block_encryption_mode = 'aes-192-ecb';
|
|
should return NULL
|
|
SELECT AES_DECRYPT(f1, @KEYS, @IV)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(f1, @KEYS, @IV)=@ENCSTR
|
|
NULL
|
|
Warnings:
|
|
Warning 1618 <IV> option ignored
|
|
Combination2..............
|
|
SET @@session.block_encryption_mode = 'aes-256-ecb';
|
|
should return NULL
|
|
SELECT AES_DECRYPT(f1, @KEYS, @IV)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(f1, @KEYS, @IV)=@ENCSTR
|
|
NULL
|
|
Warnings:
|
|
Warning 1618 <IV> option ignored
|
|
Combination3..............
|
|
SET @@session.block_encryption_mode = 'aes-128-cbc';
|
|
should return 0 or NULL
|
|
SELECT COALESCE (AES_DECRYPT(f1, @KEYS, @IV)=@ENCSTR,0) FROM t1;
|
|
COALESCE (AES_DECRYPT(f1, @KEYS, @IV)=@ENCSTR,0)
|
|
0
|
|
Combination4..............
|
|
SET @@session.block_encryption_mode = 'aes-192-cbc';
|
|
should return NULL
|
|
SELECT AES_DECRYPT(f1, @KEYS, @IV)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(f1, @KEYS, @IV)=@ENCSTR
|
|
NULL
|
|
Combination5..............
|
|
SET @@session.block_encryption_mode = 'aes-256-cbc';
|
|
should return NULL
|
|
SELECT AES_DECRYPT(f1, @KEYS, @IV)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(f1, @KEYS, @IV)=@ENCSTR
|
|
NULL
|
|
Combination6..............
|
|
SET @@session.block_encryption_mode = 'aes-128-ecb';
|
|
should return 1
|
|
SELECT AES_DECRYPT(f1, @KEYS, @IV)=@ENCSTR FROM t1;
|
|
AES_DECRYPT(f1, @KEYS, @IV)=@ENCSTR
|
|
1
|
|
Warnings:
|
|
Warning 1618 <IV> option ignored
|
|
SET @@session.block_encryption_mode = DEFAULT;
|
|
DROP TABLE IF EXISTS t1;
|
|
#
|
|
# End of 5.7 tests
|
|
#
|