Skip to content

Commit 9e459fa

Browse files
committed
[otbn] Specify the KMAC interface
This adapts the current simulator-only KMAC interface specification such that the new dynamic KMAC app interface can be used. Signed-off-by: Pascal Etterli <pascal.etterli@lowrisc.org>
1 parent 7c70c07 commit 9e459fa

4 files changed

Lines changed: 361 additions & 302 deletions

File tree

hw/ip/otbn/README.md

Lines changed: 52 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ See that document for integration overview within the broader top level system.
2929
* Full control-flow support with conditional branch and unconditional jump instructions, hardware loops, and hardware-managed call/return stacks.
3030
* Reduced, security-focused instruction set architecture for easier verification and the prevention of data leaks.
3131
* Built-in access to random numbers.
32+
* CSR / WSR based interface to KMAC HWIP to offload hashing operations.
3233

3334
## Description
3435

@@ -378,10 +379,10 @@ All read-write (RW) CSRs are set to 0 when OTBN starts an operation (when 1 is w
378379
<tr>
379380
<td>0x7D9</td>
380381
<td>RW</td>
381-
<td>KMAC_IF_STATUS</td>
382+
<td>KMAC_STATUS</td>
382383
<td>
383-
Write a 1 to bits 1 or 2 to clear the error bits.
384-
KMAC_IF_STATUS is a CSR that exposes status information for the OTBN-KMAC interface.
384+
KMAC_STATUS exposes status information for the OTBN-KMAC interface.
385+
All fields are read only except CTRL_ERROR, MSG_WRITE_ERROR, and RSP_ERROR, which are W1C.
385386
<table>
386387
<thead>
387388
<tr><th>Bit</th><th>Description</th></tr>
@@ -390,29 +391,35 @@ All read-write (RW) CSRs are set to 0 when OTBN starts an operation (when 1 is w
390391
<tr>
391392
<td>0</td>
392393
<td>
393-
MSG_WRITE_RDY indicates whether the KMAC_DATA_S0/1 WSR is ready for the next word.
394+
READY indicates whether the interface is ready to accept a command and/or new data in KMAC_DATA_S0/1.
394395
</td>
395396
</tr>
396397
<tr>
397398
<td>1</td>
398399
<td>
399-
MSG_SEND_ERROR (W1C) indicates whether an error occurred after issuing a message send command.
400+
CTRL_ERROR indicates whether a command was issued while the interface was not ready for it or the command violates the order. The command(s) raising this error are ignored. Is cleared (W1C) when SW writes a 1 to it.
400401
</td>
401402
</tr>
402403
<tr>
403404
<td>2</td>
404405
<td>
405-
MSG_WRITE_ERROR (W1C) indicates whether an error occurred after writing to the KMAC_DATA_S0/1 WSR.
406+
MSG_WRITE_ERROR indicates whether a write to KMAC_DATA_S0/1 occurred while the interface was not ready to accept new message data. Is cleared (W1C) when SW writes a 1 to it.
406407
</td>
407408
</tr>
408409
<tr>
409410
<td>3</td>
410411
<td>
411-
DIGEST_VALID indicates whether the 64 bit word in KMAC_DATA_S0/1 WSR is valid.
412+
RSP_VALID indicates that the lowest 64 bit words in KMAC_DATA_S0/1 contain valid data (actual digest data is only valid if RSP_ERROR is not 1). Is cleared once KMAC_DATA_S0 and KMAC_DATA_S1 have been read.
412413
</td>
413414
</tr>
414415
<tr>
415-
<td>31:4</td>
416+
<td>4</td>
417+
<td>
418+
RSP_ERROR is set to 1 and held when a response is received that signals an error on the KMAC HWIP side. If 1, all received digest data (incl. previously received) must be considered as invalid. Is cleared (W1C) when SW writes a 1 to it.
419+
</td>
420+
</tr>
421+
<tr>
422+
<td>31:5</td>
416423
<td>
417424
Reserved. Always reads as 0. Any write is ignored.
418425
</td>
@@ -424,9 +431,10 @@ All read-write (RW) CSRs are set to 0 when OTBN starts an operation (when 1 is w
424431
<tr>
425432
<td>0x7DA</td>
426433
<td>RW</td>
427-
<td>KMAC_INTR</td>
434+
<td>KMAC_CTRL</td>
428435
<td>
429-
KMAC_INTR is a CSR that exposes the KMAC_ERROR interrupt of the KMAC HWIP.
436+
The KMAC control register is used to control the KMAC interface.
437+
Always reads as 0.
430438
<table>
431439
<thead>
432440
<tr><th>Bit</th><th>Description</th></tr>
@@ -435,141 +443,75 @@ All read-write (RW) CSRs are set to 0 when OTBN starts an operation (when 1 is w
435443
<tr>
436444
<td>0</td>
437445
<td>
438-
KMAC_ERROR (W1C) indicates whether an error occurred in the KMAC HWIP.
446+
START: Writing 1 to this bit issues a START command.
439447
</td>
440448
</tr>
441449
<tr>
442-
<td>31:1</td>
450+
<td>1</td>
443451
<td>
444-
Reserved. Always reads as 0. Any write is ignored.
452+
SEND: Writing 1 to this bit starts sending the current message in KMAC_DATA_S0/1. If `KMAC_STRB` is partial (i.e. not all bytes are valid), issuing this command will simultaneously also send the PROCESS command.
445453
</td>
446454
</tr>
447-
</tbody>
448-
</table>
449-
</td>
450-
</tr>
451-
<tr>
452-
<td>0x7DB</td>
453-
<td>RW</td>
454-
<td>KMAC_CFG</td>
455-
<td>
456-
A configuration register for the KMAC interface.
457-
The encodings for the fields are equivalent to the encodings for the CFG_SHADOWED register in the KMAC HWIP.
458-
<table>
459-
<thead>
460-
<tr><th>Bit</th><th>Description</th></tr>
461-
</thead>
462-
<tbody>
463455
<tr>
464-
<td>0</td>
456+
<td>2</td>
465457
<td>
466-
KMAC_EN enables keyed operation in the KMAC HWIP (kmac_en = 0/1).
458+
PROCESS: Writing 1 to this bit issues a PROCESS command. Can be issued to terminate the message phase if the last message is not a partial message (which will automatically trigger the PROCESS command).
467459
</td>
468460
</tr>
469461
<tr>
470-
<td>3:1</td>
462+
<td>3</td>
471463
<td>
472-
STRENGTH allows OTBN to select the desired security strength (kstrength = L128 / L224 / L256 / L384 / L512).
464+
DONE: Writing 1 to this bit issues a DONE command.
473465
</td>
474466
</tr>
475467
<tr>
476-
<td>5:4</td>
468+
<td>9:4</td>
477469
<td>
478-
MODE allows OTBN to set the KMAC hashing mode (mode = SHAKE / cSHAKE / SHA3).
470+
Reserved. Any write is ignored. Always reads as 0.
479471
</td>
480472
</tr>
481473
<tr>
482-
<td>31:6</td>
474+
<td>10</td>
483475
<td>
484-
Reserved. Always reads as 0. Any write is ignored.
476+
EN_XOF enables the eXtendable Output Function (XOF) operation. If 1, XOF operation is enabled and the KMAC HWIP will automatically trigger a RUN command once the full rate has been pushed. If 0, KMAC HWIP will only push the first rate, and no other digest will be produced. Usually enabled for SHAKE and cSHAKE and disabled for SHA3 and KMAC modes.
485477
</td>
486478
</tr>
487-
</tbody>
488-
</table>
489-
</td>
490-
</tr>
491-
<tr>
492-
<td>0x7DC</td>
493-
<td>RW</td>
494-
<td>KMAC_MSG_SEND</td>
495-
<td>
496-
A command register to send a message to KMAC.
497-
Reads from this register always return a 0.
498-
<table>
499-
<thead>
500-
<tr><th>Bit</th><th>Description</th></tr>
501-
</thead>
502-
<tbody>
503479
<tr>
504-
<td>0</td>
480+
<td>13:11</td>
505481
<td>
506-
MSG_SEND can be set to send the contents of KMAC_DATA_S0 and KMAC_DATA_S1 to KMAC.
482+
STRENGTH defines the security strength of the operation. Valid values are L128, L224, L256, L384, and L512. See KMAC HWIP for encoding of values. The selected value must be compatible with chosen mode (see corresponding standards). If STRENGTH = L224 and MODE = SHA3, the digest size is not a multiple of 64 bits. As of this, in the last digest response (response 4) only the lower 32 bits contain valid data.
507483
</td>
508484
</tr>
509485
<tr>
510-
<td>31:1</td>
486+
<td>15:14</td>
511487
<td>
512-
Reserved. Always reads as 0. Any write is ignored.
488+
MODE defines the hashing mode. This can be SHA3, SHAKE, cSHAKE, or KMAC. See KMAC HWIP for encoding of values. Note, cSHAKE uses prefix from KMAC HWIP CSRs (configured by SW), and KMAC always uses hard coded "KMAC" prefix.
513489
</td>
514490
</tr>
515-
</tbody>
516-
</table>
517-
</td>
518-
</tr>
519-
<tr>
520-
<td>0x7DD</td>
521-
<td>RW</td>
522-
<td>KMAC_CMD</td>
523-
<td>
524-
The encodings for the commands are equivalent to the encodings for the CMD register in the KMAC HWIP.
525-
Reads from this register always return a 0.
526-
<table>
527-
<thead>
528-
<tr><th>Bit</th><th>Description</th></tr>
529-
</thead>
530-
<tbody>
531491
<tr>
532-
<td>5:0</td>
492+
<td>31:16</td>
533493
<td>
534-
CMD is the KMAC command field used to issue START, PROCESS, RUN and DONE commands to KMAC.
535-
</td>
536-
</tr>
537-
<tr>
538-
<td>31:6</td>
539-
<td>
540-
Reserved. Always reads as 0. Any write is ignored.
494+
Reserved. Any write is ignored.
541495
</td>
542496
</tr>
543497
</tbody>
544498
</table>
545499
</td>
546500
</tr>
547501
<tr>
548-
<td>0x7DE</td>
502+
<td>0x7DB</td>
549503
<td>RW</td>
550-
<td>KMAC_BYTE_STROBE</td>
504+
<td>KMAC_STRB</td>
551505
<td>
552-
The input bytes of KMAC_DATA_S0/1 that are valid and should be consumed by KMAC.
506+
Defines which of the bytes of KMAC_DATA_S0/1 are valid and should be sent towards the KMAC HWIP.
507+
Each bit corresponds to one byte in KMAC_DATA_S0/1, with bit 0 corresponding to the least significant byte.
553508
<br>
554-
For all message chunks except the final one, BYTE_STROBE must be programmed to all ones, indicating that all bytes in KMAC_DATA are valid. For the final message chunk, selected bits may be cleared to indicate unused bytes.
509+
For all message chunks except the final one, BYTE_STROBE must be programmed to all ones, indicating that all bytes in KMAC_DATA are valid.
510+
For the final message chunk, selected bits may be cleared to indicate unused bytes.
555511
Any cleared bits must correspond to the most-significant bytes only, that is, the mask must be contiguous, with no zero bit followed by a one at a higher significance.
556-
This needs to be the case, because that's how SHA3 inside KMAC expects the data.
557512
If a non contiguous strobe is defined the behaviour is undefined.
558513
<br>
559-
Reads from this register return the current configuration of the KMAC_BYTE_STROBE CSR.
560-
<table>
561-
<thead>
562-
<tr><th>Bit</th><th>Description</th></tr>
563-
</thead>
564-
<tbody>
565-
<tr>
566-
<td>31:0</td>
567-
<td>
568-
BYTE_STROBE is the KMAC byte strobe field.
569-
</td>
570-
</tr>
571-
</tbody>
572-
</table>
514+
Reads from this register return the current strobe.
573515
</td>
574516
</tr>
575517
<tr>
@@ -636,75 +578,6 @@ All read-write (RW) CSRs are set to 0 when OTBN starts an operation (when 1 is w
636578
Reads never stall.
637579
</td>
638580
</tr>
639-
<tr>
640-
<td>0xFC2</td>
641-
<td>RO</td>
642-
<td>KMAC_STATUS</td>
643-
<td>
644-
Writes to this CSR are always ignored.
645-
This CSR exposes the internal state of the SHA3 FSM within KMAC.
646-
<table>
647-
<thead>
648-
<tr><th>Bit</th><th>Description</th></tr>
649-
</thead>
650-
<tbody>
651-
<tr>
652-
<td>0</td>
653-
<td>
654-
SHA3_IDLE indicates whether the SHA3 core is in the idle state.
655-
</td>
656-
</tr>
657-
<tr>
658-
<td>1</td>
659-
<td>
660-
SHA3_ABSORB indicates whether the SHA3 core is in the absorb state.
661-
</td>
662-
</tr>
663-
<tr>
664-
<td>2</td>
665-
<td>
666-
SHA3_SQUEEZE indicates whether the SHA3 core is in the squeeze state.
667-
</td>
668-
</tr>
669-
<tr>
670-
<td>31:3</td>
671-
<td>
672-
Reserved. Always reads as 0. Any write is ignored.
673-
</td>
674-
</tr>
675-
</tbody>
676-
</table>
677-
</td>
678-
</tr>
679-
<tr>
680-
<td>0xFC3</td>
681-
<td>RO</td>
682-
<td>KMAC_ERROR</td>
683-
<td>
684-
Writes to this register are ignored.
685-
This register exposes the error code from the KMAC HWIP ERR_CODE register.
686-
No other information from the KMAC HWIP ERR_CODE register is exposed.
687-
<table>
688-
<thead>
689-
<tr><th>Bit</th><th>Description</th></tr>
690-
</thead>
691-
<tbody>
692-
<tr>
693-
<td>7:0</td>
694-
<td>
695-
ERROR_CODE contains the error code coming directly from the KMAC HWIP.
696-
</td>
697-
</tr>
698-
<tr>
699-
<td>31:8</td>
700-
<td>
701-
Reserved. Always reads as 0. Any write is ignored.
702-
</td>
703-
</tr>
704-
</tbody>
705-
</table>
706-
</td>
707-
</tr>
708581
<tr>
709582
<td>0xFCA</td>
710583
<td>RO</td>
@@ -870,16 +743,18 @@ All read-write (RW) WSRs are set to 0 when OTBN starts an operation (when 1 is w
870743
<td>RW</td>
871744
<td><a name="kmac-data-s0">KMAC_DATA_S0</a></td>
872745
<td>
873-
KMAC_DATA_S0 is the first 256-bit share of the masked message or digest interface.
746+
KMAC_DATA_S0 and KMAC_DATA_S1 are used to send message parts towards the KMAC HWIP as well as to receive the resulting digest.
874747
<br>
875-
For masked operations, provide the first share here and the second share in KMAC_DATA_S1.
748+
For sending message parts, i.e., when writing to the WSRs, the WSRs are 256-bit wide.
749+
The message is sent towards the KMAC HWIP in 64-bit parts, starting with the least significant word.
750+
To send a masked message, provide the first share in KMAC_DATA_S0 and the second share in KMAC_DATA_S1.
751+
If no masking is required, set one share to the plaintext data and the other share to all-zeros.
876752
<br>
877-
If masking is not required:
878-
- Set this share to the plaintext data.
879-
- Set the other share to all-zeros.
753+
When receiving the digest, i.e., reading from the WSRs, the digest data is only 64-bit wide and is placed in the least significant 64 bits while the other bits read as `'0`.
754+
If a valid response is present (indicated by KMAC_STATUS.RSP_VALID), once both KMAC_DATA_S0 and KMAC_DATA_S1 are read, the KMAC interface starts accepting the next digest part.
880755
<br>
881-
The digest data is provided in chunks of 64 bits at a time.
882-
For plaintext retrieval of the digest, software must XOR the values from KMAC_DATA_S0 and KMAC_DATA_S1.
756+
The provided digest is always shared, even if no masking is used for the message.
757+
To retrieve the plaintext digest, software must XOR the values from KMAC_DATA_S0 and KMAC_DATA_S1.
883758
<table>
884759
<thead>
885760
<tr><th>Bit</th><th>Description</th></tr>
@@ -906,35 +781,7 @@ All read-write (RW) WSRs are set to 0 when OTBN starts an operation (when 1 is w
906781
<td>RW</td>
907782
<td><a name="kmac-data-s1">KMAC_DATA_S1</a></td>
908783
<td>
909-
KMAC_DATA_S1 is the second 256-bit share of the masked message or digest interface.
910-
<br>
911-
For masked operations, provide the second share here and the second share in KMAC_DATA_S0.
912-
<br>
913-
If masking is not required:
914-
- Set this share to the plaintext data.
915-
- Set the other share to all-zeros.
916-
<br>
917-
The digest data is provided in chunks of 64 bits at a time.
918-
For plaintext retrieval of the digest, software must XOR the values from KMAC_DATA_S0 and KMAC_DATA_S1.
919-
<table>
920-
<thead>
921-
<tr><th>Bit</th><th>Description</th></tr>
922-
</thead>
923-
<tbody>
924-
<tr>
925-
<td>63:0</td>
926-
<td>
927-
Write: Least significant word of the message share. Read: Current 64-bit word of the digest share.
928-
</td>
929-
</tr>
930-
<tr>
931-
<td>255:64</td>
932-
<td>
933-
Write: Words 1-3 of the message share. Read: Returns `0`. Digest shares are read out via the least significant word only.
934-
</td>
935-
</tr>
936-
</tbody>
937-
</table>
784+
KMAC_DATA_S1 is the counterpart of KMAC_DATA_S0, see its documentation for details.
938785
</td>
939786
</tr>
940787
<tr>

0 commit comments

Comments
 (0)