Skip to content

Commit

Permalink
add ecdsa page
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowonpaper committed Sep 21, 2024
1 parent 57bb1b0 commit 7a4f938
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
6 changes: 6 additions & 0 deletions malta.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
["Open redirect", "/open-redirect"]
]
},
{
"title": "Cryptography",
"pages": [
["ECDSA", "/cryptography/ecdsa"]
]
},
{
"title": "Links",
"pages": [
Expand Down
83 changes: 83 additions & 0 deletions pages/cryptography/ecdsa.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
title: "Elliptic curve digital signature algorithm (ECDSA)"
---

# Elliptic curve digital signature algorithm (ECDSA)

ECDSA is a digital signature algorithm using elliptic-curve cryptography. A private key is used to sign a message and a public key is used verify the signature.

The message is hashed with algorithms like SHA-256 before signing.

```go
import (
"crypto/ecdsa"
"crypto/rand"
"crypto/sha256"
)

msg := "Hello world!"
hash := sha256.Sum256([]byte(msg))
signature, err := ecdsa.SignASN1(rand.Reader, privateKey, hash[:])
```

## Signatures

ECDSA signatures are represented using a pair of positive integers, (r, s).

### IEEE P1363

In the IEEE P1363 format, the signature is the concatenation of r and s. The values are encoded as big-endian bytes with a size equivalent to the curve size. For example, P-256 is 256 bits or 32 bytes in size.

```ts
r || s;
```

### PKIX

In [RFC 5480](https://datatracker.ietf.org/doc/html/rfc5480) by the PKIX working group, the signature is ASN.1 DER encoded sequence of r and s.

```
SEQUENCE {
r INTEGER,
s INTEGER
}
```

## Public keys

ECDSA public keys are represented as a pair of positive integers, (x, y).

### SEC1

In SEC 1, which defines ECDSA, public keys can either be uncompressed or compressed. Uncompressed keys are the concatenation of x and y, with a leading `0x04` byte. The values are encoded as big-endian bytes with a size equivalent to the curve size. For example, P-256 is 256 bits or 32 bytes in size.

```
0x04 || x || y
```

Compressed keys are the x value with a leading `0x02` if x is even or `0x03` byte if odd. The y value can be calculated from x and the curve.

```
0x02 || x
0x03 || x
```

### PKIX

In [RFC 5480](https://datatracker.ietf.org/doc/html/rfc5480) by the PKIX working group, the public key is represented as a `SubjectPublicKeyInfo` ASN.1 sequence. The `subjectPublicKey` is either the compressed or uncompressed SEC1 public key.

```
SubjectPublicKeyInfo := SEQUENCE {
algorithm AlgorithmIdentifier,
subjectPublicKey BIT STRING
}
```

The `AlgorithmIdentifier` for ECDSA is an ASN.1 sequence with the ECDSA object identifier (`1.2.840.10045.2.1`) and the curve (e.g. `1.2.840.10045.3.1.7` for P-256 curve)

```
AlgorithmIdentifier := SEQUENCE {
algorithm OBJECT IDENTIFIER
namedCurve OBJECT IDENTIFIER
}
```

0 comments on commit 7a4f938

Please sign in to comment.