# CKKS KeyGen and bootstrapping

**URL:** <https://openfhe.discourse.group/t/ckks-keygen-and-bootstrapping/372>\
**Category:** Library Questions\
**Created:** [February 18, 2023, 10:44pm UTC](https://openfhe.discourse.group/t/ckks-keygen-and-bootstrapping/372 "2023-02-18T22:44:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ujinnam](https://avatars.discourse-cdn.com/v4/letter/u/8edcca/32.png) [@ujinnam](https://openfhe.discourse.group/u/ujinnam)\
**Post date:** [February 18, 2023, 10:44pm UTC](https://openfhe.discourse.group/t/ckks-keygen-and-bootstrapping/372/1 "2023-02-18T22:44:30Z")

</div>

Hi,

I have a couple of questions about the secret key generation of CKKS and its bootstrapping.

1. Here ([openfhe-development/base-pke.cpp at 745a4920fd711d789d08d250f1f444bac23195fd · openfheorg/openfhe-development · GitHub](https://github.com/openfheorg/openfhe-development/blob/745a4920fd711d789d08d250f1f444bac23195fd/src/pke/lib/schemebase/base-pke.cpp#L68)) in the code, it seems like it is generating a secret key with hamming weight 16 in SPARSE\_TERNARY case, but it says SPARSE\_TERNARY uses hamming weight 64 in README. I would like to know if ‘16’ here does not denote the hamming weight.

2. In the CKKS bootstrapping procedure, K\_UNIFORM was set to 512 by default. Is this K here the range of the sine approximation? or is it (the range of approximation) \* 2^r where r is the number of iterations for the double-angle formula?

Thank you,  
Yujin

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [February 22, 2023, 10:20pm UTC](https://openfhe.discourse.group/t/ckks-keygen-and-bootstrapping/372/2 "2023-02-22T22:20:44Z")

</div>

Hi @ujinnam ,

1. This is a bug. I’ve created an issue for it: [Hamming weight for SPARSE\_TERNARY · Issue #311 · openfheorg/openfhe-development · GitHub](https://github.com/openfheorg/openfhe-development/issues/311) Thank you for reporting it. Everywhere else in OpenFHE, we set the Hamming weight to 64. Note that we do not recommend using sparse secrets in practice. `TERNARY_UNIFORM` should be used instead. There are several attacks for sparse secrets: [On the Feasibility and Impact of Standardising Sparse-secret LWE Parameter Sets for Homomorphic Encryption](https://eprint.iacr.org/2019/1148)
2. K\_UNIFORM is set to 512 to allow up to 512$q$-overflows after `ModRaise`. This corresponds to the full range of the sine function (after the last double-angle iteration).
