Skip to content

chaintope/rsa-accumulatorrb

Repository files navigation

RSA Accumulator for Ruby Build Status Gem Version MIT License

Cryptographic accumulator based on the strong RSA assumption BBF18 in Ruby.

Installation

Add this line to your application's Gemfile:

gem 'rsa-accumulator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rsa-accumulator

Usage

Setup accumulator

First, initialize the accumulator. Since the accumulator uses groups of unknown order, it can be generated in following ways:

require 'rsa-accumulator'

# using RSA modulus published by RSA Laboratory
acc = RSA::Accumulator.generate_rsa2048

# using Random RSA modulus with a specified bit length(default value is )
acc = RSA::Accumulator.generate_random(2048)

Adding elements and membership proof

You can add arbitrary String data to the accumulator.

acc.add('a', 'b')
proof = acc.add('c')

You can use inclusion proof to prove that an element exists in an accumulator.

acc.member?(proof)

Non membership proof

You can generate non-membership proof and prove that the elements does not exist in the accumulator.

members = %w(a b)
non_members = %w(c, d)
acc.add(*members)
proof = acc.prove_non_membership(members, non_members)
acc.non_member?(non_members, proof)
=> true

Delete element from accumulator

You can remove elements from the accumulator by providing the inclusion proof.

acc.add('a', 'b')
proof = acc.add('c')
acc.delete(proof)

acc.member?(proof)
=> false

Holding the product of all elements

This feature is experimental and has not been checked against large amounts of data.

acc = RSA::Accumulator.generate_rsa2048(hold_elements: true)
acc.add('a', 'b', 'c')
acc.add('d', 'e')

# acc has product of all elements in acc#products, so you can get membership proof.
proof = acc.prove_membership('b')