1414
1515namespace CompactMPC . ObliviousTransfer
1616{
17+ // note(lumip): the implementation does not seem to actually follow any construction given in
18+ // [Moni Naor and Benny Pinkas: Computationally Secure Oblivious Transfer. 2005.]
19+ // so what is the exact reference here?
20+ // looks like
21+ // [Moni Naor and Benny Pinkas: Efficient oblivious transfer protocols 2001.]
1722 public class NaorPinkasObliviousTransfer : GeneralizedObliviousTransfer
1823 {
1924 private SecurityParameters _parameters ;
@@ -37,6 +42,7 @@ public NaorPinkasObliviousTransfer(SecurityParameters parameters, CryptoContext
3742
3843 public override async Task SendAsync ( IMessageChannel channel , Quadruple < byte [ ] > [ ] options , int numberOfInvocations , int numberOfMessageBytes )
3944 {
45+ // note(lumip): common argument verification code.. wrap into a common method in a base class?
4046 if ( options . Length != numberOfInvocations )
4147 throw new ArgumentException ( "Provided options must match the specified number of invocations." , nameof ( options ) ) ;
4248
@@ -64,6 +70,8 @@ public override async Task SendAsync(IMessageChannel channel, Quadruple<byte[]>[
6470 } ) ;
6571
6672 BigInteger alpha = listOfExponents [ 0 ] ;
73+ // note(lumip): sender should probably verify that the all generated elements are different!
74+ // otherwise the receiver could recover two or more of the sent values
6775
6876#if DEBUG
6977 stopwatch . Stop ( ) ;
@@ -175,6 +183,11 @@ public override async Task<byte[][]> ReceiveAsync(IMessageChannel channel, Quadr
175183 return selectedOptions ;
176184 }
177185
186+ /// <summary>
187+ /// Returns a random element from the group as well as the corresponding exponent for the group generator.
188+ /// </summary>
189+ /// <param name="exponent">The exponent with which the returned group element can be obtained from the group generator.</param>
190+ /// <returns>A random group element.</returns>
178191 private BigInteger GenerateGroupElement ( out BigInteger exponent )
179192 {
180193 do
@@ -186,11 +199,22 @@ private BigInteger GenerateGroupElement(out BigInteger exponent)
186199 return BigInteger . ModPow ( _parameters . G , exponent , _parameters . P ) ;
187200 }
188201
202+ /// <summary>
203+ /// Multiplicatively inverts a group element.
204+ /// </summary>
205+ /// <param name="groupElement">The group element to be inverted.</param>
206+ /// <returns>The multiplicative inverse of the argument in the group.</returns>
189207 private BigInteger Invert ( BigInteger groupElement )
190208 {
191209 return BigInteger . ModPow ( groupElement , _parameters . Q - 1 , _parameters . P ) ;
192210 }
193211
212+ /// <summary>
213+ /// Asynchronously writes a list of group elements (BigInteger) to a message channel.
214+ /// </summary>
215+ /// <param name="channel">The network message channel.</param>
216+ /// <param name="groupElements">The list of group elements to write/send.</param>
217+ /// <returns></returns>
194218 private Task WriteGroupElements ( IMessageChannel channel , IReadOnlyList < BigInteger > groupElements )
195219 {
196220 MessageComposer message = new MessageComposer ( 2 * groupElements . Count ) ;
@@ -204,6 +228,12 @@ private Task WriteGroupElements(IMessageChannel channel, IReadOnlyList<BigIntege
204228 return channel . WriteMessageAsync ( message . Compose ( ) ) ;
205229 }
206230
231+ /// <summary>
232+ /// Asynchronously reads a specified number of group elements from a message channel.
233+ /// </summary>
234+ /// <param name="channel">The network message channel.</param>
235+ /// <param name="numberOfGroupElements">Number of group elements to read/receive.</param>
236+ /// <returns></returns>
207237 private async Task < BigInteger [ ] > ReadGroupElements ( IMessageChannel channel , int numberOfGroupElements )
208238 {
209239 MessageDecomposer message = new MessageDecomposer ( await channel . ReadMessageAsync ( ) ) ;
@@ -246,10 +276,22 @@ private async Task<Quadruple<byte[]>[]> ReadOptions(IMessageChannel channel, int
246276 return options ;
247277 }
248278
249- private byte [ ] MaskOption ( byte [ ] message , BigInteger groupElement , int invocationIndex , int optionIndex )
279+ /// <summary>
280+ /// Masks an option (i.e., a sender input message).
281+ /// </summary>
282+ ///
283+ /// The option is XOR-masked with the output of a random oracle queried with the
284+ /// concatentation of the binary representations of the given groupElement, invocationIndex and optionIndex.
285+ ///
286+ /// <param name="option">The sender input/option to be masked.</param>
287+ /// <param name="groupElement">The group element that contributes receiver choice to the query.</param>
288+ /// <param name="invocationIndex">The index of the OT invocation this options belongs to.</param>
289+ /// <param name="optionIndex">The index of the option.</param>
290+ /// <returns></returns>
291+ private byte [ ] MaskOption ( byte [ ] option , BigInteger groupElement , int invocationIndex , int optionIndex )
250292 {
251293 byte [ ] query = BufferBuilder . From ( groupElement . ToByteArray ( ) ) . With ( invocationIndex ) . With ( optionIndex ) . Create ( ) ;
252- return _randomOracle . Mask ( message , query ) ;
294+ return _randomOracle . Mask ( option , query ) ;
253295 }
254296 }
255297}
0 commit comments