Commit c7bb35a3 authored by Stephane Glondu's avatar Stephane Glondu

Distinguish the two hash functions used in PKI encryption

parent 00996b77
...@@ -347,13 +347,13 @@ To compute the \texttt{encrypted\_msg}: ...@@ -347,13 +347,13 @@ To compute the \texttt{encrypted\_msg}:
\item compute $\textsf{beta}=\textsf{ek}^r\times g^s$ \item compute $\textsf{beta}=\textsf{ek}^r\times g^s$
\item compute $\textsf{data}$ as the hexadecimal encoding of the (symmetric) \item compute $\textsf{data}$ as the hexadecimal encoding of the (symmetric)
encryption of $M$ using AES in CCM mode with encryption of $M$ using AES in CCM mode with
$\textsf{SHA256}(g^s)$ as the key and $\textsf{SHA256}(g^r)$ as the $\textsf{SHA256}(\texttt{key|}g^s)$ as the key and $\textsf{SHA256}(\texttt{iv|}g^r)$ as the
initialization vector (where numbers are written in base 10) initialization vector (where numbers are written in base 10)
\end{enumerate} \end{enumerate}
To decrypt an \texttt{encrypted\_msg} using a decryption key \textsf{dk}: To decrypt an \texttt{encrypted\_msg} using a decryption key \textsf{dk}:
\begin{enumerate} \begin{enumerate}
\item compute the symmetric key as $\textsf{SHA256}(\textsf{beta}/(\textsf{alpha}^{\textsf{dk}}))$ \item compute the symmetric key as $\textsf{SHA256}(\texttt{key|}\textsf{beta}/(\textsf{alpha}^{\textsf{dk}}))$
\item compute the initialization vector as $\textsf{SHA256}(\textsf{alpha})$ \item compute the initialization vector as $\textsf{SHA256}(\texttt{iv|}\textsf{alpha})$
\item decrypt $\textsf{data}$ \item decrypt $\textsf{data}$
\end{enumerate} \end{enumerate}
......
...@@ -132,8 +132,8 @@ module MakePKI (G : GROUP) (M : RANDOM) = struct ...@@ -132,8 +132,8 @@ module MakePKI (G : GROUP) (M : RANDOM) = struct
let key = G.(g **~ key) in let key = G.(g **~ key) in
let y_alpha = G.(g **~ r) in let y_alpha = G.(g **~ r) in
let y_beta = G.((y **~ r) *~ key) in let y_beta = G.((y **~ r) *~ key) in
let key = sha256_hex (G.to_string key) in let key = sha256_hex ("key|" ^ G.to_string key) in
let iv = sha256_hex (G.to_string y_alpha) in let iv = sha256_hex ("iv|" ^ G.to_string y_alpha) in
let y_data = Platform.encrypt ~key ~iv ~plaintext in let y_data = Platform.encrypt ~key ~iv ~plaintext in
let msg = {y_alpha; y_beta; y_data} in let msg = {y_alpha; y_beta; y_data} in
M.return (string_of_encrypted_msg G.write msg) M.return (string_of_encrypted_msg G.write msg)
...@@ -142,8 +142,8 @@ module MakePKI (G : GROUP) (M : RANDOM) = struct ...@@ -142,8 +142,8 @@ module MakePKI (G : GROUP) (M : RANDOM) = struct
let decrypt x msg = let decrypt x msg =
let {y_alpha; y_beta; y_data} = encrypted_msg_of_string G.read msg in let {y_alpha; y_beta; y_data} = encrypted_msg_of_string G.read msg in
let key = sha256_hex G.(to_string (y_beta *~ invert (y_alpha **~ x))) in let key = sha256_hex G.("key|" ^ to_string (y_beta *~ invert (y_alpha **~ x))) in
let iv = sha256_hex (G.to_string y_alpha) in let iv = sha256_hex ("iv|" ^ G.to_string y_alpha) in
Platform.decrypt ~key ~iv ~ciphertext:y_data Platform.decrypt ~key ~iv ~ciphertext:y_data
let make_cert ~sk ~dk = let make_cert ~sk ~dk =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment