Skip to content

Commit 63db739

Browse files
author
Danielle Madeley
committed
Remaining sections of applied page
1 parent f4f5087 commit 63db739

File tree

2 files changed

+122
-1
lines changed

2 files changed

+122
-1
lines changed

docs/applied.rst

+117
Original file line numberDiff line numberDiff line change
@@ -724,25 +724,142 @@ A simple example:
724724
Signing/Verifying
725725
-----------------
726726

727+
Signing and verification mechanisms require two components:
728+
729+
* the cipher; and
730+
* the hashing function.
731+
732+
Raw versions for some mechanisms also exist. These require you to do your
733+
own hashing outside of PKCS #11.
734+
735+
Signing functions typically work on a finite length of data, so the signing
736+
of large amounts of data requires hashing with a secure one-way hash function.
737+
727738
AES
728739
~~~
729740

741+
A `MAC` is required for signing with AES. The default mechanism is
742+
`SHA512_HMAC` (aka HMAC-SHA512).
743+
744+
A number of other hashing functions and MACs are available depending on
745+
your implementation.
746+
747+
::
748+
749+
# Given a secret key, `key`
750+
signature = key.sign(data)
751+
752+
assert key.verify(data, signature)
753+
730754
RSA
731755
~~~
732756

757+
The default signing and verification mechanism for RSA is `RSA_SHA512_PKCS`.
758+
759+
Other mechanisms are available:
760+
761+
+-------------------+-------------------------------------------+
762+
| Mechanism | Notes |
763+
+===================+===========================================+
764+
| RSA_PKCS | No hashing. Supply your own. |
765+
+-------------------+-------------------------------------------+
766+
| SHA*_RSA_PKCS | SHAx message digesting. |
767+
+-------------------+-------------------------------------------+
768+
| RSA_PKCS_PSS | Not currently implemented. |
769+
+-------------------+ |
770+
| SHA*_RSA_PKCS_PSS | |
771+
+-------------------+-------------------------------------------+
772+
| RSA_9796 | ISO/IES 9796 RSA signing. |
773+
+-------------------+-------------------------------------------+
774+
| RSA_X_509 | X.509 (raw) RSA signing. |
775+
+-------------------+-------------------------------------------+
776+
| RSA_X9_31 | X9.31 RSA signing. |
777+
+-------------------+-------------------------------------------+
778+
779+
::
780+
781+
# Given a private key `private`
782+
signature = private.sign(data)
783+
784+
# Given a public key `public`
785+
assert public.verify(data, signature)
786+
733787
ECDSA
734788
~~~~~
735789

790+
The default signing and verification mechanism for ECDSA is `ECDSA_SHA512`.
791+
792+
Other mechanisms are available:
793+
794+
+------------+-------------------------------------------+
795+
| Mechanism | Notes |
796+
+============+===========================================+
797+
| ECDSA | No hashing. Input truncated to 1024 bits. |
798+
+------------+-------------------------------------------+
799+
| ECDSA_SHA* | ECDSA with SHAx message digesting. |
800+
+------------+-------------------------------------------+
801+
802+
::
803+
804+
# Given a private key `private`
805+
signature = private.sign(data)
806+
807+
# Given a public key `public`
808+
assert public.verify(data, signature)
736809

737810
Wrapping/Unwrapping
738811
-------------------
739812

813+
The expectation when using HSMs is that secret and private keys never leave
814+
the secure boundary of the HSM. However, there is a use case for transmitting
815+
secret and private keys over insecure mediums. We can do this using key
816+
wrapping.
817+
818+
Key wrapping is similar to encryption and decryption except instead of turning
819+
plaintext into crypttext it turns key objects into crypttext and vice versa.
820+
821+
Keys must be marked as `EXTRACTABLE` to remove them from the HSM, even wrapped.
822+
740823
AES
741824
~~~
742825

826+
The key we're wrapping can be any sensitive key, either a secret key or
827+
a private key. In this example we're extracting an AES secret key:
828+
829+
::
830+
831+
# Given two secret keys, `key1` and `key2`, we can extract an encrypted
832+
# version of `key2`
833+
crypttext = key1.wrap_key(key2)
834+
835+
Wrapping doesn't store any parameters about the keys. We must supply those
836+
to import the key.
837+
838+
::
839+
840+
key = key1.unwrap_key(ObjectClass.SECRET_KEY, KeyType.AES, crypttext)
841+
743842
RSA
744843
~~~
745844

845+
The key we're wrapping can be any sensitive key, either a secret key or
846+
a private key. In this example we're extracting an AES secret key:
847+
848+
::
849+
850+
# Given a public key, `public`, and a secret key `key`, we can extract an
851+
encrypted version of `key`
852+
crypttext = public.wrap_key(key)
853+
854+
Wrapping doesn't store any parameters about the keys. We must supply those
855+
to import the key.
856+
857+
::
858+
859+
# Given a private key, `private`, matching `public` above we can decrypt
860+
# and import `key`.
861+
key = private.unwrap_key(ObjectClass.SECRET_KEY, KeyType.AES, crypttext)
862+
746863
Deriving Shared Keys
747864
--------------------
748865

pkcs11/mechanisms.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,16 @@ class Mechanism(IntEnum):
405405
"""
406406

407407
ECDSA = 0x00001041
408+
"""ECDSA with no hashing. Input truncated to 1024-bits."""
408409
ECDSA_SHA1 = 0x00001042
409410
ECDSA_SHA224 = 0x00001043
410411
ECDSA_SHA256 = 0x00001044
411412
ECDSA_SHA384 = 0x00001045
412413
ECDSA_SHA512 = 0x00001046
413-
"""Default for signing/verification with :attr:`KeyType.EC` keys."""
414+
"""
415+
ECDSA with SHA512 hashing.
416+
Default for signing/verification with :attr:`KeyType.EC` keys.
417+
"""
414418

415419
ECDH1_DERIVE = 0x00001050
416420
"""

0 commit comments

Comments
 (0)