aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKornel Dulęba <kd@FreeBSD.org>2022-10-06 14:20:58 +0000
committerKornel Dulęba <kd@FreeBSD.org>2022-10-06 14:42:31 +0000
commitfdbd0ba75d99f1909b13a9f9ece5e8c576bd8977 (patch)
tree79b09b93e477d7fe6ae4fa5979c2b0977ede7dd7
parentdc39a3346e7d492114e94ddec7049e720579d6f3 (diff)
downloadsrc-fdbd0ba75d99f1909b13a9f9ece5e8c576bd8977.tar.gz
src-fdbd0ba75d99f1909b13a9f9ece5e8c576bd8977.zip
test/sys/opencrypto: Fix NIST KAT parser iterator
When yield a.k.a "generator" iterator is used we need to return all data using "yield", before returning from the function. Because of that only encryption tests were run for AES-CBC, other modes were affected as well. Add one more loop to the iterator "next" routine to fix that. This unveiled a problem in the GCM AEAD parser logic, which didn't correctly handle tests cases with empty plaintext, i.e. AAD only. Include the fix in this patch as it's a rather trivial one. Obtained from: Semihalf Differential Revision: https://reviews.freebsd.org/D36861
-rw-r--r--tests/sys/opencrypto/cryptodev.py38
1 files changed, 19 insertions, 19 deletions
diff --git a/tests/sys/opencrypto/cryptodev.py b/tests/sys/opencrypto/cryptodev.py
index d97a731d37ba..7e9b1f6a9fbb 100644
--- a/tests/sys/opencrypto/cryptodev.py
+++ b/tests/sys/opencrypto/cryptodev.py
@@ -38,6 +38,7 @@ from fcntl import ioctl
import os
import platform
import random
+import re
import signal
from struct import pack as _pack
import sys
@@ -258,7 +259,7 @@ class Crypto:
caead.op = op
caead.flags = CRD_F_IV_EXPLICIT
caead.flags = 0
- if src is not None and len(src) != 0:
+ if src:
src = str_to_ascii(src)
caead.len = len(src)
s = array.array('B', src)
@@ -287,7 +288,7 @@ class Crypto:
ioctl(_cryptodev, CIOCCRYPTAEAD, bytes(caead))
- if src is not None:
+ if src:
s = array_tobytes(s)
else:
s = empty_bytes()
@@ -358,6 +359,7 @@ class KATParser:
self._pending = None
self.fname = fname
self.fp = None
+ self.field_re = re.compile(r"\[(?P<field>[^]]+)\]")
def __enter__(self):
self.fp = open(self.fname)
@@ -372,24 +374,22 @@ class KATParser:
def __next__(self):
while True:
- didread = False
- if self._pending is not None:
- i = self._pending
- self._pending = None
- else:
- i = self.fp.readline()
- didread = True
-
- if didread and not i:
- return
-
- if not i.startswith('#') and i.strip():
- break
+ while True:
+ if self._pending is not None:
+ i = self._pending
+ self._pending = None
+ else:
+ i = self.fp.readline()
+ if not i:
+ return
+
+ if not i.startswith('#') and i.strip():
+ break
- if i[0] == '[':
- yield i[1:].split(']', 1)[0], self.fielditer()
- else:
- raise ValueError('unknown line: %r' % repr(i))
+ matches = self.field_re.match(i)
+ if matches is None:
+ raise ValueError("Unknown line: %r" % (i))
+ yield matches.group("field"), self.fielditer()
def eatblanks(self):
while True: