def __init__(self, algorithm): if algorithm not in _ALGORITHMS: raise ValueError('unknown algorithm', algorithm) size = C.passacre_gen_size() self._algorithm = algorithm self._buf = ffi.new('unsigned char []', size) self._context = ffi.cast('struct passacre_gen_state *', self._buf) self._check(C.passacre_gen_init, _ALGORITHMS[algorithm])
def squeeze(self, n_bytes): output = ffi.new('unsigned char[]', n_bytes) self._check(C.passacre_gen_squeeze, output, n_bytes) return ffi.buffer(output)[:]