-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.xml
154 lines (72 loc) · 40.2 KB
/
search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>k8s_loong64</title>
<link href="/2022/10/26/k8s-loong64/"/>
<url>/2022/10/26/k8s-loong64/</url>
<content type="html"><![CDATA[<h2 id="版本"><a href="#版本" class="headerlink" title="版本"></a>版本</h2><pre><code class="text">k8s: 1.20.11golang: go1.19 loong64</code></pre><h2 id="不支持的架构"><a href="#不支持的架构" class="headerlink" title="不支持的架构"></a>不支持的架构</h2><pre><code class="text">!!! [0509 06:19:40] Unsupported host arch. Must be x86_64, 386, arm, arm64, s390x or ppc64le.!!! [0509 06:19:45] Unsupported host arch. Must be x86_64, 386, arm, arm64, s390x or ppc64le.</code></pre><p>修改hack/lib/golang.sh文件</p><ul><li>KUBE_SUPPORTED_SERVER_PLATFORMS</li><li>KUBE_SUPPORTED_NODE_PLATFORMS</li><li>KUBE_SUPPORTED_CLIENT_PLATFORMS</li><li>KUBE_SUPPORTED_TEST_PLATFORMS<br>添加上linux/loong64</li></ul><p>修改hack/lib/util.sh<br>在kube::util::host_arch() 里添加</p><pre><code class="bash">loongarch64*) host_arch=loongarch64 ;;</code></pre><p>修改hack/local-up-cluster.sh文件</p><pre><code class="bash">loongarch64*) host_arch=loongarch64 ;;</code></pre><h2 id="修改code-generator"><a href="#修改code-generator" class="headerlink" title="修改code-generator"></a>修改code-generator</h2><pre><code class="text">+++ [0509 06:58:10] Building go targets for linux/loong64: ./vendor/k8s.io/code-generator/cmd/prerelease-lifecycle-genfind: 'rsync': No such file or directoryfind: 'rsync': No such file or directoryGenerating prerelease lifecycle code for 27 targets</code></pre><h2 id="修改ginko"><a href="#修改ginko" class="headerlink" title="修改ginko"></a>修改ginko</h2><p>报错内容</p><pre><code class="text"># k8s.io/kubernetes/vendor/github.com/onsi/ginkgo/internal/remotevendor/github.com/onsi/ginkgo/internal/remote/output_interceptor_unix.go:42:2: undefined: syscallDupvendor/github.com/onsi/ginkgo/internal/remote/output_interceptor_unix.go:43:2: undefined: syscallDup</code></pre><p>修改<code>vendor/github.com/onsi/ginkgo/internal/remote/syscall_dup_unix.go</code></p><pre><code class="golang">// +build !linux !arm64// +build !linux !riscv64// +build !linux !loong64// +build !windows// +build !solaris</code></pre><p>拷贝 <code>vendor/github.com/onsi/ginkgo/internal/remote/syscall_dup_linux_arm64.go</code> 为<code>syscall_dup_linux_loong64.go</code>并修改</p><pre><code class="golang">// +build linux,loong64</code></pre><h2 id="替换sys-unix"><a href="#替换sys-unix" class="headerlink" title="替换sys/unix"></a>替换sys/unix</h2><p>报错内容</p><pre><code class="text"># k8s.io/kubernetes/vendor/golang.org/x/sys/unixvendor/golang.org/x/sys/unix/affinity_linux.go:14:35: undefined: _NCPUBITSvendor/golang.org/x/sys/unix/affinity_linux.go:17:25: undefined: cpuMaskvendor/golang.org/x/sys/unix/affinity_linux.go:50:27: undefined: cpuMaskvendor/golang.org/x/sys/unix/sockcmsg_unix.go:33:9: undefined: Cmsghdrvendor/golang.org/x/sys/unix/ztypes_linux.go:22:11: undefined: Timespecvendor/golang.org/x/sys/unix/ztypes_linux.go:23:11: undefined: Timespecvendor/golang.org/x/sys/unix/ztypes_linux.go:1112:12: undefined: SockaddrStoragevendor/golang.org/x/sys/unix/ztypes_linux.go:2284:8: undefined: Timespecvendor/golang.org/x/sys/unix/ztypes_linux.go:2748:8: undefined: TIPCSubscrvendor/golang.org/x/sys/unix/ztypes_linux.go:2968:10: undefined: PPSKInfovendor/golang.org/x/sys/unix/affinity_linux.go:50:27: too many errors</code></pre><pre><code class="bash">go install golang.org/x/sys@latestcp -r ${GOPATH}/pkg/mod/golang.org/x/sys@{latest}/unix vendor/golang.org/x/sys/</code></pre><h2 id="替换net-internal-socket-net-ipv4-net-ipv6"><a href="#替换net-internal-socket-net-ipv4-net-ipv6" class="headerlink" title="替换net/internal/socket net/ipv4 net/ipv6"></a>替换net/internal/socket net/ipv4 net/ipv6</h2><p>报错内容</p><pre><code class="text"># k8s.io/kubernetes/vendor/golang.org/x/net/internal/socketvendor/golang.org/x/net/internal/socket/mmsghdr_unix.go:11:17: undefined: mmsghdrvendor/golang.org/x/net/internal/socket/cmsghdr.go:9:10: undefined: cmsghdrvendor/golang.org/x/net/internal/socket/cmsghdr.go:10:10: undefined: cmsghdrvendor/golang.org/x/net/internal/socket/cmsghdr.go:11:10: undefined: cmsghdrvendor/golang.org/x/net/internal/socket/msghdr_linux.go:9:10: undefined: msghdrvendor/golang.org/x/net/internal/socket/msghdr_linux.go:9:28: undefined: iovecvendor/golang.org/x/net/internal/socket/msghdr_linux.go:23:10: undefined: msghdrvendor/golang.org/x/net/internal/socket/msghdr_linux.go:30:10: undefined: msghdrvendor/golang.org/x/net/internal/socket/msghdr_linux.go:34:10: undefined: msghdrvendor/golang.org/x/net/internal/socket/sys_linux.go:14:31: undefined: mmsghdrvendor/golang.org/x/net/internal/socket/sys_linux.go:14:31: too many errors# k8s.io/kubernetes/vendor/golang.org/x/net/ipv4vendor/golang.org/x/net/ipv4/icmp.go:34:2: undefined: icmpFiltervendor/golang.org/x/net/ipv4/icmp_linux.go:7:10: undefined: icmpFiltervendor/golang.org/x/net/ipv4/icmp_linux.go:11:10: undefined: icmpFiltervendor/golang.org/x/net/ipv4/icmp_linux.go:15:10: undefined: icmpFiltervendor/golang.org/x/net/ipv4/icmp_linux.go:23:10: undefined: icmpFiltervendor/golang.org/x/net/ipv4/sys_linux.go:19:19: undefined: sysIP_TTLvendor/golang.org/x/net/ipv4/sys_linux.go:20:19: undefined: sysIP_PKTINFOvendor/golang.org/x/net/ipv4/sys_linux.go:20:34: undefined: sizeofInetPktinfovendor/golang.org/x/net/ipv4/sys_linux.go:24:79: undefined: sysIP_TOSvendor/golang.org/x/net/ipv4/sys_linux.go:25:79: undefined: sysIP_TTLvendor/golang.org/x/net/ipv4/sys_linux.go:25:79: too many errors# k8s.io/kubernetes/vendor/golang.org/x/net/ipv6vendor/golang.org/x/net/ipv6/icmp.go:37:2: undefined: icmpv6Filtervendor/golang.org/x/net/ipv6/icmp_linux.go:7:10: undefined: icmpv6Filtervendor/golang.org/x/net/ipv6/icmp_linux.go:11:10: undefined: icmpv6Filtervendor/golang.org/x/net/ipv6/icmp_linux.go:15:10: undefined: icmpv6Filtervendor/golang.org/x/net/ipv6/icmp_linux.go:25:10: undefined: icmpv6Filtervendor/golang.org/x/net/ipv6/sys_linux.go:19:21: undefined: sysIPV6_TCLASSvendor/golang.org/x/net/ipv6/sys_linux.go:20:21: undefined: sysIPV6_HOPLIMITvendor/golang.org/x/net/ipv6/sys_linux.go:21:21: undefined: sysIPV6_PKTINFOvendor/golang.org/x/net/ipv6/sys_linux.go:21:38: undefined: sizeofInet6Pktinfovendor/golang.org/x/net/ipv6/sys_linux.go:22:21: undefined: sysIPV6_PATHMTUvendor/golang.org/x/net/ipv6/sys_linux.go:22:21: too many errors</code></pre><pre><code class="bash">go install golang.org/x/net@latestcp -r ${GOPATH}/pkg/mod/golang.org/x/net@{latest}/internal/socket vendor/golang.org/x/net/internalcp -r ${GOPATH}/pkg/mod/golang.org/x/net@{latest}/ipv4 vendor/golang.org/x/netcp -r ${GOPATH}/pkg/mod/golang.org/x/net@{latest}/ipv6 vendor/golang.org/x/net</code></pre><h2 id="修改etcd"><a href="#修改etcd" class="headerlink" title="修改etcd"></a>修改etcd</h2><p>报错内容</p><pre><code class="text">vendor/go.etcd.io/bbolt/db.go:127:13: undeclared name maxMapSize for array lengthvendor/go.etcd.io/bbolt/db.go:400:12: undefined: maxMapSizevendor/go.etcd.io/bbolt/db.go:418:10: undefined: maxMapSizevendor/go.etcd.io/bbolt/db.go:419:8: undefined: maxMapSizevendor/go.etcd.io/bbolt/db.go:885:2: pos declared but not usedvendor/go.etcd.io/bbolt/bolt_unix.go:66:15: undeclared name maxMapSize for array lengthvendor/go.etcd.io/bbolt/tx.go:533:12: undefined: maxAllocSizevendor/go.etcd.io/bbolt/tx.go:534:10: undefined: maxAllocSizevendor/go.etcd.io/bbolt/unsafe.go:27:12: undeclared name maxAllocSize for array length</code></pre><p>拷贝 <code>vendor/go.etcd.io/bbolt/bolt_arm64.go</code>为<code>vendor/go.etcd.io/bbolt/bolt_loong64.go</code> 并修改</p><pre><code class="golang">// +build loong64</code></pre><h2 id="编译"><a href="#编译" class="headerlink" title="编译"></a>编译</h2><p><code>KUBE_BUILD_PLATFORMS=linux/loong64 make all</code></p>]]></content>
</entry>
<entry>
<title>pprof</title>
<link href="/2022/10/24/pprof/"/>
<url>/2022/10/24/pprof/</url>
<content type="html"><![CDATA[<h2 id="开启pprof"><a href="#开启pprof" class="headerlink" title="开启pprof"></a>开启pprof</h2><pre><code class="golang">import ( "net/http" _ "net/http/pprof")func main(){ http.ListenAndServe(":6060", nil)}</code></pre><p>see <code>127.0.0.1:6060/debug/pprof</code></p><ul><li>allocs 过去所有内存分配的样本</li><li>block 导致同步原语阻塞的堆栈痕迹</li><li>cmdline 当前程序的命令行调用</li><li>goroutine 当前所有goroutine的堆栈痕迹</li><li>heap 实时对象的内存分配样本。你可以指定gc GET参数,在进行堆采样之前运行GC。</li><li>mutex 争夺突扰的持有者的堆栈痕迹<br>概况。CPU配置文件。你可以在seconds GET参数中指定持续时间。在你得到profile文件后,使用go tool pprof命令来调查该profile。</li><li>threadcreate 导致创建新的操作系统线程的堆栈痕迹</li><li>trace: 对当前程序的执行情况进行跟踪。你可以在秒的GET参数中指定持续时间。在你得到跟踪文件后,使用go tool trace命令来调查跟踪。</li></ul><h2 id="可视化"><a href="#可视化" class="headerlink" title="可视化"></a>可视化</h2><p><strong><a href="https://graphviz.org/download/">点击这里查看如何安装graphviz</a></strong></p><p><code>go tool pprof -http=:8000 http://10.1.40.70:31644/debug/pprof/{cmd}</code></p><h3 id="堆"><a href="#堆" class="headerlink" title="堆"></a>堆</h3><p><code>go tool pprof -http=:8000 http://10.1.40.70:31644/debug/pprof/heap</code></p>]]></content>
</entry>
<entry>
<title>fabric全同态加密合约的设计与实现</title>
<link href="/2022/10/21/fabric%E5%85%A8%E5%90%8C%E6%80%81%E5%8A%A0%E5%AF%86%E5%90%88%E7%BA%A6%E7%9A%84%E8%AE%BE%E8%AE%A1%E4%B8%8E%E5%AE%9E%E7%8E%B0/"/>
<url>/2022/10/21/fabric%E5%85%A8%E5%90%8C%E6%80%81%E5%8A%A0%E5%AF%86%E5%90%88%E7%BA%A6%E7%9A%84%E8%AE%BE%E8%AE%A1%E4%B8%8E%E5%AE%9E%E7%8E%B0/</url>
<content type="html"><![CDATA[<h2 id="隐私计算"><a href="#隐私计算" class="headerlink" title="隐私计算"></a>隐私计算</h2><h3 id="隐私计算定义"><a href="#隐私计算定义" class="headerlink" title="隐私计算定义"></a>隐私计算定义</h3><p>隐私计算是一类在处理和分析计算数据的过程中能保持数据不透明、不泄露、无法被计算方法以及其他非授权方获取技术方案。</p><h3 id="隐私计算流派"><a href="#隐私计算流派" class="headerlink" title="隐私计算流派"></a>隐私计算流派</h3><h4 id="安全多方计算"><a href="#安全多方计算" class="headerlink" title="安全多方计算"></a>安全多方计算</h4><p>双方或多方参与,在不暴露自己所有的信息,得到计算结果。大都基于不经意传输、混淆电路与秘密分享实现,例如百万富翁问题。</p><pre><code class="text">两个富翁,分别为张三和李四。他们自己都清楚自己有几千万财产,也即,他们心里清楚 1~10中的一个数(代表自己千万级的财富);他们想知道到底谁的数更大一些。1.张三找10个一模一样的箱子,按照1~10的顺序摆好,并按照自己的财富值分别往里面放入苹果梨和香蕉,具体放法为:如果序号小于自己的财富之,放入苹果,相等,则放入梨,大于自己的财富值,放入香蕉;2.李四在10个箱子里选择符合自己财产的箱子,并销毁其他箱子(其实只要保证张三不知道李四选择那个箱子即可)3.张三和李四一起打开箱子:-- 如果是苹果,张三比李四富有-- 如果是梨,两人一样有钱-- 如果是香蕉,李四比张三富有</code></pre><p>百万富翁问题采取的就是不经意传输,不经意传输的本质是让发送者发送一些消息,使得发送者不知道接收者需要那条消息,而接收者又只能获取其中自己需要的消息。</p><pre><code class="text">1. 假定发送者要发送N条消息,发送者生成N对公私钥,并将N个公钥发送给接收者。2. 接收者生成一个随机数,并用收到的N个公钥之一加密随机数(用哪个公钥钥取决于想获取哪条数据),并将密文结果回复给发送者。3. 发送者用自己的N个私钥分别解密收到随机数密文,并得到N个解密结果并将N个结果分别与要发送的N条信息进行异或运算,并将结果发给接收者。4. 接收者用自己的真实随机数与收到的消息分别做异或操作,得到的N个结果中只有一条为真实数据,其他的为随机数。</code></pre><h4 id="联邦学习"><a href="#联邦学习" class="headerlink" title="联邦学习"></a>联邦学习</h4><p>联邦学习是一种分布式的机器学习技术,系统中各节点对本地数据进行计算生成模型,再在这些模型上建立一个统一模型,例如输入预测。</p><pre><code class="text">输入预测是指输入法的智能联想,输入法本身集成有有联邦学习中的一个节点,用来学习用户输入习惯,这里并未泄露用户输入数据,输入数据仍留存在本地,只是通过输入数据构建了输入预测模型,系统中各个节点将用户的输入预测模型上传到云端,云端服务器根据这些模型计算出统一模型,返还给各个节点。当然,在真实的场景中,统一模型因该只是用户的个人模型的补充。在这个过程中,两次模糊了用户的个人信息,所以联邦学习是一种近似计算。</code></pre><h3 id="隐私计算层次模型"><a href="#隐私计算层次模型" class="headerlink" title="隐私计算层次模型"></a>隐私计算层次模型</h3><ul><li>可信执行环境是通过软硬件方法在中央处理器中构建一个安全区域,保证其内部加载的程序和数据在机密性和完整性上得到保护,使得数据在硬件层面的计算具备可信性,这是保障上层体系的正确性的基石。</li><li>秘密分享、同态加密、差分隐私、混淆电路、不经意传输是密码学中的协议或者加密算法,被上层体系所依赖。</li><li>安全多方计算、联邦学习本质上是用来处理实际的业务场景的体系,建立在密码学的基础之上。</li></ul><p> <span class="lazyload-img-span"> <img data-src="https://imgse.com/i/x6SbE8" > </sapn> <br>如果把数据的状态划分为静止、传输、操作三种,那么根本意义上的数据有效性应在在这三种状态下都得到保障。但就实际状况而言,严格的保障数据有效性付出的成本远不及收益,所以密码学通常都会考虑恶意行为。</p><ul><li>静止态:指数据处于存储状态,例如存储在外部存储之中。</li><li>传输态:指数据从一个位置转移到另一个位置的状态</li><li>操作态:指数据正在被使用,进行计算</li></ul><p>比如区块链在数据的静止态保障了数据的安全性,https协议在数据的传输态的安全性,可信执行环境保障了数据在操作态的安全性。</p><h2 id="同态加密"><a href="#同态加密" class="headerlink" title="同态加密"></a>同态加密</h2><p>同态加密:简单来说同态加密就是使得明文和密文在进行相同的运算后结果仍保持一致,<br>同态加密可以使得计算能在密文上进行<br><a href="https://imgse.com/i/x6SbE8"> <span class="lazyload-img-span"> <img data-src="https://s1.ax1x.com/2022/10/20/x6SbE8.png" > </sapn> </a></p><h3 id="同态加密的分类"><a href="#同态加密的分类" class="headerlink" title="同态加密的分类"></a>同态加密的分类</h3><ul><li>部分同态加密:只能做无限次同态加法或者只能做无限次同态乘法操作(只能累加或者累乘)</li><li>些许同态加密:可以进行有限次数的任意同态操作(可以做加法或者乘法,但是次数有限)</li><li>全同态加密:可以进行无限次的任意同态操作(可以计算任何函数)</li></ul><p>为什么说实现加法和乘法就可以计算任何函数?从门电路的角度上,如下与非门真值表所示,“1+A<em>B”可以得到与非门的所有输出(当A和B都为1时,1+A</em>B=2,而非0,因为是门电路是二进制,1+1发生了进位,然而简单门电路,只能记录最低位,所以结果是0),而与非门可以构建任意的门电路。</p><table><thead><tr><th>A</th><th>B</th><th>输出</th></tr></thead><tbody><tr><td>0</td><td>0</td><td>1</td></tr><tr><td>1</td><td>0</td><td>1</td></tr><tr><td>0</td><td>1</td><td>1</td></tr><tr><td>1</td><td>1</td><td>0</td></tr></tbody></table><h2 id="全同态加密合约的设计与实现"><a href="#全同态加密合约的设计与实现" class="headerlink" title="全同态加密合约的设计与实现"></a>全同态加密合约的设计与实现</h2><p>方案的灵感来源于论文《边缘计算下全同态加密智能合约设计》,随后我检索了相关信息,TBaas中fabric的智能合约也使用了相同的模式,论文中所使用的库是微软的SEAL,TBaas使用的是paillierb部分同态加密的内部库。随后我有在github上检索了基于go实现的同态加密库,从中挑选了有过业务与落地经验的Lattigo全同态加密库</p><h3 id="Lattigo"><a href="#Lattigo" class="headerlink" title="Lattigo"></a>Lattigo</h3><p>Lattigo:基于格的多方同态加密库,具备如下特性:</p><ul><li>全RNS BFV和CKKS方案及其各自多方版本的实现。</li><li>性能可与最先进的C++库相媲美。</li><li>密集键和稀疏键高效、高精度的自举过程,适用于全RNS CKKS。</li><li>支持跨平台构建的纯 Go 实现,包括浏览器客户端的 WASM 编译。</li></ul><h4 id="相关名词释义"><a href="#相关名词释义" class="headerlink" title="相关名词释义"></a>相关名词释义</h4><ul><li>格:是指Lattigo是基于格密码方案实现的,格是一种数学结构,本质上由N维空间中的一组点组成,并具有一定的周期结构,格密码方案是指基于基向量来生成最短的独立向量作为秘密向量(数学家和密码学家们普遍认为,对于一个维数足够高的格,通过一组随机选取的格基找到一组短格基,或得到一组线性无关的短格向量是困难的。这个问题称作最短独立向量问题)</li><li>BFV和CKKS:是两种全同态加密的两种方案</li><li>RNS:剩余数系统,用较少的数表示较多的数</li></ul><h4 id="源码结构"><a href="#源码结构" class="headerlink" title="源码结构"></a>源码结构</h4><ul><li>lattigo/ring:RNS基中多项式的模块化算术运算</li><li>lattigo/bfv:提供对整数的模块化算术。</li><li>lattigo/ckks:在复数和实数上提供近似算术。</li><li>lattigo/dbfv和:BFV和CKKS方案的多方版本,支持具有秘密共享密钥的安全多方计算解决方案。</li><li>lattigo/rlwe和 :基于 RLWE 的通用多方同态加密的通用基础。</li></ul><h4 id="Lattigo方案的可行性分析"><a href="#Lattigo方案的可行性分析" class="headerlink" title="Lattigo方案的可行性分析"></a>Lattigo方案的可行性分析</h4><p>使用lattigo/bfv来作为全同态加密合约的支撑工具,使得智能合约失去了浮点数计算能力,本质上来讲,对精度要求要求严苛的场景都不应使用浮点数,浮点数应通过同比扩大或者同比缩小来消除小数或还原小数。同时lattigo/bfv提供有加运算、减运算、非运算、模运算、乘运算、除运算等,满足基本运算需求。fabric的合约具有完整且独立的运行环境,理论上任意的应用程序在接入合约API后都可以作为合约运行,满足lattigo的运行需求。</p><h3 id="业务场景"><a href="#业务场景" class="headerlink" title="业务场景"></a>业务场景</h3><p>A集团需要统计下属子公司的财报,为了保障财务报表的不可篡改性,财务报表被写入区块链中,但是由于区块链数据本质上是公开的,可能被泄露。如果采用公钥加密财务报表,那统计报表时仍需先获取密文在本地解密后在进行计算,这个过程并不能保证数据不被篡改。</p><h4 id="同态加密解决方案"><a href="#同态加密解决方案" class="headerlink" title="同态加密解决方案"></a>同态加密解决方案</h4><ul><li>总部为这次报表统计生成专业密钥对</li><li>总部使用公钥向合约注册报表统计事件</li><li>总部告知分公司事件ID并通知其提交报表</li><li>分公司使用事件ID向合约获取事件公钥</li><li>分公司使用公钥加密报表数据并提交</li><li>总部在所有分公司完成提交后可向合约获取统计结果</li><li>合约进行统计,返回统计结果</li><li>总部使用私钥解密统计结果<br><a href="https://imgse.com/i/x6S7Hf"> <span class="lazyload-img-span"> <img data-src="https://s1.ax1x.com/2022/10/20/x6S7Hf.png" > </sapn> </a><br>在整个过程中只有各分公司知道自己提交的内容,链上存储的数据都是密文,需要私钥进行解密,而私钥掌握在总部手中。</li></ul><h2 id="合约实现"><a href="#合约实现" class="headerlink" title="合约实现"></a>合约实现</h2><pre><code class="golang">package mainimport ( "fmt" "github.com/hyperledger/fabric-chaincode-go/shim" pb "github.com/hyperledger/fabric-protos-go/peer" "github.com/tuneinsight/lattigo/v3/bfv" "github.com/tuneinsight/lattigo/v3/rlwe")type TurnoverCC struct{}func (c *TurnoverCC) Init(stub shim.ChaincodeStubInterface) pb.Response { return shim.Success(nil)}func (c *TurnoverCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response { args := stub.GetArgs() function := string(args[0]) args = args[1:] switch function { case "setPubKey": err := setPubkey(stub, string(args[0]), args[1]) if err != nil { return shim.Error(err.Error()) } return shim.Success(nil) case "getPubKey": index := string(args[0]) payload, err := getPubKey(stub, index) if err != nil { return shim.Error(err.Error()) } if payload == nil { return shim.Error(fmt.Sprintf("not found %s", index)) } return shim.Success(payload) case "submit": err := submit(stub, string(args[0]), string(args[1]), args[2]) if err != nil { return shim.Error(err.Error()) } return shim.Success(nil) case "sum": payload, err := sum(stub, string(args[0])) if err != nil { return shim.Error(err.Error()) } return shim.Success(payload) } return shim.Error(fmt.Sprintf("function %s is not found!", function))}func setPubkey(stub shim.ChaincodeStubInterface, index string, pub_key []byte) error { return stub.PutState(index, pub_key)}func getPubKey(stub shim.ChaincodeStubInterface, index string) ([]byte, error) { return stub.GetState(index)}func submit(stub shim.ChaincodeStubInterface, index, key string, text []byte) error { compositeKey, err := stub.CreateCompositeKey("indexs", []string{index, key}) if err != nil { return err } return stub.PutState(compositeKey, text)}func sum(stub shim.ChaincodeStubInterface, index string) ([]byte, error) { paramDef := bfv.PN13QP218 paramDef.T = 0x3ee0001 params, err := bfv.NewParametersFromLiteral(paramDef) if err != nil { return nil, err } evaluator := bfv.NewEvaluator(params, rlwe.EvaluationKey{}) iterator, err := stub.GetStateByPartialCompositeKey("indexs", []string{index}) if err != nil { return nil, err } res := new(bfv.Ciphertext) if iterator.HasNext() { raw, err := iterator.Next() if err != nil { return nil, err } err = res.UnmarshalBinary(raw.Value) if err != nil { return nil, err } } for iterator.HasNext() { raw, err := iterator.Next() if err != nil { return nil, err } text := new(bfv.Ciphertext) err = text.UnmarshalBinary(raw.Value) if err != nil { return nil, err } evaluator.Add(res, text, res) } return res.MarshalBinary()}func main() { err := shim.Start(new(TurnoverCC)) if err != nil { fmt.Printf("Error starting TurnoverCC chaincode: %s", err) }}</code></pre><pre><code class="go">package mainimport ( "log" "testing" "github.com/hyperledger/fabric-chaincode-go/shimtest" "github.com/tuneinsight/lattigo/v3/bfv" "github.com/tuneinsight/lattigo/v3/rlwe")func TestTurnover(t *testing.T) { // 生成参数 paramDef := bfv.PN13QP218 paramDef.T = 0x3ee0001 params, err := bfv.NewParametersFromLiteral(paramDef) if err != nil { log.Fatalln(err) } // 生成密钥对 kgen := bfv.NewKeyGenerator(params) priv_key, pub_key := kgen.GenKeyPair() // 初始化链码 cc := new(TurnoverCC) stub := shimtest.NewMockStub("turnover", cc) pubKeyArg, err := pub_key.MarshalBinary() if err != nil { log.Fatalln(err) } setEnve(stub, "test", pubKeyArg) submitData(stub, "test", "1", 2000) submitData(stub, "test", "2", 5000) submitData(stub, "test", "3", -3000) // 解密数据 ciphertext := sumData(stub, "test") decryptor := bfv.NewDecryptor(params, priv_key) text := decryptor.DecryptNew(ciphertext) // 解码数据 encoder := bfv.NewEncoder(params) res := encoder.DecodeIntNew(text) log.Println(res[0])}func setEnve(stub *shimtest.MockStub, index string, pubKeyArg []byte) { res := stub.MockInvoke("1", [][]byte{[]byte("setPubKey"), []byte(index), pubKeyArg}) if res.Status == 500 { log.Println(res.Message) }}func sumData(stub *shimtest.MockStub, index string) *bfv.Ciphertext { res := stub.MockInvoke("1", [][]byte{[]byte("sum"), []byte(index)}) ciphertext := new(bfv.Ciphertext) err := ciphertext.UnmarshalBinary(res.Payload) if err != nil { log.Fatalln(err) } return ciphertext}func submitData(stub *shimtest.MockStub, index, key string, data int64) { // 生成参数 paramDef := bfv.PN13QP218 paramDef.T = 0x3ee0001 params, err := bfv.NewParametersFromLiteral(paramDef) if err != nil { log.Fatalln(err) } // 获取公钥 res := stub.MockInvoke("1", [][]byte{[]byte("getPubKey"), []byte(index)}) if res.Status == 500 { log.Println(res.Message) } var pubKey rlwe.PublicKey err = pubKey.UnmarshalBinary(res.Payload) if err != nil { log.Fatalln(err) } text := bfv.NewPlaintext(params) // 生成一个编码器,并将数据编码到文本中 encoder := bfv.NewEncoder(params) encoder.Encode([]int64{data}, text) // 生成公钥加密器,并加密文本 encryptor := bfv.NewEncryptor(params, &pubKey) ciphertext := encryptor.EncryptNew(text) raw, err := ciphertext.MarshalBinary() if err != nil { log.Fatalln(err) } res = stub.MockInvoke("1", [][]byte{[]byte("submit"), []byte(index), []byte(key), raw}) if res.Status == 500 { log.Println(res.Message) }}</code></pre>]]></content>
<tags>
<tag> golang </tag>
</tags>
</entry>
<entry>
<title>linux| && ||</title>
<link href="/2022/10/21/linux/"/>
<url>/2022/10/21/linux/</url>
<content type="html"><![CDATA[<h2 id="amp-amp-和-amp"><a href="#amp-amp-和-amp" class="headerlink" title="&& 和 &"></a>&& 和 &</h2><p><code>& 表示任务后台执行,与nohup命令功能差不多。</code></p><pre><code class="text"># 运行jar包,并且置于后台执行,执行的日志重定向到当前默认的log.txt文件中[root@localhost local]$ java -jar test.jar > log.txt &</code></pre><pre><code class="text">&& 表示前一条命令执行成功时,才执行后一条命令。</code></pre><pre><code class="text"># 执行ls -l成功后,执行cd ..[root@localhost tmp]$ ls -l && cd .. 总用量 4 -rw-r–r–. 1 root root 2252 1月 4 22:25 log.txt -rw——-. 1 root root 0 1月 3 23:23 yum.log [root@localhost /]$</code></pre><h2 id="和"><a href="#和" class="headerlink" title="| 和 ||"></a>| 和 ||</h2><p><code>| 表示管道,上一条命令的输出,作为下一条命令参数(输入)。</code></p><pre><code class="text"># 查询全部进程后输出结果在进行过滤跟 进行中包含aux的进程[root@localhost ~]$ ps -aux | grep auxWarning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQroot 53 0.0 0.0 0 0 ? S 16:33 0:00 [ata_aux]root 2379 4.0 0.1 110224 1172 pts/2 R+ 22:55 0:00 ps -auxroot 2380 0.0 0.0 103316 868 pts/2 D+ 22:55 0:00 grep aux</code></pre><p><code>|| 表示上一条命令执行失败后,才执行下一条命令。</code></p><pre><code class="text">[root@localhost tmp]$ als -l || cd ..-bash: als: command not found[root@localhost /]$</code></pre><h2 id="gt-和-gt-gt"><a href="#gt-和-gt-gt" class="headerlink" title="> 和 >>"></a>> 和 >></h2><p><code>> 表示stdout标准输出信息重定向输出,覆盖写。</code></p><pre><code class="text">[root@localhost ~]$ cat test.txtHello[root@localhost ~]$ echo 'World' > test.txt[root@localhost ~]$ cat test.txtWorld</code></pre><p><code>>> 表示内容追加写。</code></p><pre><code class="text">[root@localhost ~]$ cat test.txtHello[root@localhost ~]$ echo 'World' >> test.txt[root@localhost ~]$ cat test.txtHelloWorld</code></pre><h2 id="amp-gt-、2-gt-amp-1-和-2-gt-1"><a href="#amp-gt-、2-gt-amp-1-和-2-gt-1" class="headerlink" title="&> 、2>&1 和 2>1"></a>&> 、2>&1 和 2>1</h2><p><code>&> 表示stdout标准输出和stderr错误输出信息,重定向输出,覆盖写。</code></p><pre><code class="text">[root@localhost ~]$ cat test.txtWorld[root@localhost ~]$ lll-bash: lll: command not found[root@localhost ~]$ lll > test.txt[root@localhost ~]$ cat test.txt# 由于这个是错误信息,所以不能使用标准输出>将信息重定向到test文件中,但覆盖写为空# 所以错误信息直接在控制台打印出来了[root@localhost ~]$ lll &> test.txt[root@localhost ~]$ cat test.txt-bash: lll: command not found# 使用&>重定向错误信息没有输出到控制台了,表示错误信息正确重定向到了test文件,也同样是覆盖写</code></pre><p><code>2>&1 表示把标准错误的输出重定向到标准输出1,&指示不要把1当做普通文件,而是fd=1即标准输出处理。</code></p><p><code>2>1 表示把标准错误的输出重定向到1,但这个1不是标准输出,而是一个名为1的文件。</code></p><h2 id="linux重定向的设备代码"><a href="#linux重定向的设备代码" class="headerlink" title="linux重定向的设备代码"></a>linux重定向的设备代码</h2><ul><li>空设备文件/dev/null</li><li>标准输入(stdin) 代码为0,实际映射关系:/dev/stdin -> /proc/self/fd/0</li><li>标准输出(stdout)代码为1,实际映射关系:/dev/stdout -> /proc/self/fd/1</li><li>标准错误输出(stderr)代码为2,实际映射关系:/dev/stderr ->/pro/self/fd/2</li></ul><h3 id="command-gt-a-2-gt-1-、command-gt-a-2-gt-a-与-command-gt-a-2-gt-amp-1的区别"><a href="#command-gt-a-2-gt-1-、command-gt-a-2-gt-a-与-command-gt-a-2-gt-amp-1的区别" class="headerlink" title="command>a 2>1 、command>a 2>a 与 command>a 2>&1的区别"></a>command>a 2>1 、command>a 2>a 与 command>a 2>&1的区别</h3><pre><code class="text">1. command>a 2>&1 等价于 command 1>a 2>&1 意思为执行command产生的标准输入重定向到文件a中,标准错误也重定向到文件a中。2. command>a 2>a 不等价于 command 1>a 2>&1,其区别如下: i. command>a 2>a打开文件两次,而command 1>a 2>&1只打开文件一次; ii. command>a 2>a由于打开文件两次,导致stdout被stderr覆盖; iii. 从IO效率上来讲,command 1>a 2>&1比command 1>a 2>a的效率更高。3. command>a 2>1 等价于 command 1>a 2>1 意思为执行command产生的标准输入重定向到文件a中,标准错误重定向到文件1中。</code></pre>]]></content>
</entry>
<entry>
<title>Dockerfile</title>
<link href="/2022/10/20/Dockerfile/"/>
<url>/2022/10/20/Dockerfile/</url>
<content type="html"><![CDATA[<pre><code class="Dockerfile"># 定义基础镜像版本ARG GO_VERSION=1.17.13ARG ALPINE_VERSION=3.16# 构建运行环境FROM alpine:${ALPINE_VERSION} AS base# 换源,同步时区RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositoriesRUN apk update && apk add --no-cache tzdata \ && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && echo "Asia/Shanghai" > /etc/timezone# 构建编译时环境FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build# 设置go envENV GOPATH="/go" \ GO111MODULE="on" \ GOPROXY="https://goproxy.cn" \ CGO_ENABLED="0"# 换源,安装编译依赖RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositoriesRUN apk update && apk add --no-cache \ git \ makeCOPY . /go/src/github.com/Ning-Qing/templeWORKDIR /go/src/github.com/Ning-Qing/templeRUN make build# 拷贝二进制文件FROM baseWORKDIR /fabric-relayerCOPY --from=build /go/src/github.com/Ning-Qing/temple/build/fabric-relayer ./templeENTRYPOINT ["./temple"]# 使用CMD传参CMD ["-h"]</code></pre>]]></content>
<tags>
<tag> golang </tag>
</tags>
</entry>
<entry>
<title>Makefile</title>
<link href="/2022/10/20/Makefile/"/>
<url>/2022/10/20/Makefile/</url>
<content type="html"><![CDATA[<pre><code class="Makefile">DOCKER_NS ?= github.com/Ning-QingPKG_NS ?= github.com/NingQingPKG_NAME ?= templePKG_VERSION ?= 1.0.0GO_VERSION ?= 1.17.13ALPINE_VERSION ?= 3.16SUPPORTED_PLATFORMS = linux/arm64,linux/amd64export PKG_VERSIONARCH := $(shell arch)OS := $(shell uname -s)ifeq ($(ARCH),x86_64) ARCH=amd64else ifeq ($(ARCH),arm64) ARCH=arm64else exit $$?endififeq ($(OS),Linux) OS=linuxelse exit $$?endifbuild: @echo "Building $(PKG_NAME)..." @go mod tidy && go build -o ./build/$(PKG_NAME) \ -ldflags "-X 'main.application=$(PKG_NAME)' \ -X 'main.version=$(PKG_VERSION)'" \ . @echo "see ./build/$(PKG_NAME)" run: @go mod tidy && go run .image: @echo "Building $(PKG_NAME) docker image - $(DOCKER_NS)/$(PKG_NAME):$(PKG_VERSION)" @docker build --no-cache -f Dockerfile \ --build-arg GO_VERSION=$(GO_VERSION) \ --build-arg ALPINE_VERSION=$(ALPINE_VERSION) \ -t $(DOCKER_NS)/$(PKG_NAME):$(PKG_VERSION) . @docker tag $(DOCKER_NS)/$(PKG_NAME):$(PKG_VERSION) $(PKG_NAME):latest @echo "scan image $(DOCKER_NS)/$(PKG_NAME):$(PKG_VERSION) or $(PKG_NAME):latest" @echo "maybe you want psuh image to $(DOCKER_NS),you can make push"push: @echo "push image $(DOCKER_NS)/$(PKG_NAME):$(PKG_VERSION) to $(DOCKER_NS)" @docker push $(DOCKER_NS)/$(PKG_NAME):$(PKG_VERSION)image-relase: @docker buildx create --use --name $(PKG_NAME)-builder @echo "Building $(PKG_NAME) docker image relase - $(DOCKER_NS)/$(PKG_NAME):$(PKG_VERSION)" @docker buildx build \ --platform $(SUPPORTED_PLATFORMS) \ --build-arg GO_VERSION=$(GO_VERSION) \ --build-arg ALPINE_VERSION=$(ALPINE_VERSION) \ -f Dockerfile -t $(DOCKER_NS)/$(PKG_NAME):$(PKG_VERSION) . --push @docker tag $(DOCKER_NS)/$(PKG_NAME):$(PKG_VERSION) $(PKG_NAME):latest @echo "you can go to $(DOCKER_NS) see image $(DOCKER_NS)/$(PKG_NAME):$(PKG_VERSION)" @docker buildx rm $(PKG_NAME)-builderclean: @rm -rf build @docker buildx ls | grep $(PKG_NAME)-builder && docker buildx rm $(PKG_NAME)-builder || exit 0.PHONY: build image image-relase clean</code></pre>]]></content>
<tags>
<tag> golang </tag>
</tags>
</entry>
<entry>
<title>options模式</title>
<link href="/2022/10/20/options%E6%A8%A1%E5%BC%8F/"/>
<url>/2022/10/20/options%E6%A8%A1%E5%BC%8F/</url>
<content type="html"><![CDATA[<pre><code class="golang">const ( DefaultHost = "127.0.0.1" DefaultPort = "8080")type Option func(c *Client)type Client struct { Host string Port string}func NewClient(options ...Option) *Client { c := &Client{ Host: DefaultHost, Port: DefaultPort, } for _, option := range options { option(c) } return c}func WitchHost(host string) Option { return func(c *Client) { c.Host = host }}</code></pre>]]></content>
<tags>
<tag> golang </tag>
</tags>
</entry>
<entry>
<title>windows去除桌面快捷图标</title>
<link href="/2022/10/20/windows%E5%8E%BB%E9%99%A4%E6%A1%8C%E9%9D%A2%E5%BF%AB%E6%8D%B7%E5%9B%BE%E6%A0%87/"/>
<url>/2022/10/20/windows%E5%8E%BB%E9%99%A4%E6%A1%8C%E9%9D%A2%E5%BF%AB%E6%8D%B7%E5%9B%BE%E6%A0%87/</url>
<content type="html"><![CDATA[<h2 id="去掉小箭头"><a href="#去掉小箭头" class="headerlink" title="去掉小箭头"></a>去掉小箭头</h2><pre><code class="bat">reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v 29 /d "%systemroot%\system32\imageres.dll,197" /t reg_sz /ftaskkill /f /im explorer.exeattrib -s -r -h "%userprofile%\AppData\Local\iconcache.db"del "%userprofile%\AppData\Local\iconcache.db" /f /qstart explorerpause</code></pre><p>复制上面的代码。新建一个文本文件。粘贴后另存为.bat文件,然后以管理员身份打开。<br>ok!</p><h2 id="恢复小箭头"><a href="#恢复小箭头" class="headerlink" title="恢复小箭头"></a>恢复小箭头</h2><pre><code class="bat">reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v 29 /ftaskkill /f /im explorer.exeattrib -s -r -h "%userprofile%\AppData\Local\iconcache.db"del "%userprofile%\AppData\Local\iconcache.db" /f /qstart explorerpause</code></pre><p>同理,将上述代码另存为.bat文件,管理员身份打开。就可恢复小箭头了 </p>]]></content>
<tags>
<tag> 美化 </tag>
</tags>
</entry>
<entry>
<title>hello world</title>
<link href="/2022/10/20/helloworld/"/>
<url>/2022/10/20/helloworld/</url>
<content type="html"><![CDATA[<pre><code class="golang"> fmt.Println("Hello world!")</code></pre>]]></content>
</entry>
</search>