sample_chain/common/kgc/sign.go

73 lines
2.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package kgc
import (
"crypto/elliptic"
"fmt"
)
// Certificateless_Sign(prikey, pubkey, msg, ID)
func Certificateless_Sign(pri_key, pub_key, msg []byte, id string) (signature []byte, err error) {
curve := elliptic.P256()
s := BytesToBig(pri_key)
x, y := bytes_halve(pub_key)
Qx := BytesToBig(x)
Qy := BytesToBig(y)
//fmt.Println("公钥第一部分长度为:", len(x))
//fmt.Println("公钥第二部分长度为:", len(y))
ID := []byte(id)
PK_pub := "7196e9722d561a0fea21485fc16140096cc9b88f7174aec7508f14a7b85b61ba299292c726367bbcbf8f00b977849164bf9d3fd6260e55dd6498517bc0dec541"
pk1, pk2 := string_halve(PK_pub)
//fmt.Println("KGC公钥第二部分长度为", len([]byte(pk1)))
//fmt.Println("KGC公钥第二部分长度为", len([]byte(pk2)))
PKx := BytesToBig([]byte(pk1))
PKy := BytesToBig([]byte(pk2))
Ux, Uy, v := SignThumb(curve, ID, msg, s, Qx, Qy, PKx, PKy)
sig := mergeBigInts(Ux, Uy, v)
//fmt.Println("打印签名长度:", len(sig))
//fmt.Println("签名得到的v值为", v)
return sig, nil
}
// Certificateless_Verify(publicKey, ID, signature, msg)
func Certificateless_Verify(pubkey []byte, id string, signature, msg []byte) error {
//x, y := bytes_halve(pubkey)
//fmt.Println("公钥第一部分长度为:", len(x))
//fmt.Println("公钥第二部分长度为:", len(y))
//fmt.Println("接收到消息!!!!!!!!!")
curve := elliptic.P256()
x, y := bytes_halve(pubkey)
Qx := BytesToBig(x)
Qy := BytesToBig(y)
//fmt.Println(pubkey)
ID := []byte(id)
PK_pub := "7196e9722d561a0fea21485fc16140096cc9b88f7174aec7508f14a7b85b61ba299292c726367bbcbf8f00b977849164bf9d3fd6260e55dd6498517bc0dec541"
pk1, pk2 := string_halve(PK_pub)
PKx := BytesToBig([]byte(pk1))
PKy := BytesToBig([]byte(pk2))
Ux, Uy, v := AnalSig(signature)
//fmt.Println("打印接收参数111", v)
//fmt.Println("转换后的签名结果为", Ux, Uy, v)
err := VerifyThumb(curve, ID, msg, Qx, Qy, PKx, PKy, Ux, Uy, v)
if err != nil {
fmt.Println("shibai-----------------------------------------")
return err
}
//fmt.Println("签名验证chenggongllllllllsssssssssssssssssss")*/
return nil
}