☕
Pause for minutes until .
Remaining:
Pius Walter
T4INF1202: Kryptologie
Part 9: Asymmetric Signatures Part 1
2026-05-27
Table of Contents
Recap
Cryptographic Message Encoding
4
Unique message encoding
  • We are using cryptographic hash functions in every signing operation
  • This allows signatures over arbitrary length inputs
  • It also means that each bit of the input needs to be correct in its representation, otherwise the hash function will output something entirely different
  • This is straightforward when dealing with raw bytes, you would just take them as they are and hash them
Unique message encoding
  • What happens, however, when we have semantic representation of data that we would like to sign?
  • For example, say we want to sign a single boolean value: true or false
  • C convention: boolean has length 8 bits; 0 is false, everything else is true
  • This would create ambiguous encoding
Unique message encoding
  • Or let's say you want to sign JSON data.
  • Two representations can be semantically equivalent yet have completely different byte representations/hash values.
{ "foo": "bar", "value": 9 }
or
{"value":9,"foo":"bar"}
Unique message encoding
  • In order to support this, we need a way to uniquely encode every semantic representation into exactly one binary representation.
  • This needs to be a distinguished representation, the authoritative representation used that is applied before signing data.
Message encoding
  • This is one of the problems which ASN.1Abstract Syntax Notation One and their respective encoding aims to solve
  • ITU-T standard, published first in 1984. First X.208, later versions in X.68x series.
  • Much of the PKI infrastructure we still use goes back to this and related standards, e.g., X.509 is also created by ITU-T and specified in ASN.1
Abstract syntax notation
  • As the name indicates, ASN.1 is an abstract way of describing the syntax of data structures
  • There are various primitive data types: integer, boolean, bit strings, byte strings (octet strings), object IDs (OIDObject identifiers)
  • And compound types: sequence (i.e., an array), set
  • The notation entirely decouples the representation of a data structure from its representation
