@@ -620,6 +620,7 @@ \subsection{Simple Encryption Demonstration}
620
620
(only on x86 with SSE4.1) &&&&& \\
621
621
\hline Twofish & twofish\_ desc & 16 & 16, 24, 32 & 16 & 7 \\
622
622
\hline DES & des\_ desc & 8 & 8 & 16 & 13 \\
623
+ \hline DES-X & desx\_ desc & 8 & 24 & 24 & 27 \\
623
624
\hline 3DES (EDE mode) & des3\_ desc & 8 & 16, 24 & 16 & 14 \\
624
625
\hline CAST5 (CAST-128) & cast5\_ desc & 8 & 5 $ \ldots $ 16 & 12, 16 & 15 \\
625
626
\hline Noekeon & noekeon\_ desc & 16 & 16 & 16 & 16 \\
@@ -8028,16 +8029,31 @@ \subsection{Depadding}
8028
8029
The following struct is used in various parts of the library that deals with user-passwords.
8029
8030
8030
8031
\begin {verbatim }
8031
- typedef struct {
8032
+ typedef struct password_ctx {
8032
8033
/**
8033
8034
Callback function that is called when a password is required.
8034
8035
8036
+ Please be aware that the library takes ownership of the pointer that is
8037
+ returned to the library via `str`.
8038
+ The data will be zeroed and `free()`'d as soon as it isn't required anymore.
8039
+ c.f. the documentation of the `free()` function pointer for details.
8040
+
8035
8041
@param str Pointer to pointer where the password will be stored.
8036
8042
@param len Pointer to the length of the password.
8037
8043
@param userdata `userdata` that was passed in the `password_ctx` struct.
8038
8044
@return CRYPT_OK on success
8039
8045
*/
8040
8046
int (*callback)(void **str, unsigned long *len, void *userdata);
8047
+ /**
8048
+ Optional free function to free the allocated buffer.
8049
+
8050
+ At the point where the value returned by `callback()` is not required
8051
+ anymore the library will free it by either calling this `free()` function
8052
+ or `XFREE()` in case this `free()` function is set to `NULL`.
8053
+
8054
+ @param str Pointer to the buffer to be free'd.
8055
+ */
8056
+ void (*free)(void *str);
8041
8057
/** Opaque `userdata` pointer passed when the callback is called */
8042
8058
void *userdata;
8043
8059
} password_ctx;
@@ -8049,12 +8065,17 @@ \subsection{Depadding}
8049
8065
the \textit {callback } pointer inside is \textit {NULL }.
8050
8066
8051
8067
The \textit {str } pointer is declared as a \textit {void } pointer, since passwords are not necessarily
8052
- always representable as a NUL-terminated C string. Therefor the user also has to provide the length of the
8068
+ always representable as a NUL-terminated C string. Therefore the user also has to provide the length of the
8053
8069
password via \textit {len }.
8054
8070
8055
8071
In order to prevent arbitrary limitations of the length of a password, the user is responsible for the
8056
8072
dynamic allocation of the buffer that holds the password. The library takes ownership of said buffer
8057
- and will zeroize it and call \texttt {XFREE } on it as soon as it doesn't require it anymore.
8073
+ and will zeroize it and will free it as soon as it doesn't require it anymore.
8074
+ Since the user can not necessarily ensure the usage of the same dynamic memory allocation API, as used
8075
+ within the library, the library provides a way to pass a custom `free()` function within the password context.
8076
+ In case the \textit {free } function pointer is set, the library will use said function to free
8077
+ the string \textit {str }. In case \textit {free } is NULL, the default `XFREE()` function will be used.
8078
+
8058
8079
8059
8080
An example usage is as follows:
8060
8081
0 commit comments