Open Jyun-Neng opened 6 years ago
addition, multiplication, comparisons, all of these take O(log n) levels for n-bit numbers. You can look in the code to see how it is done (the comparison code is a bit easier to decipher).
@shaih: Doesn't this document also detail how binary arith & comparison work in HElib? :) https://eprint.iacr.org/2018/202
I try to use Test_binaryArith to do different bit size binary addition. In my opinion, doing n-bit addition should consume n levels by using ripple carry adder.
For example: a=(a_1, a_0), b=(b_1, b_0), where a, b are 2-bit numbers and (a_1, a_0), (b_1, b_0) are its binary representation, respectively. And the addition result is sum=(sum_2, sum_1, sum_0). sum_0 = a_0 + b_0 sum_1 = a_1 + b_1 + (a_0 b_0) (consumes 1 level) sum_2 = (a_1 b_1) (a_0 b_0) (consumes 2 levels)
But in fact, Test_binaryArith.cpp consumes fewer levels than above method. For example, running 5-bit addition consumes 3 levels, running 8-bit addition consumes 4 levels. I think that this program does not use the ripple carry adder, but I don't know what method does this program use.