@@ -799,7 +799,7 @@ \subsection{Background}
799
799
$ P$ under the key $ k$ as $ E_k(P)$ . In some modes there exists an initialization vector denoted as $ C_{-1}$ .
800
800
801
801
\subsubsection {ECB Mode }
802
- \index {ECB mode }
802
+ \index {ECB Mode }
803
803
ECB or Electronic Codebook Mode is the simplest method to use. It is given as:
804
804
\begin {equation }
805
805
C_i = E_k(P_i)
@@ -808,7 +808,7 @@ \subsubsection{ECB Mode}
808
808
than once.
809
809
810
810
\subsubsection {CBC Mode }
811
- \index {CBC mode }
811
+ \index {CBC Mode }
812
812
CBC or Cipher Block Chaining mode is a simple mode designed to prevent trivial forms of replay and swap attacks on ciphers.
813
813
It is given as:
814
814
\begin {equation }
@@ -817,7 +817,7 @@ \subsubsection{CBC Mode}
817
817
It is important that the initialization vector be unique and preferably random for each message encrypted under the same key.
818
818
819
819
\subsubsection {CTR Mode }
820
- \index {CTR mode }
820
+ \index {CTR Mode }
821
821
CTR or Counter Mode is a mode which only uses the encryption function of the cipher. Given a initialization vector which is
822
822
treated as a large binary counter the CTR mode is given as:
823
823
\begin {eqnarray }
@@ -829,24 +829,24 @@ \subsubsection{CTR Mode}
829
829
as the block cipher is under a chosen plaintext attack (provided the initialization vector is unique).
830
830
831
831
\subsubsection {CFB Mode }
832
- \index {CFB mode }
832
+ \index {CFB Mode }
833
833
CFB or Ciphertext Feedback Mode is a mode akin to CBC. It is given as:
834
834
\begin {eqnarray }
835
835
C_i = P_i \oplus C_{-1} \nonumber \\
836
836
C_{-1} = E_k(C_i)
837
837
\end {eqnarray }
838
- Note that in this library the output feedback width is equal to the size of the block cipher. That is this mode is used
839
- to encrypt whole blocks at a time . However, the library will buffer data allowing the user to encrypt or decrypt partial
838
+ The library supports all output feedback widths as specified in NIST SP 800-38A: CFB1, CFB8, and CFB64 resp. CFB128, i.e. equal
839
+ to the size of the block cipher . The library will buffer data allowing the user to encrypt or decrypt partial
840
840
blocks without a delay. When this mode is first setup it will initially encrypt the initialization vector as required.
841
841
842
842
\subsubsection {OFB Mode }
843
- \index {OFB mode }
843
+ \index {OFB Mode }
844
844
OFB or Output Feedback Mode is a mode akin to CBC as well. It is given as:
845
845
\begin {eqnarray }
846
846
C_{-1} = E_k(C_{-1}) \nonumber \\
847
847
C_i = P_i \oplus C_{-1}
848
848
\end {eqnarray }
849
- Like the CFB mode the output width in CFB mode is the same as the width of the block cipher. OFB mode will also
849
+ The output width in OFB mode is the same as the width of the block cipher. OFB mode will also
850
850
buffer the output which will allow you to encrypt or decrypt partial blocks without delay.
851
851
852
852
\subsection {Choice of Mode }
@@ -874,8 +874,8 @@ \subsection{Ciphertext Stealing}
874
874
The more sane way to deal with partial blocks is to pad them with zeroes, and then use CBC normally.
875
875
876
876
\subsection {Initialization }
877
- \index {CBC Mode } \index {CTR Mode }
878
- \index {OFB Mode } \index {CFB Mode }
877
+ \index {CBC Initialization } \index {CTR Initialization }
878
+ \index {OFB Initialization } \index {CFB Initialization }
879
879
The library provides simple support routines for handling CBC, CTR, CFB, OFB and ECB encoded messages. Assuming the mode
880
880
you want is XXX there is a structure called \textit {symmetric\_ XXX } that will contain the information required to
881
881
use that mode. They have identical setup routines (except CTR and ECB mode):
@@ -913,6 +913,7 @@ \subsection{Initialization}
913
913
The routines return {\bf CRYPT\_ OK} if the cipher initialized correctly, otherwise, they return an error code.
914
914
915
915
\subsubsection {CTR Mode }
916
+ \index {CTR Initialization - specific}
916
917
In the case of CTR mode there is an additional parameter \textit {ctr\_ mode } which specifies the mode that the counter is to be used in.
917
918
If \textbf {CTR\_ COUNTER\_ LITTLE\_ ENDIAN } was specified then the counter will be treated as a little endian value. Otherwise, if
918
919
\textbf {CTR\_ COUNTER\_ BIG\_ ENDIAN } was specified the counter will be treated as a big endian value. As of v1.15 the RFC 3686 style of
@@ -942,6 +943,37 @@ \subsubsection{CTR Mode}
942
943
Changing the counter size has little (really no) effect on the performance of the CTR chaining mode. It is provided for compatibility
943
944
with other software (and hardware) which have smaller fixed sized counters.
944
945
946
+ \subsubsection {CFB Mode }
947
+ \index {CFB Initialization - specific}
948
+
949
+ In the case of the CFB mode there are multiple segment sizes possible. The most common one, where each processed segment equals the
950
+ block size of the underlying cipher, and two speciality modes. 1-bit CFB mode and 8-bit CFB mode, where each processed segment is
951
+ either 1 or 8 bits wide. Each segment denotes here one block cipher operation.
952
+ To produce 16 bytes AES-CFB output, a single AES operation is required.
953
+ To produce 16 bytes AES-CFB8 output, 16 AES operations are required.
954
+ To produce 16 bytes AES-CFB1 output, 128 AES operations are required.
955
+
956
+ The extended setup API looks as follows and accepts the values \textit {0, 1, 8 and 64 or 128 }. Whether \textit {64 } or \textit {128 } is
957
+ accepted depends on the block size of the underlying cipher, \textit {0 } will automatically select the block size as width.
958
+
959
+ \begin {small }
960
+ \begin {verbatim }
961
+ /**
962
+ Extended initialization of a CFB context
963
+ @param cipher The index of the cipher desired
964
+ @param IV The initialization vector
965
+ @param key The secret key
966
+ @param keylen The length of the secret key (octets)
967
+ @param num_rounds Number of rounds in the cipher desired (0 for default)
968
+ @param width The width of the mode (0 for default)
969
+ @param cfb The CFB state to initialize
970
+ @return CRYPT_OK if successful
971
+ */
972
+ int cfb_start_ex(int cipher, const unsigned char *IV, const unsigned char *key,
973
+ int keylen, int num_rounds, int width, symmetric_CFB *cfb);
974
+ \end {verbatim }
975
+ \end {small }
976
+
945
977
\subsection {Encryption and Decryption }
946
978
To actually encrypt or decrypt the following routines are provided:
947
979
\index {ecb\_ encrypt()} \index {ecb\_ decrypt()} \index {cfb\_ encrypt()} \index {cfb\_ decrypt()}
0 commit comments