Research Article

A Lightweight AES Coprocessor Based on RISC-V Custom Instructions

Algorithm 1

Software and hardware codesign.
Input: The address of all parameters, including the key, the plaintext (or message), the ciphertext (or tag) and the IV. Length of the plaintext (or message).
(1)Function AES_CBC_ENCRY(, ,,):
(2)ifthen
(3)  fordo
(4)   
(5)  end
(6)  CBC_INIT //The embedded custom instruction
(7)  LOOP //The embedded custom instruction
   / If the plaintext needs to be protected, then /
(8)  fordo
(9)   
(10)  end
(11)end
(12)Function AES_CMAC_AUTHEN :
(13)ifthen
(14)  CMAC_INIT //The embedded custom instruction
(15)  LOOP //The embedded custom instruction
(16)end
 / The encryption procedure is as follows /
 / Here is key agreement /
(17)KEY_UPDATE //The embedded custom instruction
 / Here is IV synchronisation and plaintext padding /
(18)AES_CBC_ENCRY(
 / Next is message authentication /
 / Here is message padding /
(19)AES_CMAC_AUTHEN