int modulus_to_poly_degree()

in src/hit/common.cpp [153:196]


    int modulus_to_poly_degree(int mod_bits) {
        // When determining what dimension to use, we must first determine how many
        // primes need to be in our modulus (more on this below). Then we must
        // consult the following table to determine the smallest possible dimension.
        // A larger coeff_modulus implies a larger noise budget, hence more encrypted
        // computation capabilities. However, an upper bound for the total bit-length
        // of the coeff_modulus is determined by the poly_modulus_degree, as follows:
        //
        //     +----------------------------------------------------+
        //     | poly_modulus_degree | max coeff_modulus bit-length |
        //     +---------------------+------------------------------+
        //     | 1024                | 27                           |
        //     | 2048                | 54                           |
        //     | 4096                | 109                          |
        //     | 8192                | 218                          |
        //     | 16384               | 438                          |
        //     | 32768               | 881                          |
        //     +---------------------+------------------------------+
        if (mod_bits <= 27) {
            return 1024;
            // NOLINTNEXTLINE(readability-else-after-return)
        } else if (mod_bits <= 54) {
            return 2048;
        } else if (mod_bits <= 109) {
            return 4096;
        } else if (mod_bits <= 218) {
            return 8192;
        } else if (mod_bits <= 438) {
            return 16384;
        } else if (mod_bits <= 881) {
            return 32768;
        } else if (mod_bits <= 1761) {
            return 65536;
        }
        // SEAL will throw an exception when poly degree is 131072 or larger
        // (which corresponds to the 262144th cyclotomic ring)
        // else if(mod_bits <= 3524) { return 131072; }
        // else if(mod_bits <= 7050) { return 262144; }
        else {
            LOG_AND_THROW_STREAM(
                "This computation is too big to handle right now: cannot determine a valid ring size for a "
                << mod_bits << "-bit modulus");
        }
    }