You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
@@ -29,6 +29,7 @@ See that document for integration overview within the broader top level system.
29
29
* Full control-flow support with conditional branch and unconditional jump instructions, hardware loops, and hardware-managed call/return stacks.
30
30
* Reduced, security-focused instruction set architecture for easier verification and the prevention of data leaks.
31
31
* Built-in access to random numbers.
32
+
* CSR / WSR based interface to KMAC HWIP to offload hashing operations.
32
33
33
34
## Description
34
35
@@ -378,10 +379,10 @@ All read-write (RW) CSRs are set to 0 when OTBN starts an operation (when 1 is w
378
379
<tr>
379
380
<td>0x7D9</td>
380
381
<td>RW</td>
381
-
<td>KMAC_IF_STATUS</td>
382
+
<td>KMAC_STATUS</td>
382
383
<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 RSP_ERROR, CTRL_ERROR, and MSG_WRITE_ERROR which are W1C.
385
386
<table>
386
387
<thead>
387
388
<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
390
391
<tr>
391
392
<td>0</td>
392
393
<td>
393
-
MSG_WRITE_RDY indicates whether the KMAC_DATA_S0/1 WSR is ready for the next word.
394
+
READY is 1 when the interface is ready to accept a command and/or new data in KMAC_DATA_S0/1.
394
395
</td>
395
396
</tr>
396
397
<tr>
397
398
<td>1</td>
398
399
<td>
399
-
MSG_SEND_ERROR (W1C) indicates whether an error occurred after issuing a message send command.
400
+
RSP_VALID is 1 when 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). This flag is cleared once both, KMAC_DATA_S0 and KMAC_DATA_S1, have been read or when a DONE command is issued.
400
401
</td>
401
402
</tr>
402
403
<tr>
403
404
<td>2</td>
404
405
<td>
405
-
MSG_WRITE_ERROR (W1C) indicates whether an error occurred after writing to the KMAC_DATA_S0/1 WSR.
406
+
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. This flag is cleared (W1C) when SW writes a 1 to it.
406
407
</td>
407
408
</tr>
408
409
<tr>
409
410
<td>3</td>
410
411
<td>
411
-
DIGEST_VALID indicates whether the 64 bit word in KMAC_DATA_S0/1 WSR is valid.
412
+
CTRL_ERROR is 1 when a command was issued while the interface was not ready for it or the command violated the expected command order (for example, a SEND command is issued before a START command). A command raising this error is ignored. This flag is cleared (W1C) when SW writes a 1 to it.
412
413
</td>
413
414
</tr>
414
415
<tr>
415
-
<td>31:4</td>
416
+
<td>4</td>
417
+
<td>
418
+
MSG_WRITE_ERROR is 1 when a write to KMAC_DATA_S0/1, KMAC_STRB or KMAC_CFG occurred while the interface was not ready to accept new message data or a new configuration. It is also set when a write to KMAC_DATA_S0/1 collides with an incoming digest response. This flag is cleared (W1C) when SW writes a 1 to it.
419
+
</td>
420
+
</tr>
421
+
<tr>
422
+
<td>31:5</td>
416
423
<td>
417
424
Reserved. Always reads as 0. Any write is ignored.
418
425
</td>
@@ -424,9 +431,10 @@ All read-write (RW) CSRs are set to 0 when OTBN starts an operation (when 1 is w
424
431
<tr>
425
432
<td>0x7DA</td>
426
433
<td>RW</td>
427
-
<td>KMAC_INTR</td>
434
+
<td>KMAC_CTRL</td>
428
435
<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.
430
438
<table>
431
439
<thead>
432
440
<tr><th>Bit</th><th>Description</th></tr>
@@ -435,66 +443,49 @@ All read-write (RW) CSRs are set to 0 when OTBN starts an operation (when 1 is w
435
443
<tr>
436
444
<td>0</td>
437
445
<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.
439
447
</td>
440
448
</tr>
441
449
<tr>
442
-
<td>31:1</td>
450
+
<td>1</td>
443
451
<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.
445
453
</td>
446
454
</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>
463
455
<tr>
464
-
<td>0</td>
456
+
<td>2</td>
465
457
<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.
467
459
</td>
468
460
</tr>
469
461
<tr>
470
-
<td>3:1</td>
462
+
<td>3</td>
471
463
<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.
473
465
</td>
474
466
</tr>
475
467
<tr>
476
-
<td>5:4</td>
468
+
<td>4</td>
477
469
<td>
478
-
MODE allows OTBN to set the KMAC hashing mode (mode = SHAKE / cSHAKE / SHA3).
470
+
CLOSE: Writing 1 to this bit issues a CLOSE command.
479
471
</td>
480
472
</tr>
481
473
<tr>
482
-
<td>31:6</td>
474
+
<td>31:5</td>
483
475
<td>
484
-
Reserved. Always reads as 0. Any write is ignored.
476
+
Reserved. Any write is ignored. Always reads as 0.
485
477
</td>
486
478
</tr>
487
479
</tbody>
488
480
</table>
489
481
</td>
490
482
</tr>
491
483
<tr>
492
-
<td>0x7DC</td>
484
+
<td>0x7DB</td>
493
485
<td>RW</td>
494
-
<td>KMAC_MSG_SEND</td>
486
+
<td>KMAC_CFG</td>
495
487
<td>
496
-
A command register to send a message to KMAC.
497
-
Reads from this register always return a 0.
488
+
The KMAC configuration register is used to set the hashing session configuration.
498
489
<table>
499
490
<thead>
500
491
<tr><th>Bit</th><th>Description</th></tr>
@@ -503,73 +494,41 @@ All read-write (RW) CSRs are set to 0 when OTBN starts an operation (when 1 is w
503
494
<tr>
504
495
<td>0</td>
505
496
<td>
506
-
MSG_SEND can be set to send the contents of KMAC_DATA_S0 and KMAC_DATA_S1 to KMAC.
497
+
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.
507
498
</td>
508
499
</tr>
509
500
<tr>
510
-
<td>31:1</td>
511
-
<td>
512
-
Reserved. Always reads as 0. Any write is ignored.
513
-
</td>
514
-
</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>
531
-
<tr>
532
-
<td>5:0</td>
501
+
<td>3:1</td>
533
502
<td>
534
-
CMD is the KMAC command field used to issue START, PROCESS, RUN and DONE commands to KMAC.
503
+
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 such, only the lower 32 bits of the last digest response (4th beat of the digest response) contain valid data.
535
504
</td>
536
505
</tr>
537
506
<tr>
538
-
<td>31:6</td>
507
+
<td>5:4</td>
539
508
<td>
540
-
Reserved. Always reads as 0. Any write is ignored.
509
+
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.
541
510
</td>
542
511
</tr>
543
512
</tbody>
544
513
</table>
545
514
</td>
546
515
</tr>
547
516
<tr>
548
-
<td>0x7DE</td>
517
+
<td>0x7DC</td>
549
518
<td>RW</td>
550
-
<td>KMAC_BYTE_STROBE</td>
519
+
<td>KMAC_STRB</td>
551
520
<td>
552
-
The input bytes of KMAC_DATA_S0/1 that are valid and should be consumed by KMAC.
521
+
Defines which of the bytes of KMAC_DATA_S0/1 are valid and should be sent towards the KMAC HWIP.
522
+
Each bit corresponds to one byte in KMAC_DATA_S0/1, with bit 0 corresponding to the least significant byte.
523
+
May only be written to when KMAC_STATUS.READY = 1.
553
524
<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.
555
-
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.
525
+
For all messages except the final one, KMAC_STRB must be programmed to all ones, indicating that all bytes in KMAC_DATA_S0/1 are valid.
526
+
The final message can be shorter.
527
+
It can be 1 to 32 bytes long which must be encoded in KMAC_STRB by setting the corresponding number of least significant bits to 1.
528
+
The strobe therefore must always be contiguous and LSB aligned.
557
529
If a non contiguous strobe is defined the behaviour is undefined.
558
530
<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>
531
+
Reads from this register return the current strobe.
573
532
</td>
574
533
</tr>
575
534
<tr>
@@ -636,75 +595,6 @@ All read-write (RW) CSRs are set to 0 when OTBN starts an operation (when 1 is w
636
595
Reads never stall.
637
596
</td>
638
597
</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>
708
598
<tr>
709
599
<td>0xFCA</td>
710
600
<td>RO</td>
@@ -870,16 +760,19 @@ All read-write (RW) WSRs are set to 0 when OTBN starts an operation (when 1 is w
870
760
<td>RW</td>
871
761
<td><a name="kmac-data-s0">KMAC_DATA_S0</a></td>
872
762
<td>
873
-
KMAC_DATA_S0 is the first 256-bit share of the masked message or digest interface.
763
+
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.
874
764
<br>
875
-
For masked operations, provide the first share here and the second share in KMAC_DATA_S1.
765
+
For sending message parts, i.e., when writing to the WSRs, the WSRs are 256-bit wide.
766
+
The message is sent towards the KMAC HWIP in 64-bit parts, starting with the least significant word.
767
+
To send a masked message, provide the first share in KMAC_DATA_S0 and the second share in KMAC_DATA_S1.
768
+
If no masking is required, set one share to the plaintext data and the other share to all-zeros.
876
769
<br>
877
-
If masking is not required:
878
-
- Set this share to the plaintext data.
879
-
- Set the other share to all-zeros.
770
+
When reading from the WSRs, the digest data is only 64-bit wide and is placed in the least significant 64 bits.
771
+
The upper bits [255:64] are not updated by the digest response.
772
+
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.
880
773
<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.
774
+
The provided digest is always in Boolean shared representation.
775
+
To retrieve the plaintext digest, software must XOR the values from KMAC_DATA_S0 and KMAC_DATA_S1.
883
776
<table>
884
777
<thead>
885
778
<tr><th>Bit</th><th>Description</th></tr>
@@ -894,7 +787,7 @@ All read-write (RW) WSRs are set to 0 when OTBN starts an operation (when 1 is w
894
787
<tr>
895
788
<td>255:64</td>
896
789
<td>
897
-
Write: Words 1-3 of the message share. Read: Returns `0`. Digest shares are read out via the least significant word only.
790
+
Write: Words 1-3 of the message share. Read: Digest shares are read out via the least significant word only, these bits are not affected by a digest response and keep the value written by SW.
898
791
</td>
899
792
</tr>
900
793
</tbody>
@@ -906,35 +799,7 @@ All read-write (RW) WSRs are set to 0 when OTBN starts an operation (when 1 is w
906
799
<td>RW</td>
907
800
<td><a name="kmac-data-s1">KMAC_DATA_S1</a></td>
908
801
<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>
802
+
KMAC_DATA_S1 is the counterpart of KMAC_DATA_S0: see its documentation for details.
0 commit comments