Skip to content

Commit 5656191

Browse files
committed
x509
1 parent c7f593e commit 5656191

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

common/crypto/x509/x509.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -323,25 +323,19 @@ func createTBSCertificate(template *Certificate, sigAlg SignatureAlgorithm) ([]b
323323
var publicKeyBytes []byte
324324
if template.PublicKey != nil {
325325
if gostPub, ok := template.PublicKey.(*gost3410.PublicKey); ok {
326-
// Encode GOST public key as X and Y coordinates
326+
// Encode GOST public key according to GOST R 34.10-2012 standard
327+
// The public key should be encoded as a BIT STRING containing the raw public key
327328
xBytes := gostPub.X.Bytes()
328329
yBytes := gostPub.Y.Bytes()
329330

330-
// Create GOST public key structure
331-
gostPubKey := struct {
332-
X []byte
333-
Y []byte
334-
}{
335-
X: xBytes,
336-
Y: yBytes,
337-
}
331+
// Combine X and Y coordinates into a single byte array
332+
// GOST public key format: 04 || X || Y (uncompressed format)
333+
pubKeyRaw := make([]byte, 1+len(xBytes)+len(yBytes))
334+
pubKeyRaw[0] = 0x04 // Uncompressed point indicator
335+
copy(pubKeyRaw[1:], xBytes)
336+
copy(pubKeyRaw[1+len(xBytes):], yBytes)
338337

339-
// Marshal to ASN.1 DER
340-
pubKeyDER, err := asn1.Marshal(gostPubKey)
341-
if err != nil {
342-
return nil, fmt.Errorf("failed to marshal GOST public key: %w", err)
343-
}
344-
publicKeyBytes = pubKeyDER
338+
publicKeyBytes = pubKeyRaw
345339
}
346340
}
347341

0 commit comments

Comments
 (0)