All,
I'm trying to add CRC32 HW support for stm32h7 and am somewhat confused
about how the crypto API is supposed to work, especially whether
CIOGSESSION should be called once per CRC, or once per update.
From what I can find the crypto API documentation is quite thin and
does not document the ioctl calls, their expected arguments, and what
they do, so I'm trying to reverse engineer that from the existing
testing code in nuttx-apps/testing/drivers/crypto.
In nuttx-apps/testing/drivers/crypto/crc32.c, after the crypto device is
open (and ioctl(CRIOCGET) returns the fd used by following ioctl()
calls), the first 7 testcases use a pattern of:
1. ioctl(CIOCGSESSION) to start a crypto session supplying a key
(initial value?)
2. ioctl(CIOCCRYPT, &cryp) where cryp.flag has COP_FLAG_UPDATE set to
update the CRC computation with supplied buffer (cryp.src is
address, cryp.len is byte length)
3. ioctl(CIOCCRYPT, &cryp) where cryp.flags is zero and cryp.mac points
to where the CRC32 value is copied to
Note the 7th testcase passes "1234567890" repeated eight times in one
update (e.g. cryp.src is address of buffer containing "1234567890"
repeated 8 times and cryp.len is 80) then calls ioctl(CIOCCRYPT) again
to extacts the CRC
For test case 8, it replicates test case 7, bit instead of a single 80
byte buffer, it makes eight update calls each with a 10-byte buffer of
"12345678890" which using software crypto produces the same CRC as test
case 7. However it does so with a ioctl(CIOCGSESSION) call before each
of the eight updates.
The software crypto implementation works for this case, but I'm trying
to understand is that by accident, or by design? If I move the
ioctl(CIOGSESSION) call to before the loop (so it is only done once
followed by 8 ioctl(CIOCCRYT) calls to add data to the CRC and final
ioctl(CIOCCRYPT) with flags set to zero to extract the computed CRC) -
it also works.
My question is whether the Crypto API expects a call ioctl(CIOCGSESSION)
before _each_ update, or should the code make a _single_ call to
ioctl(CIOCGSESSION) per CRC calculation(but followed by any number of
ioctl(CIOCCRYPT) calls with COP_FLAG_UPDATE bit set in cryp.flag).
Thanks in advance!
--
Peter Barada
[email protected]