[{"content":"设$\\mathcal{R}$是整环，$f(x),g(x)\\in \\mathcal{R}[x]$为正次数多项式，$\\text{deg}(f)=d,\\text{deg}(g)=e$，则\n$\\text{Res}(f,g)=0$当且仅当存在不为0的多项式$p(x),q(x)\\in \\mathcal{R}[x],\\text{deg}(p)\\lt e,\\text{deg}(g)\\lt d$，使得$fp+gq=0$。\n进一步，如果$g$的最高次项系数$c_g^e$是整环里的可逆元，则设$g_1(x)=g/c_g^e$，显然$g_1(x)$是首一多项式，再令$f_1(x)=f/c_g^e$\n此时$fp+gq=0$等价于$f_1p+g_1q=0$等价于$f_1p\\equiv 0(\\text{mod}\\;g_1)$\n设$\\mathcal{R}_g[x]=\\mathcal{R}[x](\\text{mod}\\;g_1)$，显然$R_g$是$\\mathcal{R}$上秩等于$e$的有限生成自由模，则$f_1$诱导出$R_g$上的一个线性变换 $$\rx\\in R_g,f_1x\\in R_g\r$$ 因为有$p\\neq 0(\\text{mod}\\;g_1),f_1p\\equiv 0(\\text{mod}\\;g_1)$，所以$\\text{rank}(\\text{ker}(f_1))\\gt 0$，即$\\text{rank}(f_1)\\lt e$。(秩-零化度定理)\n给定$R_g$上的一组基比如多项式基$\\{1,x,...,x^{e-1}\\}$，则$f_1$在这组基上的表示矩阵为$M$ $$\r\\text{rank}(f_1)\\lt e \\iff \\text{det}(M)=0\r$$ 注意：交换环上矩阵不满秩与矩阵不可逆不等价，应该是矩阵可逆一定满秩，满秩不一定可逆，不满秩一定不可逆，不可逆不一定不满秩。这是因为矩阵可逆等价于行列式是单位元即乘法可逆元。0一定是非单位元。\n如果$\\mathcal{R}$是整环，则$f$和$g$有公因子的必要条件是$\\text{Res}(f,g)=0$。\n如果$\\mathcal{R}$是唯一分解环即UFD，则$f$和$g$有公因子当且仅当$\\text{Res}(f,g)=0$。\n如果$\\mathcal{R}[x]$是欧几里得环ED，则$f$和$g$有公因子当且仅当$\\text{det}(M)=0$。\n$\\mathcal{R}[x]$是欧几里得环当且仅当$\\mathcal{R}$是除环。\n有限域上的一元多项式环是欧几里得环ED，多元多项式环是唯一分解环UFD。\n$f$和$g$有公因子是$f$和$g$有公共根的必要条件。\n注意：唯一分解环UFD一定是整环，主理想整环PID一定是UFD，欧几里得环ED一定是PID，域一定是ED。\n设$\\mathcal{R}$是整环，$f(x),g(x)\\in \\mathcal{R}[x]$为正次数多项式，$\\text{deg}(f)=d,\\text{deg}(g)=e$，则\n$$\rf 和 g 不互素的必要条件是存在不为 0 的多项式 p(x),q(x)\\in \\mathcal{R}[x],\\text{deg}(p)\\lt e,\\text{deg}(g)\\lt d，使得 fp+gq=0。\r$$ 如果$\\mathcal{R}$是唯一分解整环即UFD，则变成了充要条件。\n关于唯一分解整环有如下高斯定理： $$\r\\mathcal{R}是唯一分解整环当且仅当\\mathcal{R}[x]是唯一分解整环\r$$ 因此，如果$\\mathcal{R}$是唯一分解整环，则$\\mathcal{R}$上的任意数量变元的多项式环也是唯一分解整环。\n常见的唯一分解整环就是整数环、域、和定义在它们上面的一元和多元多项式环。\n贝祖定理的存在条件\r主理想整环（PID）上成立贝祖定理：若 $f$ 与 $g$ 互素，则存在 $u,v \\in \\mathcal{R}[x]$ 使得 $uf+vg=1$。\n对于非 PID 的 UFD（如 $\\mathbb{Z}[x]$），互素不一定能组合出 $1$。例如 $2$ 与 $x$ 在 $\\mathbb{Z}[x]$ 中互素，但不存在整系数多项式 $u,v$ 使 $2u + xv = 1$（常数项矛盾）。因此，在更一般的环上，互素只能用公因子的不存在来刻画，而无法通过线性组合的形式体现。\n整环\r戴德金环\r模\r参考链接：\n戴德金环上的模结构初步 - Bembew 数学\n[【抽象代数】10. 几类重要的整环 - 知乎][(https://zhuanlan.zhihu.com/p/191411259)]\n9.3 多项式环是唯一分解整环9.3 POLYNOMIAL RINGS THAT ARE UNIQUE FACTORIZ - 掘金\n有限域上多项式因子分解 - maTHμ - 计算机代数系统\n","date":"2026-03-15T00:00:00Z","image":"https://www.wfz521.com/p/%E6%9C%89%E9%99%90%E5%9F%9F%E5%AD%A6%E4%B9%A0/pkq_hu_4cdd2b70889c13db.png","permalink":"https://www.wfz521.com/p/%E6%9C%89%E9%99%90%E5%9F%9F%E5%AD%A6%E4%B9%A0/","title":"有限域学习"},{"content":"我叫皮卡丘，爱好是放电，哈哈哈哈哈\n","date":"2025-10-17T00:00:00Z","image":"https://www.wfz521.com/p/%E4%B8%AA%E4%BA%BA%E7%AE%80%E5%8E%86/pkq_hu_4cdd2b70889c13db.png","permalink":"https://www.wfz521.com/p/%E4%B8%AA%E4%BA%BA%E7%AE%80%E5%8E%86/","title":"个人简历"},{"content":"FFT\rFFT的误差\r问题1：已知$\\mathbf{a}=\\mathbf{M}^{-1}\\mathbf{b}$，其中$\\mathbf{M}\\in \\mathbb{C}^{n\\times n},\\mathbf{b}\\in \\mathbb{C}^{n}$，这里把$\\mathbf{a}$看做多项式系数，$\\mathbf{b}$看做n维向量，分析$e=\\Vert \\mathbf{b}-\\mathbf{M}\\mathbf{a}\\Vert_\\infty$的上界？\n问题2：已知$\\mathbf{a}_1=\\mathbf{M}^{-1}\\mathbf{b}_1,\\mathbf{a}_2=\\mathbf{M}^{-1}\\mathbf{b}_2$，其中$\\mathbf{M}\\in \\mathbb{C}^{n\\times n},\\mathbf{b}_1,\\mathbf{}_2\\in \\mathbb{C}^{n}$，分析 $$ e_+=\\Vert (\\mathbf{b}1+{simd}\\mathbf{b}_2)-\\mathbf{M}(\\mathbf{a}1+{poly}\\mathbf{a}2)\\Vert\\infty\\\ne_\\times=\\Vert (\\mathbf{b}1\\times{simd}\\mathbf{b}_2)-\\mathbf{M}(\\mathbf{a}1\\times{poly}\\mathbf{a}2)\\Vert\\infty $$ 两个误差的上界？\n回答：显然，误差不好准确估计，但是维数越高，误差的上界应该越大。\n对于双精度的FHE运算来说，FFT的运算误差应该可以控制在单精度范围内。\n","date":"2025-10-16T00:00:00Z","image":"https://www.wfz521.com/p/%E5%BF%AB%E9%80%9F%E5%82%85%E9%87%8C%E5%8F%B6%E5%8F%98%E6%8D%A2/pkq_hu_4cdd2b70889c13db.png","permalink":"https://www.wfz521.com/p/%E5%BF%AB%E9%80%9F%E5%82%85%E9%87%8C%E5%8F%B6%E5%8F%98%E6%8D%A2/","title":"快速傅里叶变换"},{"content":"SIMD不等式\r$$\r\\mathbf{a}=(a_0,a_1,...,a_{n-1}),\\mathbf{b}=(b_0,b_1,...,b_{n-1})\\\\\r\\mathbf{a}+\\mathbf{b} = (a_0+b_0,a_1+b_1,...,a_{n-1}+b_{n-1})\\\\\r\\mathbf{a}\\circ\\mathbf{b} = (a_0\\times b_0,a_1\\times b_1,...,a_{n-1}\\times b_{n-1})\\\\\r\\Vert c\\circ\\mathbf{a}\\Vert=c\\times\\Vert\\mathbf{a}\\Vert\\\\\r\\Vert\\mathbf{a}+\\mathbf{b}\\Vert \\leq \\Vert\\mathbf{a}\\Vert+ \\Vert\\mathbf{b}\\Vert\\\\\r\\Vert\\mathbf{a}\\circ\\mathbf{b}\\Vert \\leq \\Vert\\mathbf{a}\\Vert\\times \\Vert\\mathbf{b}\\Vert\\\\\r$$嵌入不等式\r在n维向量和n个系数的多项式之间存在同构关系$\\sigma$，不妨设$a(x)=\\Sigma a_iX^i$，满足： $$\r\\sigma(a(x)+_{\\sigma}b(x))=\\sigma(a(x))+\\sigma(b(x))\\\\\r\\sigma(a(x)\\cdot_{\\sigma}b(x))=\\sigma(a(x))\\circ\\sigma(b(x))\r$$ 则 $$\r\\Vert\\sigma(c\\cdot a(x))\\Vert = \\Vert c\\circ \\sigma(a(x))\\Vert =c\\times \\Vert\\sigma(a(x))\\Vert\\\\\r\\Vert\\sigma(a(x)+_{\\sigma}b(x))\\Vert \\leq \\Vert\\sigma(a(x))\\Vert + \\Vert\\sigma(b(x))\\Vert\\\\\r\\Vert\\sigma(a(x)\\cdot_{\\sigma}b(x))\\Vert \\leq \\Vert\\sigma(a(x))\\Vert \\times \\Vert\\sigma(b(x))\\Vert\\\\\r$$ 利用这个嵌入不等式就可以很好的分析同态噪声的变化情况，因为密文就是以多项式形式存在，而明文是向量。\n赫尔德(Holder)不等式\r已知$\\frac{1}{p}+\\frac{1}{q}=1,1\\leq p\\leq+\\infty,1\\leq q\\leq+\\infty $，对于任意两个复数向量$\\mathbf{a},\\mathbf{b}\\in \\mathbb{C}^n$，有 $$\r\\left|\\sum_{i=0}^{n-1}a_i\\bar{b}_i\\right|\\leq \\sum_{i=0}^{n-1} \\left|a_i\\right|\\left|b_i\\right|\\leq\\Vert\\mathbf{a}\\Vert_p\\Vert\\mathbf{b}\\Vert_q\r$$ 特别的，当p=1时有，$\\left|\\sum_{i=0}^{n-1}a_i\\bar{b}_i\\right|\\leq \\sum_{i=0}^{n-1} \\left|a_i\\right|\\left|b_i\\right|\\leq\\Vert\\mathbf{a}\\Vert_1\\Vert\\mathbf{b}\\Vert_{\\infty}$\n矩阵-向量不等式\r对于任意矩阵$\\mathbf{M}\\in \\mathbb{C}^{n\\times n}$，任意向量$\\mathbf{a}\\in\\mathbb{R}^n$，令$\\mathbf{b}=\\mathbf{M}\\mathbf{a}$，则 $$\rb_i=\\mathbf{M}_i\\mathbf{a}=\\sum_{j=0}^{n-1}M_{i,j}a_j\\\\\ra_j\\in \\mathbb{R},\\bar{a}_j = a_j\\\\\r\\left|b_i\\right| = \\left|\\sum_{j=0}^{n-1}M_{i,j}a_j\\right|=\\left|\\sum_{j=0}^{n-1}M_{i,j}\\bar{a}_j\\right|\\leq\r\\Vert\\mathbf{M}_i\\Vert_p\\Vert\\mathbf{a}\\Vert_q\\\\\r\\Vert \\mathbf{b}\\Vert_\\infty\\leq \\text{max}_{0\\leq i\\leq n-1}\\{{\\Vert\\mathbf{M}_i\\Vert_p}\\}\\Vert\\mathbf{a}\\Vert_q\r$$ 不妨设$\\mathbf{M}$可逆，则$\\mathbf{a}=\\mathbf{M}^{-1}\\mathbf{b}$，\n$$\\Vert \\mathbf{a}\\Vert_\\infty\\leq \\text{max}_{0\\leq i\\leq n-1}\\{{\\Vert\\mathbf{M}^{-1}_i\\Vert_p}\\}\\Vert\\mathbf{b}\\Vert_q$$综合可得， $$\r\\frac{\\Vert \\mathbf{a}\\Vert_\\infty}{\\text{max}_{0\\leq i\\leq n-1}\\{{\\Vert\\mathbf{M}^{-1}_i\\Vert_1}\\}}\\leq\\Vert \\mathbf{b}\\Vert_\\infty\\leq \\text{max}_{0\\leq i\\leq n-1}\\{{\\Vert\\mathbf{M}_i\\Vert_p}\\}\\Vert\\mathbf{a}\\Vert_q\r$$快速傅里叶变换不等式\rFFT里面的矩阵满足\n$\\text{max}_{0\\leq i\\leq n-1}\\{{\\Vert\\mathbf{M}_i\\Vert_\\infty}\\}=1$\n$\\text{max}_{0\\leq i\\leq n-1}\\{{\\Vert\\mathbf{M}_i\\Vert_1}\\}=n$\n所以有 $$\r\\frac{\\Vert \\mathbf{a}\\Vert_\\infty}{\\text{max}_{0\\leq i\\leq n-1}\\{{\\Vert\\mathbf{M}^{-1}_i\\Vert_1}\\}}\\leq\\Vert \\mathbf{b}\\Vert_\\infty\\leq\\Vert\\mathbf{a}\\Vert_1\\leq n\\Vert\\mathbf{a}\\Vert_{\\infty}\r$$ 事实上，$\\text{max}_{0\\leq i\\leq n-1}\\{{\\Vert\\mathbf{M}^{-1}_i\\Vert_1}\\}=1$，所以 $$\r\\Vert \\mathbf{a}\\Vert_\\infty\\leq\\Vert \\mathbf{b}\\Vert_\\infty \\leq n\\Vert\\mathbf{a}\\Vert_\\infty\r$$ 这样就使用$\\mathbf{a}$来约束$\\mathbf{b}$的无穷范数上下界了。\n快速傅里叶嵌入不等式\r如果用快速傅里叶变换作为嵌入同构关系，则 $$\r\\Vert a(x)\\Vert_\\infty \\leq \\Vert\\sigma(a(x))\\Vert_\\infty \\leq \\Vert a(x)\\Vert_1\\leq n\\Vert a(x)\\Vert_\\infty\r$$进一步，有 $$\r\\Vert a(x)\\cdot_\\sigma b(x)\\Vert_\\infty \\leq \\Vert \\sigma(a(x)\\cdot_\\sigma b(x))\\Vert_\\infty \\leq \\Vert\\sigma(a(x))\\Vert_\\infty \\times \\Vert\\sigma(b(x))\\Vert_\\infty \\leq \\Vert a(x)\\Vert_1 \\times \\Vert b(x)\\Vert_1 \\leq n^2\\Vert a(x)\\Vert_\\infty \\Vert b(x)\\Vert_\\infty\r$$ 注意$\\Vert a(x)\\cdot_\\sigma b(x)\\Vert_\\infty \\leq n^2\\Vert a(x)\\Vert_\\infty \\Vert b(x)\\Vert_\\infty$这个界不是紧的，应该是 $$\r\\Vert a(x)\\cdot_\\sigma b(x)\\Vert_\\infty \\leq \\Vert a(x)\\Vert_2 \\Vert b(x)\\Vert_2\\leq n \\Vert a(x)\\Vert_\\infty \\Vert b(x)\\Vert_\\infty\r$$ 为什么会出现不紧的界？这是因为虽然不等号具有传递性，但是取得等号的条件不具备传递性，即不同时取得等号。\n实际应用中我们建议使用下面的不等式 $$\r\\Vert \\sigma(a(x)\\cdot_\\sigma b(x))\\Vert_\\infty \\leq n^2\\Vert a(x)\\Vert_\\infty \\Vert b(x)\\Vert_\\infty\\\\\r\\Vert \\sigma(a(x)+ b(x))\\Vert_\\infty \\leq n(\\Vert a(x)\\Vert_\\infty +\\Vert b(x)\\Vert_\\infty)\r$$FHE中噪声\rn维向量$m_i$看做多项式$m_i(x)$的系数，然后FFT编码成多项式即$M_i(x)=\\sigma^{-1}(m_i(x))$，对$M_i(x)$进行同态加密，得到$C_i(x)$，不妨设对应噪声为$E_i(x)$，\n（1）加法运算：$\\Vert E_i(x)+E_j(x)\\Vert_\\infty \\leq \\Vert \\sigma\\left(E_i(x)+E_j(x)\\right)\\Vert_\\infty \\leq \\Vert \\sigma\\left(E_i(x)\\right)\\Vert_\\infty + \\Vert \\sigma\\left(E_j(x)\\right)\\Vert_\\infty$\n（2）乘法运算：$\\Vert E_i(x)\\times E_j(x)\\Vert_\\infty \\leq \\Vert \\sigma\\left(E_i(x)\\times E_j(x)\\right)\\Vert_\\infty \\leq \\Vert \\sigma\\left(E_i(x)\\right)\\Vert_\\infty \\times \\Vert \\sigma\\left(E_j(x)\\right)\\Vert_\\infty$\n（3）数乘运算：$\\Vert c\\times E_j(x)\\Vert_\\infty \\leq \\Vert \\sigma\\left(c\\times E_j(x)\\right)\\Vert_\\infty \\leq c \\times \\Vert \\sigma\\left(E_j(x)\\right)\\Vert_\\infty$\n（4）多项式乘：$\\Vert c(x)\\times E_j(x)\\Vert_\\infty \\leq \\Vert \\sigma\\left(c(x)\\times E_j(x)\\right)\\Vert_\\infty \\leq \\Vert c(x)\\Vert_1 \\times \\Vert \\sigma\\left(E_j(x)\\right)\\Vert_\\infty$\n（5）数加运算：$\\Vert c + E_j(x)\\Vert_\\infty \\leq \\Vert \\sigma\\left(c + E_j(x)\\right)\\Vert_\\infty \\leq c + \\Vert \\sigma\\left(E_j(x)\\right)\\Vert_\\infty$\n（6）多项式加：$\\Vert c(x)+ E_j(x)\\Vert_\\infty \\leq \\Vert \\sigma\\left(c(x) + E_j(x)\\right)\\Vert_\\infty \\leq \\Vert c(x)\\Vert_1 + \\Vert \\sigma\\left(E_j(x)\\right)\\Vert_\\infty$\n（7）伽罗瓦自同构：$\\Vert \\theta_t(E_j(x))\\Vert_\\infty \\leq \\Vert \\sigma\\left(\\theta_t(E_j(x))\\right)\\Vert_\\infty \\leq \\Vert \\theta_t(\\sigma(E_j(x)))\\Vert_\\infty = \\Vert \\sigma(E_j(x))\\Vert_\\infty$\n（8）弗罗比尼斯自同构：$\\Vert \\theta_{p^t}(E_j(x))\\Vert_\\infty \\leq \\Vert \\sigma\\left(\\theta_{p^t}(E_j(x))\\right)\\Vert_\\infty \\leq \\Vert \\theta_{p^t}(\\sigma(E_j(x)))\\Vert_\\infty = \\Vert \\sigma(E_j(x))\\Vert_\\infty$\n有论文表明：伽罗瓦自同构几乎不改变噪声，准确的说是因为伽罗瓦自同构在模$X^m+1$下相当于系数重排且符号可能改变。因此绝对值不变，无穷范数自然不变。\n利用上述8个公式，当给定初始噪声的$\\Vert \\sigma\\left(E_i(x)\\right)\\Vert_\\infty$上界时，就能估计后面所有使用这8中运算后的噪声界。\n补充：证明分圆多项式环上的伽罗瓦变换是自同构。关键是证明双射。\n","date":"2025-10-15T00:00:00Z","image":"https://www.wfz521.com/p/%E8%8C%83%E6%95%B0%E4%B8%8D%E7%AD%89%E5%BC%8F/pkq_hu_4cdd2b70889c13db.png","permalink":"https://www.wfz521.com/p/%E8%8C%83%E6%95%B0%E4%B8%8D%E7%AD%89%E5%BC%8F/","title":"范数不等式"},{"content":"本质\rBGV方案里面的key-swith的本质是在已有$s_A, s_B, (c_0^A,c_1^A)$并且$s_A,s_B$保密的基础上，构造出$(c_0^B,c_1^B)$，使其满足： $$\r\\left[\\left[c_0^A+s_A\\cdot c_1^A\\right]_Q\\right]_P=\\left[\\left[c_0^B+s_B\\cdot c_1^B\\right]_Q\\right]_P\r$$ 充分条件是：\n（1）$c_0^B+s_B\\cdot c_1^B\\equiv c_0^A+s_A\\cdot c_1^A+Pv(\\text{mod}\\;Q)$\n（2）$\\left|v\\right|\\leq \\frac{Q-P}{2P}-\\left|e_A\\right|$\nkey-switch的几种构造方式本质都是在不断缩小$\\left|v\\right|$的上界，\nhigh level\r用$s_B$加密$s_A$即$ks_{A\\rightarrow B}=(\\left[s_A+a\\cdot s_B+Pe_{ks}\\right]_Q,-a)\\in \\mathcal{R}_Q^2$，称$ks_{A\\rightarrow B}$是从$s_A$到$s_B$的切换密钥（公钥）。\n令$c^B=(\\left[ c_0^A+c_1^A\\cdot ks^{A\\rightarrow B}_0\\right]_Q,\\left[c_1^A\\cdot ks^{A\\rightarrow B}_1\\right]_Q)$，则 $$\r\\begin{aligned}\rc_0^B+c_1^B\\cdot s_B\u0026 = c_0^A+c_1^A\\cdot ks^{A\\rightarrow B}_0+c_1^A\\cdot ks^{A\\rightarrow B}_1\\cdot s_B\\\\\r\u0026=c_0^A+c_1^A\\cdot s_A+Pc_1^A\\cdot e_{ks}\\\\\r\u0026\\equiv m+P(e_A+c_1^A\\cdot e_{ks})(\\text{mod}\\;Q)\r\\end{aligned}\r$$ 只要保证$\\Vert e_A+c_1^A\\cdot e_{ks} \\Vert_{\\infty}\\leq\\Vert e_A\\Vert_{\\infty}+\\Vert c_1^A\\cdot e_{ks} \\Vert_{\\infty} \\leq \\frac{Q-P}{2P}$，则密钥切换成功。\n但是$\\Vert c_1^A\\cdot e_{ks}\\Vert_{\\infty}\\leq N \\Vert c_1^A\\Vert_{\\infty}\\Vert e_{ks}\\Vert_{\\infty}\\leq \\frac{NQB_{ks}}{2}$，因此有很大概率超出界，所以我们需要想办法降低$\\Vert c_1^A\\cdot e_{ks}\\Vert_{\\infty}$。\n下面介绍几种key-switch的具体构造方式，均参考自1。\nBV11\rGHS\rHYBRID\r重线性化\r重线性化技术是在处理密文乘法时提到的，对于密文乘法我们有 $$\rc^1\\cdot c^2=(c_0^1+s\\cdot c_1^1)\\cdot(c_0^2+s\\cdot c_1^2)=c_0^1\\cdot c_0^2+(c_0^1\\cdot c_1^2+c_1^1\\cdot c_0^2)\\cdot s+(c_1^1\\cdot c_1^2)\\cdot s^2\\\\\r\\left[c^1\\cdot c^2\\right]_Q=\\left[(m_1+Pe_1)(m_2+Pe_2)\\right]_Q=\\left[m_1m_2+P(m_1e_2+m_2e_1+Pe_1e_2)\\right]_Q\r$$ 令$d_0=c_0^1\\cdot c_0^2,d_1=c_0^1\\cdot c_1^2+c_1^1\\cdot c_0^2,d_2=c_1^1\\cdot c_1^2$，则 $$\r\\left[d_0+d_1\\cdot s+d_2\\cdot s^2\\right]_Q=\\left[m_1m_2+P(m_1e_2+m_2e_1+Pe_1e_2)\\right]_Q\r$$ 如果$\\left|m_1e_2+m_2e_1+Pe_1e_2\\right|\\leq \\frac{Q-P}{2P}$，则 $$\r\\left[\\left[d_0+d_1\\cdot s+d_2\\cdot s^2\\right]_Q\\right]_P=\\left[m_1m_2\\right]_P\r$$ 这样就可以把$(d_0,d_1,d_2)$看做是$\\left[m_1m_2\\right]_P$的密文。\n噪声上界估计： $$\r\\Vert m_1e_2+m_2e_1+Pe_1e_2\\Vert_{\\infty}\\leq \\frac{P}{2}(e^1_b+e^2_b)+ne^1_be^2_b\r$$ 重线性化的本质是在已有$s_B,(d_0^A,d_1^A,d_2^A)$并且$s_B$保密的基础上，构造出$(c_0^B,c_1^B)$，使其满足： $$\rc_0^B+s_B\\cdot c_1^B \\equiv d_0^A+s_B\\cdot d_1^A+s_B^2\\cdot d_2^A+Pv(\\text{mod}\\;Q)\\\\\r\\left|v\\right|\\leq \\frac{Q-P}{2P}-\\left|e_A\\right|\r$$ 令$c_1^B=c_1^{B'}+d_1^A,s_A=s_B^2$，则只需要构造出$(c_0^B,c_1^{B'})$，使其满足： $$\rc_0^B+s_B\\cdot c_1^{B'} \\equiv d_0^A+s_A\\cdot d_2^A+Pv(\\text{mod}\\;Q)\\\\\r\\left|v\\right|\\leq \\frac{Q-P}{2P}-\\left|e_A\\right|\r$$ 此时就可以看做正常的key-switch操作了，唯一的区别在于噪声上界由上面的三者确定而不是下面的两者确定，这是因为上面的三者有确定的明文形式，而下面的两者没有实际明文对应。\n噪声上界估计： $$\r\\Vert e_B\\Vert_{\\infty}=\\Vert v+e_A\\Vert_{\\infty}\\leq \\Vert v\\Vert_{\\infty}+\\frac{P}{2}(e^1_b+e^2_b)+ne^1_be^2_b\r$$ 因此密钥切换后的噪声会有所增加，且增加项为$\\left|v\\right|$。\n进行乘法的两个密文的噪声上界分别为$e_b^1,e_b^2$，但是重线性化的乘积密文噪声上界增大到$\\Vert v\\Vert_{\\infty}+\\frac{P}{2}(e^1_b+e^2_b)+ne^1_be^2_b$。\n显然，这个噪声上界有很大的概率接近解密上界即$\\frac{Q-P}{2P}$，因此需要降噪，这里BGV使用了Mod Switch的方法来进行处理，可以参考上一篇博客内容。\n此时有两种思路，（1）先分别进行Mod Switch，再进行重线性化；（2）先进行重线性化再进行Mod Switch。\n如果是把模qR的密文通过Mod Switch变成模q的密文，那么噪声上界将从$e_b$变为$\\frac{e_b}{R}+\\frac{\\sqrt{Nw(s)}}{2}$，其中$w(s)$是私钥的非零元素个数。\n单纯从噪声角度看，（1）的噪声近似为$\\frac{Ne^1_be^2_b}{R^2}+\\frac{N^2w(s)}{4}$，（2）的噪声近似为$\\frac{Ne^1_be^2_b}{R}$。这里不确定$N,R,e$三者取值，不好比较。\n从计算角度看，（1）似乎比（2）增加了一个Mod Switch操作，前者的重线性化操作处理的模数要比后者低，并且重线性化的时间要显著高于Mod Switch操作，因此（1）的计算性能不会显著低于（2）。\n因为，没有具体数值，所以目前无法得到哪种方法更好。但是看到很多开源库里面似乎都使用了第二种方法。\n此外，重线性化技术本身可以看做key-switch的一个推广特例。\n未来计划\r结合安全性、噪声和性能分析参数设计方法 分析simd下的旋转操作如何加速 分析自举操作 参考\r- [1] [KPZ22](https://eprint.iacr.org/2021/204.pdf)","date":"2025-09-02T00:00:00Z","image":"https://www.wfz521.com/p/key-switch-bgv/pkq_hu_4cdd2b70889c13db.png","permalink":"https://www.wfz521.com/p/key-switch-bgv/","title":"Key Switch (BGV)"},{"content":"符号\r$\\left[x\\right]_Q$：表示对整数$x$进行中心模$Q$运算，”中心“指的是需要保证$\\left|\\left[x\\right]_Q\\right|\\leq Q/2$，这里的$Q$一般是奇数。\n$\\lceil x \\rfloor$：表示四舍五入取整即round。\n原始\rScale1：\nScale实现：\n$$\rx'=x+\\lceil\\frac{(p-q)x}{qr}\\rfloor r\r$$如果四舍五入时，如果刚好小数位等于0.5，则有两种选择即$x+kr$和$x+(k+1)r$，这时可以随机选择一个或者使用四舍五入选择，当然也可以选择使得最后$[*]_p$之后绝对值较小的那一个。这对于噪声上界估计无明显影响。\n分析 $$\r\\begin{aligned}\r\\left|\\lceil\\frac{(p-q)x}{qr}\\rfloor-\\frac{(p-q)x}{qr}\\right|\\leq 1/2\\\\\r\\left|\\lceil\\frac{(p-q)x}{qr}\\rfloor r-\\frac{(p-q)x}{q}\\right|\\leq r/2\\\\\r\\left|x'-x-\\frac{(p-q)x}{q}\\right|\\leq r/2\\\\\r\\left|x'-\\frac{px}{q}\\right|\\leq r/2\r\\end{aligned}\r$$显然，等号当且仅当$\\frac{(p-q)x}{qr}$的小数位$=0.5$时成立。\n当然实际使用时，这里$\\left|x'-\\frac{px}{q}\\right|$是可以计算出来的，直接用计算出来的数参与上界估计即可。但是理论分析上界直接使用$r/2$就行了。\nBGV密文模数切换\n设BGV明文模数为$P$，密文初始模数为$Q=Q_L$对于级别$L$，类似级别$t(0\\leq t\\leq L)$对应$Q_t$，$Q_t=\\prod_{i=0}^{t} p_i$\n给定一个模数$Q_t$上的BGV密文$c=(c_0,c_1)$，需要将其切换到$Q_{t'}$上的密文$c'=(c_0',c_1')$，其中$t'\\lt t$。\n注意：$c_i\\in Z_{Q_t}[x]/X^N+1$\n操作如下：\n$$\r\\begin{aligned}\rc' \u0026= \\text{Scale}(c) \\\\\rc_0' \u0026= \\text{Scale}(c_0) \\\\\rc_1' \u0026= \\text{Scale}(c_1) \\\\\r\\left|c_0'[j] - Q_{t'}c_0[j]/Q_t\\right| \u0026\\lt P/2, \\quad (j=0,1,\\dots,N-1)\r\\end{aligned}\r$$分析：设私钥为$s$，则BGV公钥加密如下， $$\rb=a\\cdot s+P\\cdot e_s\\\\\rc_0=b\\cdot v+P\\cdot e_0+m\\\\\rc_1=-a\\cdot v+P\\cdot e_1\r$$ 其中$a,b,s,e_s,v,e_0,e_1$都需要满足特定的离散概率分布才能保证安全性。\n解密操作为$m=\\left[\\left[c_0+c_1\\cdot s\\right]_{Q_t}\\right]_P$，$c_0+c_1\\cdot s=m+P(e_s\\cdot v+e_0+s\\cdot e_1)$\n令$e=e_s\\cdot v+e_0+s\\cdot e_1$，则 $$\r\\begin{aligned}\r\\left|m\\right| \u0026\\leq P/2\\\\\r\\left(c_0,c_1\\right)\u0026\\rightarrow c_0+c_1\\cdot s = m+Pe\\\\\rm\u0026=\\left[m+Pe\\right]_P=\\left[c_0+c_1\\cdot s\\right]_P\\\\\r\\left[\\left[c_0\\right]_{Q_t}+\\left[c_1\\cdot s\\right]_{Q_t}\\right]_{Q_t}\u0026=\\left[c_0+c_1\\cdot s\\right]_{Q_t}=\\left[m+Pe\\right]_{Q_t}\\\\\r\\end{aligned}\r$$ 我们需要确保$\\left[\\left[m+Pe\\right]_{Q_t}\\right]_P=m$，因此需要满足$\\left|m+Pe\\right|=\\left|c_0+c_1\\cdot s\\right|\\lt Q_t/2$\n事实上，这里的$e$可以根据加密参数设置一个上界比如$e_b\u003e0$，需要满足$\\left|m+Pe\\right|\\leq\\left|m\\right|+P\\left|e\\right|\\lt P/2 +P\\left|e\\right|\\lt Q_t/2$\n即$\\left|e\\right|\\leq e_b\\lt \\frac{Q_t}{2P}-\\frac{1}{2}$\n又$\\left|e\\right|=\\left|e_s\\cdot v+e_0+s\\cdot e_1\\right|$，所以$\\Vert e\\Vert_{\\infty}\\leq \\Vert e_s\\Vert_2 \\Vert v\\Vert_2+\\Vert e_0\\Vert_{\\infty}+\\Vert s\\Vert_2 \\Vert e_1\\Vert_2$\n显然，$e_b$的大小应该和$s,e_s,v,e_0,e_1$的离散概率分布参数有关。\n注意，上面的分析是在解密前没有对密文进行运算的前提下展开的，下面分析如果密文参与运算如何解密分析：\n$(\\left[c_0^*\\right]_{Q_t},\\left[c_1^*\\right]_{Q_t})$，\n以加法为例，不妨假设密文$(\\left[c_0^0\\right]_{Q_t},\\left[c_1^0\\right]_{Q_t},e_b^0),(\\left[c_0^1\\right]_{Q_t},\\left[c_1^1\\right]_{Q_t},e_b^1)$进行加法运算得到 $$\r\\left(c_0^*=\\left[c_0^0\\right]_{Q_t}+\\left[c_0^1\\right]_{Q_t},c_1^*=\\left[c_1^0\\right]_{Q_t}+\\left[c_1^1\\right]_{Q_t}\\right)\\\\\r\\left(\\left[c_0^*\\right]_{Q_t}=\\left[\\left[c_0^0\\right]_{Q_t}+\\left[c_0^1\\right]_{Q_t}\\right]_{Q_t},\\left[c_1^*\\right]_{Q_t}=\\left[\\left[c_1^0\\right]_{Q_t}+\\left[c_1^1\\right]_{Q_t}\\right]_{Q_t}\\right)\\\\\rc_0^0+c_1^0\\cdot s = m^0+Pe^0,\\left|e^0\\right|\\leq e_b^0\\\\\rc_0^1+c_1^1\\cdot s = m^1+Pe^1,\\left|e^1\\right|\\leq e_b^1\\\\\rc_0^*+c_1^*\\cdot s = \\left[c_0^0\\right]_{Q_t}+\\left[c_0^1\\right]_{Q_t}+\\left[c_1^0\\right]_{Q_t}\\cdot s+\\left[c_1^1\\right]_{Q_t}\\cdot s\\\\\r\\left[c_0^*\\right]_{Q_t}+\\left[c_1^*\\right]_{Q_t}\\cdot s = \\left[c_0^0+c_0^1\\right]_{Q_t}+\\left[c_1^0+c_1^1\\right]_{Q_t}\\cdot s\\\\\r\\left[\\left[c_0^*\\right]_{Q_t}+\\left[c_1^*\\right]_{Q_t}\\cdot s\\right]_{Q_t}=\r\\left[\\left[c_0^0+c_0^1\\right]_{Q_t}+\\left[c_1^0+c_1^1\\right]_{Q_t}\\cdot s\\right]_{Q_t}\r=\\left[c_0^0+c_0^1+(c_1^0+c_1^1)\\cdot s\\right]_{Q_t}=\\left[(m^0+m^1)+P(e^0+e^1)\\right]_{Q_t}\r$$ 我们显然期待$\\left[\\left[(m^0+m^1)+P(e^0+e^1)\\right]_{Q_t}\\right]_P=\\left[m^0+m^1\\right]_P$\n由前面的分析，可知，需要保证$\\left|e^0+e^1\\right|\\lt \\frac{Q_t}{2P}-\\frac{1}{2}$，只需要$e_b^0+e_b^1\\lt \\frac{Q_t}{2P}-\\frac{1}{2}$即可。\n这也是为什么经常说加法的噪声是累加的。\n推广：\n$\\left[\\left[f\\left(m^0,m^1,\\dots,m^k\\right)+Pg\\left(e^0,e^1,\\dots,e^k\\right)\\right]_{Q_t}\\right]_P=\\left[f\\left(m^0,m^1,\\dots,m^k\\right)\\right]_P$\n成立的条件是$\\left|g\\left(e^0,e^1,\\dots,e^k\\right)\\right|\\lt \\frac{Q_t}{2P}-\\frac{1}{2}$\n通过各种不等式放缩，一般可以得到$\\left|g\\left(e^0,e^1,\\dots,e^k\\right)\\right|\\leq h(e_b^0,e_b^1,\\dots,e_b^k)\\lt \\frac{Q_t}{2P}-\\frac{1}{2}$\n模数切换成立的条件是解密后对应的明文相同，因此可以对应三个充分条件：\n(1) $c_0'=\\text{Scale}(c_0),\\;c_1'=\\text{Scale}(c_1)$ (2) $Q_t\\equiv Q_{t'}\\equiv 1(\\text{mod}\\; P)$ (3) $\\frac{Q_{t'}}{Q_t}\\left(P/2+Pe_b\\right)+P/2+P\\sqrt{N}\\Vert s\\Vert_2/2\\leq Q_{t'}/2$ 证明：\n$$\r\\begin{aligned}\rc_0[j]+(c_1\\cdot s)[j]\u0026=M+k[j]Q_t,\\left|M\\right|\\lt Q_t/2\\\\\rc_0'[j]+(c_1'\\cdot s)[j]\u0026=M+k[j]Q_t+r[j]P\\\\\rc_0'[j]+(c_1'\\cdot s)[j]\u0026=M'+k'[j]Q_{t'},\\left|M'\\right|\\lt Q_{t'}/2\\\\\rM+k[j]Q_t+r[j]P\u0026=M'+k'[j]Q_{t'}\\\\\rM+k[j]Q_t+r[j]P\u0026=M'+k'[j]Q_{t'}(\\text{mod}\\;P)\\\\\rM+k[j]\u0026\\equiv M'+k'[j](\\text{mod}\\;P)\\\\\r\\end{aligned}\r$$显然只需要说明$k[j]=k'[j]$，即可得到$M\\equiv M'(\\text{mod}\\;P)$，因此对应明文相同。\n证明$k=k'$等价于证明当$k=k'$时有$\\left|M'\\right|\\lt Q_{t'/2}$成立即$\\left|c_0'[j]+(c_1'\\cdot s)[j]-k[j]Q_{t'}\\right|\\lt Q_{t'}/2$\n直接代入验证，令 $M^*[j]=c_0'[j]+(c_1'\\cdot s)[j]-k[j]Q_{t'}$，则\n$$\r\\begin{aligned}\rM^*[j]\u0026=c_0'[j]-Q_{t'}c_0[j]/Q_t+Q_{t'}c_0[j]/Q_t+(c_1'\\cdot s)[j]+(Q_{t'}c_1/Q_t\\cdot s)[j]-(Q_{t'}c_1/Q_t\\cdot s)[j]-k[j]Q_{t'}\\\\\r\u0026=(-k[j]Q_{t'}+Q_{t'}c_0[j]/Q_t+(Q_{t'}c_1/Q_t\\cdot s)[j])\\\\\r\u0026+c_0'[j]-Q_{t'}c_0[j]/Q_t\\\\\r\u0026+(c_1'\\cdot s)[j]-(Q_{t'}c_1/Q_t\\cdot s)[j]\\\\\r\u0026=Q_{t'}M[j]/Q_t\\\\\r\u0026+c_0'[j]-Q_{t'}c_0[j]/Q_t\\\\\r\u0026+((c_1'-Q_{t'}c_1/Q_t)\\cdot s)[j]\r\\end{aligned}\r$$只需要说明此时的$\\left|M^*[j]\\right|\\lt Q_{t'}/2 $即$M^*=M'$。\n多项式乘法的系数上界可以由柯西-施瓦茨不等式确定，$\\left|(c\\cdot s)[j]\\right|\\leq \\Vert c\\Vert_2\\Vert s\\Vert_2$\n所以$\\left|((c_1'-Q_{t'}c_1/Q_t)\\cdot s)[j]\\right|\\leq \\Vert(c_1'-Q_{t'}c_1/Q_t)\\Vert_2\\Vert s\\Vert_2$\n因为$\\left|c_i'[j]-Q_{t'}c_i[j]/Q_t)\\right|\\leq P/2$，所以$||(c_i'-Q_{t'}c_i/Q_t)||_2\\leq P\\sqrt{N}/2$\n因此\n$$\r\\begin{aligned}\r\\left|M^*[j]\\right|\u0026\\leq \\frac{Q_{t'}}{Q_t}\\left|M[j]\\right|+P/2+P\\sqrt{N}\\Vert s\\Vert_2/2\r\\end{aligned}\r$$显然，如果控制$\\left|M[j]\\right|$和$\\Vert s\\Vert_2$的上界不太大，是可以做到$\\left|M^*[j]\\right|\\lt Q_{t'}/2$的，此时$M^*=M'$。注意到，如果$\\left|M^*[j]\\right|\\lt Q_{t'}/2$，则必须要求$\\left|M[j]\\right|\\lt Q_t/2$，这是必然的。\n因为$\\left|M[j]\\right|\\lt P/2 +Pe_b$，所以只需要$\\frac{Q_{t'}}{Q_t}\\left(P/2+Pe_b\\right)+P/2+P\\sqrt{N}\\Vert s\\Vert_2/2\\leq Q_{t'}/2$即可，这就是条件(3)。\n证毕。\n噪声\n$$\r\\begin{aligned}\re'\u0026=\\frac{M'-m}{P}\\\\\u0026=\\frac{Q_{t'}M[j]/Q_t+(c_0'-Q_{t'}c_0/Q_t)+\\left(\\left(c_1'-Q_{t'}c_1/Q_t\\right)\\cdot s\\right)-m}{P}\\\\\r\u0026=\\frac{Q_{t'}}{Q_t}\\frac{M[j]-m}{P}+\\frac{(c_0'-Q_{t'}c_0/Q_t)+\\left(\\left(c_1'-Q_{t'}c_1/Q_t\\right)\\cdot s\\right)}{P}+(\\frac{Q_{t'}}{Q_t}-1)\\frac{m}{P}\\\\\r\u0026=\\frac{Q_{t'}}{Q_t}e+\\frac{(c_0'-Q_{t'}c_0/Q_t)+\\left(\\left(c_1'-Q_{t'}c_1/Q_t\\right)\\cdot s\\right)}{P}+(\\frac{Q_{t'}}{Q_t}-1)\\frac{m}{P}\r\\end{aligned}\r$$$$\r\\begin{aligned}\r\\left|e'\\right|\u0026\\leq \\left|\\frac{Q_{t'}}{Q_t}e\\right|+\\left|\\frac{(c_0'-Q_{t'}c_0/Q_t)+\\left(\\left(c_1'-Q_{t'}c_1/Q_t\\right)\\cdot s\\right)}{P}\\right|+\\left|(\\frac{Q_{t'}}{Q_t}-1)\\frac{m}{P}\\right| \\\\ \u0026\\leq \\frac{Q_{t'}}{Q_t}\\left|e\\right|+\\frac{1}{2}+\\frac{\\sqrt{N}\\Vert s\\Vert_2}{2}+1-\\frac{Q_{t'}}{Q_t}\r\\\\\r\u0026=\\frac{Q_{t'}}{Q_t}\\left|e\\right|+\\frac{\\sqrt{N}\\Vert s\\Vert_2}{2}+\\frac{3}{2}-\\frac{Q_{t'}}{Q_t}\r\\\\\r\u0026\\approx \\frac{Q_{t'}}{Q_t}\\left|e\\right|+\\frac{\\sqrt{N}\\Vert s\\Vert_2}{2}\r\\\\\r\u0026\\leq \\frac{Q_{t'}}{Q_t}e_b+\\frac{\\sqrt{N}\\Vert s\\Vert_2}{2}\r\\end{aligned}\r$$所以$e_b'=\\frac{Q_{t'}}{Q_t}e_b+\\frac{\\sqrt{N}\\Vert s\\Vert_2}{2}$。\n如何设置噪声和私钥的上界是核心问题，太大了会导致支持的级别变少。当然此时安全性也会发生变化。\n还有我这里是逐个元素进行绝对值判断，也可以从向量的角度进行范数分析，比如无穷范数/欧几里得范数/嵌入范数等等。\n拓展1\r我们不再限制$Q_t\\equiv 1(\\text{mod}\\;P)$，只要求$\\text{gcd}(Q_t,P)=1$。\nScale_12\n令$Q_{t'}c_i=Q_ta_i+b_i,\\left|b_i\\right|\\leq Q_t/2$，$Q_td_i\\equiv b_i(\\text{mod}\\;P),\\left|d_i\\right|\\leq P/2$，则 $$\rc'_i=a_i+d_i\r$$ 新的公钥加解密操作如下：\n（1）加密\n令$k_t =\\left[Q_t\\right]_P,\\hat{m}=\\left[m\\cdot k_t\\right]_P$\n$$\rb=a\\cdot s+P\\cdot e_s\\\\\rc_0=b\\cdot v+P\\cdot e_0+\\hat{m}\\cdot Q_t\\\\\rc_1=-a\\cdot v+P\\cdot e_1\r$$（2）解密\n$$\r\\hat{m}=\\left[\\left[c_0+c_1\\cdot s\\right]_{Q_t}\\right]_P\\\\\rm=\\left[\\hat{m}\\cdot k_t^{-1}\\right]_P\r$$重写上述证明如下：\n$$\r\\begin{aligned}\rc_0[j]+(c_1\\cdot s)[j]\u0026=M+k[j]Q_t,\\left|M\\right|\\lt Q_t/2\\\\\rc_0'[j]+(c_1'\\cdot s)[j]\u0026=M'+k'[j]Q_{t'},\\left|M'\\right|\\lt Q_{t'}/2\\\\\r\\end{aligned}\r$$此时我们不需要证明$M\\equiv M'(\\text{mod}\\;P)$，而是要证明$M\\cdot Q_t^{-1}\\equiv M'\\cdot Q_{t'}^{-1}(\\text{mod}\\;P)$即$M\\cdot Q_{t'}\\equiv M'\\cdot Q_t(\\text{mod}\\;P)$。也就是要验证\n$$\r(c_0[j]+(c_1\\cdot s)[j]-k[j]Q_t)Q_{t'}=(c_0'[j]+(c_1'\\cdot s)[j]-k'[j]Q_{t'})Q_{t}(\\text{mod}\\;P)\\\\\r(c_0[j]+(c_1\\cdot s)[j])Q_{t'}-k[j]Q_tQ_{t'}=(c_0'[j]+(c_1'\\cdot s)[j])Q_{t}-k'[j]Q_tQ_{t'}(\\text{mod}\\;P)\r$$由Scale_new操作可得，\n$$\rQ_{t'}c_i=Q_ta_i+b_i\\\\\rQ_{t'}c_i\\equiv Q_ta_i+Q_td_i(\\text{mod}\\;P)\\\\\rQ_{t'}c_i\\equiv Q_t(a_i+d_i)(\\text{mod}\\;P)\\\\\rQ_{t'}c_i\\equiv Q_tc_i'(\\text{mod}\\;P)\\\\\r$$所以和前面的证明类似，我们只需要说明$k[j]=k'[j]$即可。\n类似的，还是带入$k$计算$M^*$，结果和前面一样，噪声分析时的唯一一点区别在于：$\\left|c_0'[j]-Q_{t'}c_0[j]/Q_t)\\right|\\leq P/2$这个上界不严格成立了，需要重新估计。\n$$\rc_0'[j]-Q_{t'}c_0[j]/Q_t=a_0+d_0-Q_{t'}c_0/Q_t=d_0-b_0/Q_t\r$$因为$\\left|d_0\\right|\\leq P/2,\\left|b_0/Q_t\\right|\\leq 1/2$，所以\n$$\r\\left|d_0-b_0/Q_t\\right|\\leq \\left|d_0\\right|+\\left|b_0/Q_t\\right|\\leq \\frac{P+1}{2}\r$$相当于原来的上界增加1/2，这个几乎可以看做没有增加了。\n条件(3)也可以更新为$\\frac{Q_{t'}}{Q_t}\\left(P/2+Pe_b\\right)+\\frac{P+1}{2}+(P+1)\\sqrt{N}\\Vert s\\Vert_2/2\\leq Q_{t'}/2$\n总的来说，用几乎没有增加的上界来放松对$Q_t$的约束，这个改变是非常成功的！！！\n当然还有其他的代价，比如需要存储$Q_t(\\text{mod}\\;P)$和$Q_t^{-1}(\\text{mod}\\;P)$且加解密都增加额外的乘法操作。\n拓展2\r拓展1的$Q_t$足够放松了，但是存在一个缺陷，$Q_{t'}c_i=Q_ta_i+b_i,\\left|b_i\\right|\\leq Q_t/2$，这里计算$a_i,b_i$是比较浪费时间的，因此我们对$Q_t$添加·一个约束，令$Q_{t'}|Q_t, t'\\lt t$。设$R=Q_t/Q_{t'}$\n我们想保证$Q_{t'}c_i\\equiv Q_tc_i'(\\text{mod}\\;P)$，一个想法是：\n令$Q_tc_i'=Q_{t'}(c_i+r_iP)$，这个$r_i$的取值目前还没有确定。\n显然，此时有$c_i'=\\frac{Q_{t'}(c_i+r_iP)}{Q_t}$。\n令$Q_{t'}|Q_t$，则$c_i'=\\frac{c_i+r_iP}{R}$\n所以$r_iP\\equiv -c_i(\\text{mod}\\;R)$\n因为$\\text{gcd}(P,R)=1$，令$r_i=-c_iP^{-1}(\\text{mod}\\;R)$。\n所以新的scale是\nScale_23\n$$\rc_i'=\\frac{c_i+\\left(-c_iP^{-1}\\left(\\text{mod}\\;R\\right)\\right)P}{R}\r$$ 类似的，有$\\left|c_i'-\\frac{c_i}{R}\\right|=\\left|\\frac{\\left(-c_iP^{-1}\\left(\\text{mod}\\;R\\right)\\right)P}{R}\\right|\\leq P/2$\n总结\r这是目前看到的三种实现BGV mod-switch的方法，三种方法既有相同之处又有各自的特点，应该根据参数选取，性能，噪声等等指标来权衡使用哪一种方式。注意：拓展2和拓展3是可以一起使用的。\n补充：在BGV方案中，私钥$s$的系数属于$\\{0,1,-1\\}$，并且规定了汉明重量h即非零元素个数。我们用$w(s)$表示。显然有: $$\r\\Vert s\\Vert_2=\\sqrt{w(s)}\r$$参考\r- [1] [BGV11](https://eprint.iacr.org/2011/277.pdf)\r- [2] [HElib20](https://eprint.iacr.org/2020/1481.pdf)\r- [3] [KPZ22](https://eprint.iacr.org/2021/204.pdf)","date":"2025-09-01T00:00:00Z","image":"https://www.wfz521.com/p/mod-switch/pkq_hu_4cdd2b70889c13db.png","permalink":"https://www.wfz521.com/p/mod-switch/","title":"Mod Switch"},{"content":"全同态加密+对称密码+隐私计算学习记录\r全同态加密\r全同态加密目前都指的是环同态\n给定两个环结构A和B，各自定义了两种运算$(+_A,\\times_A)$和$(+_B,\\times_B)$，\n如果存在一个映射f: A-\u0026gt;B，满足\n$f(a_0 +_A a_1)=f(a_0) +_B f(a_1)$\n$f(a_0 \\times_A a_1)=f(a_0) \\times_B f(a_1)$\n​\t则称f是A到B的同态映射。\n​\t对于密码方案来说，可以理解为\n$a_0 +_A a_1=Dec(Enc(a_0) +_B Enc(a_1))$\n如何构造全同态？\n有两个难点，一是如何找到两种环结构，二是如何如何针对两种环结构设计出同态映射。\n2009年，MIT的博士生Gentry基于格构造出了首个全同态方案，这个方案的实际性能很差，但是它其中的思想却一直贯彻未来的全同态方案设计当中。直接点说，Gentry基于格的方案是含有噪声的，因此必须要保证最终解密时噪声控制在某个界内，因为同态本质是针对运算做出限制，所以只需要保证每次运算后都能控制噪声在界内即可。Gentry提出了一种叫做“自举”的方法，对运算后的密文进行“同态地解密”，事实上，我觉得这个同态解密的说法不合适。下面想讲一下我个人的理解：\n理解“自举”\n一般来说，全同态加密会有一对密钥：pk、sk，也就是公钥和私钥。\n$c=Enc_{pk}(m),m=Dec_{sk}(c)$\n现在如果再构造一对密钥：$\\overline{bsk},\\overline{pk}$，满足$\\overline{bsk}=\\overline{Enc}_{\\overline{pk}}(sk)$\n自举最关键的步骤是需要把$c=Enc_{pk}(m),m=Dec_{sk}(c)$变为$\\overline{c}=\\overline{Enc}_{\\overline{pk}}(m)$，这一步也被称作重加密，这个称呼是比较贴切的，相当于换个公钥重新加密，解密后的密文可以通过参数的调整保证噪声以“极大概率”落在界内。之后还需要进行一步密钥切换，就是从$\\overline{c}=Enc_{\\overline{pk}}(m)$变成$\\hat{c}=Enc_{pk}(m)$，此时也可以通过调整参数使得噪声以“极大概率”落在界内。这里需要注意一点，自举都是概率性的，无法保证100%成功。\n$\\overline{Enc}_{\\overline{pk}}(m)=\\overline{Enc}_{\\overline{pk}}(Dec_{sk}(c))=Dec_{\\overline{bsk}}(\\overline{Enc}_{\\overline{pk}}(c))$\n通过这个公式，可以看出同态解密这个说法有点不合适，准确的理解应该是先对自举前的密文进行加密再同态地解密。 $$\rc=Enc_{pk}(m),m=Dec_{sk}(c)\\\\\r\\overline{bsk}=\\overline{Enc}_{\\overline{pk}}(sk)\\\\\r\\overline{Enc}_{\\overline{pk}}(m)=\\overline{Enc}_{\\overline{pk}}(Dec_{sk}(c))=Dec_{\\overline{bsk}}(\\overline{Enc}_{\\overline{pk}}(c))\r$$ 当然，也有对称形式的： $$\rc=Enc_{sk}(m),m=Dec_{sk}(c)\\\\\r\\overline{bsk}=Enc_{\\overline{sk}}(sk)\\\\\rEnc_{\\overline{sk}}(m)=Enc_{\\overline{sk}}(Dec_{sk}(c))=Dec_{\\overline{bsk}}(Enc_{\\overline{sk}}(c))\r$$ 注意到，在RLWE中似乎都使用非对称形式的全同态加密，在LWE中更倾向于使用对称形式的，这里应该有一些原因，需要我仔细分析一下。\n自举难点\n$Dec_{\\overline{bsk}}(\\overline{Enc}_{\\overline{pk}}(c))$，这里很显然有一个问题：$c$本身就是密文，如果对密文进行加密呢？这需要对$\\overline{Enc}$进行特别设计，既要和原来的$Enc$能够转换又要满足可以对密文进行同态加密。这是一个非常值得讨论的问题，可以通过这个切入点来看BGV/BFV/CKKS/TFHE等全同态方案的自举是如何设计的？\n自举的设计\n全同态编码\rseal库里面直接系数编码\n1 2 Plaintext pt_bfv; pt_bfv = Plaintext(gsl::span\u0026lt;const uint64_t\u0026gt;(coeffs)); 批处理编码CRT\n混合同态加密\r比较不同同态算法下一些国产对称密码的使用效果 比较不同同态算法下一些统计或机器学习的算法实现效果 RtF框架\r","date":"2025-08-27T00:00:00Z","image":"https://www.wfz521.com/p/fhe/pkq_hu_4cdd2b70889c13db.png","permalink":"https://www.wfz521.com/p/fhe/","title":"FHE"},{"content":"正文测试\r而这些并不是完全重要，更加重要的问题是， 带着这些问题，我们来审视一下学生会退会。 既然如何， 对我个人而言，学生会退会不仅仅是一个重大的事件，还可能会改变我的人生。 我们不得不面对一个非常尴尬的事实，那就是， 可是，即使是这样，学生会退会的出现仍然代表了一定的意义。 学生会退会，发生了会如何，不发生又会如何。 经过上述讨论， 生活中，若学生会退会出现了，我们就不得不考虑它出现了的事实。 学生会退会，到底应该如何实现。 这样看来， 在这种困难的抉择下，本人思来想去，寝食难安。 对我个人而言，学生会退会不仅仅是一个重大的事件，还可能会改变我的人生。 就我个人来说，学生会退会对我的意义，不能不说非常重大。 莎士比亚曾经提到过，人的一生是短的，但如果卑劣地过这一生，就太长了。这似乎解答了我的疑惑。 莫扎特说过一句富有哲理的话，谁和我一样用功，谁就会和我一样成功。这启发了我， 对我个人而言，学生会退会不仅仅是一个重大的事件，还可能会改变我的人生。 学生会退会，到底应该如何实现。 一般来说， 从这个角度来看， 这种事实对本人来说意义重大，相信对这个世界也是有一定意义的。 在这种困难的抉择下，本人思来想去，寝食难安。 了解清楚学生会退会到底是一种怎么样的存在，是解决一切问题的关键。 一般来说， 生活中，若学生会退会出现了，我们就不得不考虑它出现了的事实。 问题的关键究竟为何？ 而这些并不是完全重要，更加重要的问题是。\n奥斯特洛夫斯基曾经说过，共同的事业，共同的斗争，可以使人们产生忍受一切的力量。　带着这句话，我们还要更加慎重的审视这个问题： 一般来讲，我们都必须务必慎重的考虑考虑。 既然如此， 这种事实对本人来说意义重大，相信对这个世界也是有一定意义的。 带着这些问题，我们来审视一下学生会退会。 我认为， 我认为， 在这种困难的抉择下，本人思来想去，寝食难安。 问题的关键究竟为何？ 每个人都不得不面对这些问题。 在面对这种问题时， 要想清楚，学生会退会，到底是一种怎么样的存在。 我认为， 既然如此， 每个人都不得不面对这些问题。 在面对这种问题时， 那么， 我认为， 学生会退会因何而发生。\n引用\r思念是最暖的忧伤像一双翅膀\n让我停不了飞不远在过往游荡\n不告而别的你 就算为了我着想\n这么沉痛的呵护 我怎么能翱翔\n最暖的憂傷 - 田馥甄\n图片\r1 2 3 ![Photo by Florian Klauer on Unsplash](florian-klauer-nptLmg6jqDo-unsplash.jpg) ![Photo by Luca Bravo on Unsplash](luca-bravo-alS7ewQ41M8-unsplash.jpg) ![Photo by Helena Hertz on Unsplash](helena-hertz-wWZzXlDpMog-unsplash.jpg) ![Photo by Hudai Gayiran on Unsplash](hudai-gayiran-3Od_VKcDEAA-unsplash.jpg) 相册语法来自 Typlog\n","date":"2020-09-09T00:00:00Z","image":"https://www.wfz521.com/p/test-chinese/helena-hertz-wWZzXlDpMog-unsplash_hu_2307260c751d0e0b.jpg","permalink":"https://www.wfz521.com/p/test-chinese/","title":"Chinese Test"},{"content":"This article offers a sample of basic Markdown syntax that can be used in Hugo content files, also it shows whether basic HTML elements are decorated with CSS in a Hugo theme.\nHeadings\rThe following HTML \u0026lt;h1\u0026gt;—\u0026lt;h6\u0026gt; elements represent six levels of section headings. \u0026lt;h1\u0026gt; is the highest section level while \u0026lt;h6\u0026gt; is the lowest.\nH1\rH2\rH3\rH4\rH5\rH6\rParagraph\rXerum, quo qui aut unt expliquam qui dolut labo. Aque venitatiusda cum, voluptionse latur sitiae dolessi aut parist aut dollo enim qui voluptate ma dolestendit peritin re plis aut quas inctum laceat est volestemque commosa as cus endigna tectur, offic to cor sequas etum rerum idem sintibus eiur? Quianimin porecus evelectur, cum que nis nust voloribus ratem aut omnimi, sitatur? Quiatem. Nam, omnis sum am facea corem alique molestrunt et eos evelece arcillit ut aut eos eos nus, sin conecerem erum fuga. Ri oditatquam, ad quibus unda veliamenimin cusam et facea ipsamus es exerum sitate dolores editium rerore eost, temped molorro ratiae volorro te reribus dolorer sperchicium faceata tiustia prat.\nItatur? Quiatae cullecum rem ent aut odis in re eossequodi nonsequ idebis ne sapicia is sinveli squiatum, core et que aut hariosam ex eat.\nBlockquotes\rThe blockquote element represents content that is quoted from another source, optionally with a citation which must be within a footer or cite element, and optionally with in-line changes such as annotations and abbreviations.\nBlockquote without attribution\rTiam, ad mint andaepu dandae nostion secatur sequo quae. Note that you can use Markdown syntax within a blockquote.\nBlockquote with attribution\rDon\u0026rsquo;t communicate by sharing memory, share memory by communicating.\n— Rob Pike1\nTables\rTables aren\u0026rsquo;t part of the core Markdown spec, but Hugo supports supports them out-of-the-box.\nName Age Bob 27 Alice 23 Inline Markdown within tables\rItalics Bold Code italics bold code A B C D E F Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ultricies, sapien non euismod aliquam, dui ligula tincidunt odio, at accumsan nulla sapien eget ex. Proin eleifend dictum ipsum, non euismod ipsum pulvinar et. Vivamus sollicitudin, quam in pulvinar aliquam, metus elit pretium purus Proin sit amet velit nec enim imperdiet vehicula. Ut bibendum vestibulum quam, eu egestas turpis gravida nec Sed scelerisque nec turpis vel viverra. Vivamus vitae pretium sapien Code Blocks\rCode block with backticks\r1 2 3 4 5 6 7 8 9 10 \u0026lt;!doctype html\u0026gt; \u0026lt;html lang=\u0026#34;en\u0026#34;\u0026gt; \u0026lt;head\u0026gt; \u0026lt;meta charset=\u0026#34;utf-8\u0026#34;\u0026gt; \u0026lt;title\u0026gt;Example HTML5 Document\u0026lt;/title\u0026gt; \u0026lt;/head\u0026gt; \u0026lt;body\u0026gt; \u0026lt;p\u0026gt;Test\u0026lt;/p\u0026gt; \u0026lt;/body\u0026gt; \u0026lt;/html\u0026gt; Code block indented with four spaces\r\u0026lt;!doctype html\u0026gt;\r\u0026lt;html lang=\u0026quot;en\u0026quot;\u0026gt;\r\u0026lt;head\u0026gt;\r\u0026lt;meta charset=\u0026quot;utf-8\u0026quot;\u0026gt;\r\u0026lt;title\u0026gt;Example HTML5 Document\u0026lt;/title\u0026gt;\r\u0026lt;/head\u0026gt;\r\u0026lt;body\u0026gt;\r\u0026lt;p\u0026gt;Test\u0026lt;/p\u0026gt;\r\u0026lt;/body\u0026gt;\r\u0026lt;/html\u0026gt;\rCode block with Hugo\u0026rsquo;s internal highlight shortcode\r1 2 3 4 5 6 7 8 9 10 \u0026lt;!doctype html\u0026gt; \u0026lt;html lang=\u0026#34;en\u0026#34;\u0026gt; \u0026lt;head\u0026gt; \u0026lt;meta charset=\u0026#34;utf-8\u0026#34;\u0026gt; \u0026lt;title\u0026gt;Example HTML5 Document\u0026lt;/title\u0026gt; \u0026lt;/head\u0026gt; \u0026lt;body\u0026gt; \u0026lt;p\u0026gt;Test\u0026lt;/p\u0026gt; \u0026lt;/body\u0026gt; \u0026lt;/html\u0026gt; Diff code block\r1 2 3 4 5 [dependencies.bevy] git = \u0026#34;https://github.com/bevyengine/bevy\u0026#34; rev = \u0026#34;11f52b8c72fc3a568e8bb4a4cd1f3eb025ac2e13\u0026#34; - features = [\u0026#34;dynamic\u0026#34;] + features = [\u0026#34;jpeg\u0026#34;, \u0026#34;dynamic\u0026#34;] List Types\rOrdered List\rFirst item Second item Third item Unordered List\rList item Another item And another item Nested list\rFruit Apple Orange Banana Dairy Milk Cheese Other Elements — abbr, sub, sup, kbd, mark\rGIF is a bitmap image format.\nH2O\nXn + Yn = Zn\nPress CTRL + ALT + Delete to end the session.\nMost salamanders are nocturnal, and hunt for insects, worms, and other small creatures.\nHyperlinked image\rThe above quote is excerpted from Rob Pike\u0026rsquo;s talk during Gopherfest, November 18, 2015.\u0026#160;\u0026#x21a9;\u0026#xfe0e;\n","date":"2019-03-11T00:00:00Z","image":"https://www.wfz521.com/p/markdown-syntax-guide/pawel-czerwinski-8uZPynIu-rQ-unsplash_hu_e95a4276bf860a84.jpg","permalink":"https://www.wfz521.com/p/markdown-syntax-guide/","title":"Markdown Syntax Guide"},{"content":"Lorem est tota propiore conpellat pectoribus de pectora summo.\nRedit teque digerit hominumque toris verebor lumina non cervice subde tollit usus habet Arctonque, furores quas nec ferunt. Quoque montibus nunc caluere tempus inhospita parcite confusaque translucet patri vestro qui optatis lumine cognoscere flos nubis! Fronde ipsamque patulos Dryopen deorum.\nExierant elisi ambit vivere dedere Duce pollice Eris modo Spargitque ferrea quos palude Rursus nulli murmur; hastile inridet ut ab gravi sententia! Nomine potitus silentia flumen, sustinet placuit petis in dilapsa erat sunt. Atria tractus malis.\nComas hunc haec pietate fetum procerum dixit Post torum vates letum Tiresia Flumen querellas Arcanaque montibus omnes Quidem et Vagus elidunt\rThe Van de Graaf Canon\nMane refeci capiebant unda mulcebat\rVicta caducifer, malo vulnere contra dicere aurato, ludit regale, voca! Retorsit colit est profanae esse virescere furit nec; iaculi matertera et visa est, viribus. Divesque creatis, tecta novat collumque vulnus est, parvas. Faces illo pepulere tempus adest. Tendit flamma, ab opes virum sustinet, sidus sequendo urbis.\nIubar proles corpore raptos vero auctor imperium; sed et huic: manus caeli Lelegas tu lux. Verbis obstitit intus oblectamina fixis linguisque ausus sperare Echionides cornuaque tenent clausit possit. Omnia putatur. Praeteritae refert ausus; ferebant e primus lora nutat, vici quae mea ipse. Et iter nil spectatae vulnus haerentia iuste et exercebat, sui et.\nEurytus Hector, materna ipsumque ut Politen, nec, nate, ignari, vernum cohaesit sequitur. Vel mitis temploque vocatus, inque alis, oculos nomen non silvis corpore coniunx ne displicet illa. Crescunt non unus, vidit visa quantum inmiti flumina mortis facto sic: undique a alios vincula sunt iactata abdita! Suspenderat ego fuit tendit: luna, ante urbem Propoetides parte.\n","date":"2019-03-09T00:00:00Z","image":"https://www.wfz521.com/p/placeholder-text/matt-le-SJSpo9hQf7s-unsplash_hu_c1ca39d792aee4ab.jpg","permalink":"https://www.wfz521.com/p/placeholder-text/","title":"Placeholder Text"},{"content":"Mathematical notation in a Hugo project can be enabled by using third party JavaScript libraries.\nIn this example we will be using KaTeX\nCreate a partial under /layouts/partials/math.html Within this partial reference the Auto-render Extension or host these scripts locally. Include the partial in your templates like so: 1 2 3 {{ if or .Params.math .Site.Params.math }} {{ partial \u0026#34;math.html\u0026#34; . }} {{ end }} To enable KaTeX globally set the parameter math to true in a project\u0026rsquo;s configuration To enable KaTeX on a per page basis include the parameter math: true in content files Note: Use the online reference of Supported TeX Functions\nExamples\rInline math: $\\varphi = \\dfrac{1+\\sqrt5}{2}= 1.6180339887…$\nBlock math: $$\r\\varphi = 1+\\frac{1} {1+\\frac{1} {1+\\frac{1} {1+\\cdots} } } $$","date":"2019-03-08T00:00:00Z","permalink":"https://www.wfz521.com/p/math-typesetting/","title":"Math Typesetting"},{"content":"Emoji can be enabled in a Hugo project in a number of ways.\nThe emojify function can be called directly in templates or Inline Shortcodes.\nTo enable emoji globally, set enableEmoji to true in your site\u0026rsquo;s configuration and then you can type emoji shorthand codes directly in content files; e.g.\n🙈 :see_no_evil: 🙉 :hear_no_evil: 🙊 :speak_no_evil:\nThe Emoji cheat sheet is a useful reference for emoji shorthand codes.\nN.B. The above steps enable Unicode Standard emoji characters and sequences in Hugo, however the rendering of these glyphs depends on the browser and the platform. To style the emoji you can either use a third party emoji font or a font stack; e.g.\n1 2 3 .emoji { font-family: Apple Color Emoji, Segoe UI Emoji, NotoColorEmoji, Segoe UI Symbol, Android Emoji, EmojiSymbols; } ","date":"2019-03-05T00:00:00Z","image":"https://www.wfz521.com/p/emoji-support/the-creative-exchange-d2zvqp3fpro-unsplash_hu_27b8954607cdb515.jpg","permalink":"https://www.wfz521.com/p/emoji-support/","title":"Emoji Support"}]