<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en" style='--code-editor-font: var(--default-mono-font, "GitLab Mono"), JetBrains Mono, Menlo, DejaVu Sans Mono, Liberation Mono, Consolas, Ubuntu Mono, Courier New, andale mono, lucida console, monospace;'>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>
GitLab
</title>

<style data-premailer="ignore" type="text/css">
a { color: #1068bf; }
</style>

<style>img {
max-width: 100%; height: auto;
}
body {
font-size: .875rem;
}
body {
-webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px;
}
body {
font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"; font-size: inherit;
}
</style>
</head>
<body style='font-size: inherit; -webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px; font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";'>
<div class="content">

<p class="details" style="font-style: italic; color: #626168;">
<a href="https://gitlab.com/hanno">Hanno Böck</a> created an issue: <a href="https://gitlab.com/gnutls/gnutls/-/issues/1747">#1747</a>
</p>
<div class="md" style="position: relative; z-index: 1; color: #3a383f; word-wrap: break-word;">
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">ECDSA private key values should be stored in a bytestring of fixed-length with the size of the modulus (see RFC 5915 [1]). This also mitigates possible sidechannels that may leak information about leading zeros when loading a private key (see also [2]).</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">It appears gnutls encodes the private d value with an additional zero if the upmost bit of the d value is set (~1/2 of keys). It encodes d with a byte too small if the top 9 bits are zero. (happens in 1/512 of keys).</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">To test, generate a large number of ecdsa keys:</p>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre class="code highlight js-syntax-highlight language-plaintext" v-pre="true" style='display: block; font-size: 14px; color: #3a383f; line-height: 1.6em; overflow-x: auto; border-radius: .25rem; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: #fbfafd; margin: 0 0 1rem; padding: 12px; border: 1px solid #dcdcde;'><code style='font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; background-color: inherit; border-radius: .25rem; white-space: pre; margin-top: 0; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; overflow-wrap: normal; padding: unset;'><span id="LC1" class="line" lang="plaintext" style="margin-top: 0;">for x in $(seq 1 1000); do certtool --generate-privkey --outfile $x.key --key-type ecdsa --outder; done</span></code></pre>
<copy-code></copy-code><insert-code-snippet></insert-code-snippet>
</div>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Given the fixed-size encoding, all private keys with the same curve should have the same size, but they differ. Some are 121 bytes (correctly encoded), some 122 bytes, some (few) 120 bytes.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Here's a python script that checks if ECDSA's d has the correct encoding size:
<a href="https://github.com/hannob/tlshelpers/blob/main/checkkeyenc" rel="nofollow noreferrer noopener" target="_blank" style="margin-top: 0;">https://github.com/hannob/tlshelpers/blob/main/checkkeyenc</a></p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Given this can lead to a timing sidechannel leaking (very limited) information about the private key, one may see this as a security issue. However, the risk is very low and probably not practically relevant, as the information that can be leaked is extremely limited.</p>
<p dir="auto" style="color: #3a383f; margin: 0;" align="initial">[1] <a href="https://www.rfc-editor.org/rfc/rfc5915.html#section-3" rel="nofollow noreferrer noopener" target="_blank" style="margin-top: 0;">https://www.rfc-editor.org/rfc/rfc5915.html#section-3</a>
[2] <a href="https://seclists.org/oss-sec/2025/q4/38" rel="nofollow noreferrer noopener" target="_blank">https://seclists.org/oss-sec/2025/q4/38</a></p>
</div>

</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #626168;">

<br>
Reply to this email directly or <a href="https://gitlab.com/gnutls/gnutls/-/issues/1747">view it on GitLab</a>.
<br>
You're receiving this email because of your account on <a target="_blank" rel="noopener noreferrer" href="https://gitlab.com">gitlab.com</a>. <a href="https://gitlab.com/-/sent_notifications/1-944bbtjhckghpio0wafokh1ar/unsubscribe" target="_blank" rel="noopener noreferrer">Unsubscribe</a> from this thread · <a href="https://gitlab.com/-/profile/notifications" target="_blank" rel="noopener noreferrer" class="mng-notif-link">Manage all notifications</a> · <a href="https://gitlab.com/help" target="_blank" rel="noopener noreferrer" class="help-link">Help</a>
<span style="color: transparent; font-size: 0; display: none; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0;">
Notification message regarding https://gitlab.com/gnutls/gnutls/-/issues/1747 at 1760552289
</span>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Issue","url":"https://gitlab.com/gnutls/gnutls/-/issues/1747"}}</script>


</p>
</div>
</body>
</html>