Abstract syntax notation: example
Circle ::= SEQUENCE {
    center_x INTEGER,
    center_y INTEGER,
    radius INTEGER,
    name UTF8String
}
Abstract syntax notation
  • There are various language bindings for all kinds of languages
  • Varying feature support (ASN.1 is quite feature rich and most implementations don't support all expressions)
  • Python: pyasn1
Abstract syntax notation: example
from pyasn1.type.univ import Sequence, Integer
from pyasn1.type.char import UTF8String
from pyasn1.type.namedtype import NamedType, NamedTypes

class Circle(Sequence):
    componentType = NamedTypes(
        NamedType("center_x", Integer()),
        NamedType("center_y", Integer()),
        NamedType("radius", Integer()),
        NamedType("name", UTF8String()),
    )
Abstract syntax notation
  • We have now created a Circle class with respective typed attributes
  • This class can be instantiated and the attributes can get values
  • Obviously, types can be nested within other types
Abstract syntax notation: example
c = Circle()
c["center_x"] = 10
c["center_y"] = 20
c["radius"] = 100
c["name"] = "Pretty circle"
Abstract syntax notation
  • Until now, we did not gain much – we've introduced new syntax and have a way to assign values to these objects
  • The real advantage lies within the specification of how encoding of such data has to occur to translate it into byte streams
  • Frameworks typically support the most important encodings (but typically again not all encodings)
Abstract syntax notation: example
from pyasn1.codec.der.encoder import encode
e = encode(c)
print(e)
# b'0\x18\x02\x01\n\x02\x01\x14\x02\x01d\x0c\rPretty circle'

print(e.hex())
# 301802010a0201140201640c0d50726574747920636972636c65
Codecs
Codecs
Decoding ASN.1 DER with OpenSSL
$ openssl asn1parse -inform der -in example.der -i
    0:d=0  hl=2 l=  24 cons: SEQUENCE
    2:d=1  hl=2 l=   1 prim:  INTEGER           :0A
    5:d=1  hl=2 l=   1 prim:  INTEGER           :14
    8:d=1  hl=2 l=   1 prim:  INTEGER           :64
   11:d=1  hl=2 l=  13 prim:  UTF8STRING        :Pretty circle
Asymmetric Signatures
21
Elliptic Curve Cryptosystem
QBEntEozXWioE: y^2 = x^3 + ax + bkIt7msRdzcHK
Elliptic curves
  • For cryptographic purposes, elliptic curves typically are used in finite fields
  • Typically, either Q4mta4Ck5NLH\mathbb{F}_{2^m}Zf1qH71g5gJY (“binary curve”) or Q4mta4Ck5NLH\mathbb{F}_pZf1qH71g5gJY with prime Q4mta4Ck5NLHpZf1qH71g5gJY is used (prime field curve)
  • This means that we have an additional parameter Q4mta4Ck5NLHmZf1qH71g5gJY or Q4mta4Ck5NLHpZf1qH71g5gJY that is relevant for the curve definition
  • The values that define the curve are called domain parameters
Elliptic curves
  • The number of points that satisfy the curve equation plus one (point at infinity) is called the order of the curve Q4mta4Ck5NLH|E|Zf1qH71g5gJY
  • Points also have an order Q4mta4Ck5NLHnZf1qH71g5gJY, which can be either Q4mta4Ck5NLHnZf1qH71g5gJY or a product of factors of Q4mta4Ck5NLH|E|Zf1qH71g5gJY (i.e., a subgroup)
  • One special point is chosen: the generator point Q4mta4Ck5NLHGZf1qH71g5gJY
  • You can think of it as the “1-element”
  • Another special element is the point at infinity Q4mta4Ck5NLH\mathcal OZf1qH71g5gJY, which you can view as the “0-element”
Elliptic curves
  • The order of the generator Q4mta4Ck5NLHGZf1qH71g5gJY is the domain parameter Q4mta4Ck5NLHnZf1qH71g5gJY
  • The last domain parameter is Q4mta4Ck5NLHhZf1qH71g5gJY, the cofactor of the curve. Q4mta4Ck5NLHh = \frac{|E|}{n}Zf1qH71g5gJY
  • For cryptographic purposes, we want small Q4mta4Ck5NLHhZf1qH71g5gJY (Q4mta4Ck5NLHGZf1qH71g5gJY spans a large or full subgroup)
  • For curves in which Q4mta4Ck5NLH|E| = nZf1qH71g5gJY it follows that Q4mta4Ck5NLHh = 1Zf1qH71g5gJY
Domain parameters
  • We now have a fully defined elliptic curve; for the remainder of the presentation, assume curves in Q4mta4Ck5NLH\mathbb{F}_pZf1qH71g5gJY
  • Domain parameters: Q4mta4Ck5NLHp, a, b, n, h, GZf1qH71g5gJY
  • For many typically used curves, these domain parameters are fixed by the curve name; you simply look them up
  • You do not want to generate them yourself, as generating secure curve parameters is a topic of its own
Key generation
  • ECC key generation is fairly straightforward, maybe even simpler than for RSARivest-Shamir-Adleman:
    1. Select private key (integer scalar):
      Q4mta4Ck5NLH0 < d < nZf1qH71g5gJY
    2. Compute public key (point on curve):
      Q4mta4Ck5NLHQ = dGZf1qH71g5gJY
Signing
  • Public and private key are distinct types
  • One is a point, the other one is an integer; they are not interchangeable.
  • Hence, we need a different way of signing using that private scalar Q4mta4Ck5NLHdZf1qH71g5gJY and one that can verify the signature using the point Q4mta4Ck5NLHQZf1qH71g5gJY.
ECDSA premise
ECDSA signing
  • In ECDSAElliptic Curve Digital Signature Algorithm, the data to be signed Q4mta4Ck5NLHmZf1qH71g5gJY is first hashed by a hash function Q4mta4Ck5NLHHZf1qH71g5gJY
  • Q4mta4Ck5NLHe = H(m)Zf1qH71g5gJY
  • Then, a random integer value Q4mta4Ck5NLHkZf1qH71g5gJY is chosen by the signer, so that Q4mta4Ck5NLH0 < k < nZf1qH71g5gJY
  • Q4mta4Ck5NLHkZf1qH71g5gJY is multiplied with the generator point Q4mta4Ck5NLHGZf1qH71g5gJY to give point Q4mta4Ck5NLHRZf1qH71g5gJY:
    Q4mta4Ck5NLHR = kG = \begin{pmatrix} r_x \\ r_y \end{pmatrix}Zf1qH71g5gJY
ECDSA signing
  • In affine representation, R has an X and Y coordinate on the plane, i.e., two coordinates with respective values from Q4mta4Ck5NLH0Zf1qH71g5gJY to Q4mta4Ck5NLHp-1Zf1qH71g5gJY
  • Only the X coordinate Q4mta4Ck5NLHr_xZf1qH71g5gJY (commonly only referred to as Q4mta4Ck5NLHrZf1qH71g5gJY) of point Q4mta4Ck5NLHRZf1qH71g5gJY is used for the next step:
    QBEntEozXWios = \frac{e + r_x d}{k} \mod nkIt7msRdzcHK
  • The tuple Q4mta4Ck5NLH(r_x, s)Zf1qH71g5gJY comprises the ECDSAElliptic Curve Digital Signature Algorithm signature
ECDSA verification
  • That tuple is usually just called Q4mta4Ck5NLH(r, s)Zf1qH71g5gJY
  • When validating a signature, the receiver now has the public key Q4mta4Ck5NLHQZf1qH71g5gJY of the signer along with the message Q4mta4Ck5NLHmZf1qH71g5gJY and signature tuple Q4mta4Ck5NLH(r, s)Zf1qH71g5gJY
  • As a first step, they also compute the hash value Q4mta4Ck5NLHe = H(m)Zf1qH71g5gJY
  • Then, they perform a modular inversion: Q4mta4Ck5NLHw = s^{-1} \mod nZf1qH71g5gJY
ECDSA verification
  • Two integer values Q4mta4Ck5NLHu_1, u_2Zf1qH71g5gJY are then computed so that
    QBEntEozXWiou_1 = e \cdot w \mod nkIt7msRdzcHK
    QBEntEozXWiou_2 = r \cdot w \mod nkIt7msRdzcHK
  • Finally, a point Q4mta4Ck5NLHPZf1qH71g5gJY based on those computations:
    QBEntEozXWioP = u_1 G + u_2 QkIt7msRdzcHK
ECDSA verification
  • Q4mta4Ck5NLHPZf1qH71g5gJY also has, in its affine representation, an X and Y coordinate:
    QBEntEozXWioP = \begin{pmatrix} p_x \\ p_y \end{pmatrix}kIt7msRdzcHK
  • The signature validation is regarded as successful if and only if Q4mta4Ck5NLHp_x \stackrel{?}{=} rZf1qH71g5gJY
ECDSA explained
  • To understand why ECDSAElliptic Curve Digital Signature Algorithm works, you simply can plug in the computations in the equations and see what happens.
  • Let us start from the end of the verification, namely
    QBEntEozXWioP = u_1 G + u_2 QkIt7msRdzcHK
  • Plugging in Q4mta4Ck5NLHu_1, u_2, wZf1qH71g5gJY gives:
    QBEntEozXWioP = ewG + rwQ = w(eG + rQ) = s^{-1}(eG + rQ)kIt7msRdzcHK
ECDSA explained
QBEntEozXWioP = s^{-1}(eG + rQ)kIt7msRdzcHK
ECDSA explained
QBEntEozXWioP = s^{-1}(eG + rQ)kIt7msRdzcHK
QBEntEozXWioP = s^{-1}(eG + rdG)kIt7msRdzcHK
ECDSA explained
QBEntEozXWioP = s^{-1}(eG + rQ)kIt7msRdzcHK
QBEntEozXWioP = s^{-1}(eG + rdG)kIt7msRdzcHK
QBEntEozXWioP = s^{-1}(e + rd)GkIt7msRdzcHK
ECDSA explained
QBEntEozXWioP = s^{-1}(eG + rQ)kIt7msRdzcHK
QBEntEozXWioP = s^{-1}(eG + rdG)kIt7msRdzcHK
QBEntEozXWioP = s^{-1}(e + rd)GkIt7msRdzcHK
QBEntEozXWioP = \left(\frac{e + rd}{k}\right)^{-1}(e + rd)GkIt7msRdzcHK
ECDSA explained
QBEntEozXWioP = \left(\frac{e + rd}{k}\right)^{-1}(e + rd)G = \frac{k(e + rd)}{e + rd} G = kGkIt7msRdzcHK

  • This is the definition of Q4mta4Ck5NLHPZf1qH71g5gJY, i.e., Q4mta4Ck5NLHP = kGZf1qH71g5gJY
  • Hence, if Q4mta4Ck5NLHeZf1qH71g5gJY was correct and the signature valid, then Q4mta4Ck5NLHP_x = rZf1qH71g5gJY
ECDSA issues
38
PlayStation copy protection
Misusing ECDSA
  • Note that in ECDSAElliptic Curve Digital Signature Algorithm, Q4mta4Ck5NLHr = (kG)_xZf1qH71g5gJY depends only on the randomly chosen value Q4mta4Ck5NLHkZf1qH71g5gJY
  • Therefore, if in your implementation you just choose a fixed Q4mta4Ck5NLHkZf1qH71g5gJY, then Q4mta4Ck5NLHrZf1qH71g5gJY is also always going to be the same value
  • Hence, your signature is cut in half because you don't need to explicitly transmit Q4mta4Ck5NLHrZf1qH71g5gJY and can just use Q4mta4Ck5NLHsZf1qH71g5gJY as the signature
  • Looks like a great efficiency gain
Misusing ECDSA
  • This leads to a particularly spectacular attack
  • Imagine a fixed value Q4mta4Ck5NLHkZf1qH71g5gJY and, therefore, also a fixed value Q4mta4Ck5NLHrZf1qH71g5gJY
  • Imagine furthermore that an attacker has two messages Q4mta4Ck5NLHm_1, m_2Zf1qH71g5gJY that have valid signatures Q4mta4Ck5NLHs_1, s_2Zf1qH71g5gJY
Exploiting ECDSA
QBEntEozXWios_1 = \frac{e_1 + dr}{k} \mod nkIt7msRdzcHK
QBEntEozXWios_2 = \frac{e_2 + dr}{k} \mod nkIt7msRdzcHK

  • Up next: Solve these two equations for Q4mta4Ck5NLHkZf1qH71g5gJY
Exploiting ECDSA
QBEntEozXWiok = \frac{e_1 + dr}{s_1} \mod nkIt7msRdzcHK
QBEntEozXWiok = \frac{e_2 + dr}{s_2} \mod nkIt7msRdzcHK

  • Then substitute Q4mta4Ck5NLHkZf1qH71g5gJY in one of the equations for the other
Exploiting ECDSA
QBEntEozXWio\frac{e_1 + dr}{s_1} = \frac{e_2 + dr}{s_2} \mod nkIt7msRdzcHK
QBEntEozXWios_2(e_1 + dr) = s_1(e_2 + dr) \mod nkIt7msRdzcHK

  • Expand the equation and rearrange...
Exploiting ECDSA
QBEntEozXWios_2 e_1 + s_2 dr = s_1 e_2 + s_1 dr \mod nkIt7msRdzcHK
QBEntEozXWios_2 e_1 - s_1 e_2 = s_1 dr - s_2 dr \mod nkIt7msRdzcHK
QBEntEozXWios_2 e_1 - s_1 e_2 = d(s_1 r - s_2 r) \mod nkIt7msRdzcHK

  • One last division.
Exploiting ECDSA
QBEntEozXWiod = \frac{s_2 e_1 - s_1 e_2}{s_1 r - s_2 r} \mod nkIt7msRdzcHK

  • Q4mta4Ck5NLHs_1, s_2Zf1qH71g5gJY are the signatures which the attacker has
  • Q4mta4Ck5NLHe_1, e_2Zf1qH71g5gJY are the hashes over Q4mta4Ck5NLHm_1, m_2Zf1qH71g5gJY which the attacker has
  • Q4mta4Ck5NLHrZf1qH71g5gJY is the fixed value which the attacker has
  • Q4mta4Ck5NLHdZf1qH71g5gJY is the private signing key which the attacker now also has
Exploiting ECDSA
  • While this is known to people who know ECDSAElliptic Curve Digital Signature Algorithm, the people implementing this code were obviously not aware of it
  • The formulae are complicated enough that you don't see it with the naked eye unless you do the math
  • When you are not familiar with cryptographic engineering, a total break upon nonce reuse is not something you would expect
Conclusion
48
Takeaway
  • ASN.1 is a powerful way of expressing syntax in an abstact manner and it is quite prevalent in cryptographic software
  • Correct implementation of cryptographic algorithms is essential; in prescriptive documentation, the critical importance of such steps is often implied – this is a minefield for the uninitiated
Thank you!
Any questions?
Acronyms