@@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};
1515
1616use crate :: record_layer:: aead:: AeadError ;
1717
18- /// Maximum key share power .
18+ /// Maximum exponent used in GHASH .
1919const MAX_POWER : usize = 1026 ;
2020
2121#[ async_trait]
@@ -26,13 +26,13 @@ pub(crate) trait Ghash {
2626 /// Preprocesses GHASH.
2727 async fn preprocess ( & mut self , ctx : & mut Context ) -> Result < ( ) , GhashError > ;
2828
29- /// Sets the key for the hash function.
29+ /// Sets the additive key share for the hash function.
3030 fn set_key ( & mut self , key : Vec < u8 > ) -> Result < ( ) , GhashError > ;
3131
3232 /// Sets up GHASH, computing the key shares.
3333 async fn setup ( & mut self , ctx : & mut Context ) -> Result < ( ) , GhashError > ;
3434
35- /// Computes the GHASH tag.
35+ /// Computes the GHASH tag share .
3636 fn compute ( & self , input : & [ u8 ] ) -> Result < Vec < u8 > , GhashError > ;
3737}
3838
@@ -80,12 +80,13 @@ where
8080{
8181 fn alloc ( & mut self ) -> Result < ( ) , GhashError > {
8282 if !self . alloc {
83- // We need only half the number of `MAX_POWER` M2As because of the free
84- // squaring trick and we need one extra A2M conversion in the beginning.
83+ // Odd powers are computed using M2A, even powers are computed
84+ // locally. We need one extra A2M conversion in the beginning.
8585 // Both M2A and A2M, each require a single OLE.
8686 AdditiveToMultiplicative :: < Gf2_128 > :: alloc ( & mut self . converter , 1 )
8787 . map_err ( GhashError :: conversion) ?;
8888
89+ // -1 because the odd power H^1 is already known at this point.
8990 MultiplicativeToAdditive :: < Gf2_128 > :: alloc ( & mut self . converter , ( MAX_POWER / 2 ) - 1 )
9091 . map_err ( GhashError :: conversion) ?;
9192
@@ -128,7 +129,7 @@ where
128129
129130 async fn setup ( & mut self , ctx : & mut Context ) -> Result < ( ) , GhashError > {
130131 let State :: SetKey { key : add_key } = self . state . take ( ) else {
131- return Err ( GhashError :: state ( "can not setup before key is set" ) ) ;
132+ return Err ( GhashError :: state ( "cannot setup before key is set" ) ) ;
132133 } ;
133134
134135 let mut mult_key = self
@@ -156,9 +157,9 @@ where
156157 * acc = power_n * mult_key;
157158 Some ( power_n)
158159 } )
159- // Start from H^3
160+ // Start from H^3.
160161 . skip ( 2 )
161- // Skip even powers
162+ // Skip even powers.
162163 . step_by ( 2 )
163164 . collect ( ) ;
164165
@@ -249,7 +250,7 @@ fn compute_shares(key: Gf2_128, odd_powers: &[Gf2_128]) -> Vec<Gf2_128> {
249250 let base = shares[ i / 2 - 1 ] ;
250251 shares. push ( base * base) ;
251252 } else {
252- // Odd power
253+ // Odd power.
253254 shares. push ( odd_powers[ odd_idx] ) ;
254255 odd_idx += 1 ;
255256 }
@@ -423,7 +424,7 @@ mod tests {
423424 let sender_key: u128 = rng. random ( ) ;
424425 let receiver_key: u128 = h ^ sender_key;
425426
426- // Message length is not a multiple of the block length
427+ // Message length is not a multiple of the block length.
427428 let message: Vec < u8 > = ( 0 ..14 ) . map ( |_| rng. random ( ) ) . collect ( ) ;
428429
429430 let ( mut sender, mut receiver) = create_pair ( ) ;
0 commit comments