<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="font-family: 'Segoe UI',Frutiger,'Frutiger Linotype','Dejavu Sans','Helvetica Neue',Arial,sans-serif; font-size: 14px;">
<div class="hiri-body-wrapper" contenteditable="true">
<div>Hi Jussi,<br>
<br>
No problem and thanks for coming back on my email.<br>
<br>
You are right - "all KCV algorithms I managed to find encrypt zero input block with the actual key as key" - except cases where the key is a weak key. While this might sound ridiculous there are many cases like this - in production as well as in test environments.
E.g. Thales HSM default-load key-set works with some weak keys and while doing symmetric crypto we need to support those as well (in testing / dev environments Thales HSM is almost always loaded with a default key set so crypto can be reproduced and validated).<br>
<br>
Hope it makes better sense now.<br>
<br>
Cheers,<br>
Jan<br>
</div>
</div>
<div class="hiri-signature-wrapper" contenteditable="true">
<div style="font-family: "Segoe UI", Arial, sans-serif; background-color: rgb(255, 255, 255);">
On 2020-01-06 00:36:19+10:00 Jussi Kivilinna wrote:</div>
</div>
<div class="hiri-extra-edited" contenteditable="true">
<blockquote style="padding-left:10px; border-left:1px solid #ccc; margin:0">
<div>
<pre class="hiri-plaintext-quote">Hello,
Apparently my first reply went only to the mailing list.
There I wrote: "I tried to find KCV specification where zero key is used to encrypt actual key as input block for KCV value, but all KCV algorithms I managed to find encrypt zero input block with the actual key as key. Can you check your documentation for KCV if zero key is really used and give pointer/link to that spec for us?"
-Jussi
On 4.1.2020 12.33, Jan Bilek wrote:
&gt; Ping?
&gt; &nbsp;
&gt;
&gt; On 2019-12-21 11:40:06+10:00 Jan Bilek wrote:
&gt;
&gt; Hi,
&gt;
&gt; We have a problem here where I need to encrypt a block of data with zeros.
&gt;
&gt; &lt;&gt;
&gt; &nbsp;&nbsp;gcry_check_version (NULL);
&gt; &nbsp; unsigned char key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
&gt; &nbsp; unsigned char out[8];
&gt; &nbsp; unsigned char data[8];
&gt; &nbsp; gcry_error_t err = 0;
&gt; &nbsp; gcry_cipher_hd_t hd = nullptr;
&gt; &nbsp; err = gcry_cipher_open(&amp;hd, GCRY_CIPHER_DES, GCRY_CIPHER_MODE_ECB, 0);
&gt; &nbsp; //auto blklen = gcry_cipher_get_algo_blklen(GCRY_CIPHER_DES);
&gt; &nbsp; //auto algolen = gcry_cipher_get_algo_keylen (GCRY_CIPHER_DES);
&gt; &nbsp; err = gcry_cipher_setkey (hd, key, sizeof(key));
&gt; &nbsp; std::cerr &lt;&lt; "gpg_err_code: " &lt;&lt; gpg_err_code(err) &lt;&lt; std::endl;
&gt; &nbsp; std::cerr &lt;&lt; "gpg_strerror: " &lt;&lt; gpg_strerror(err) &lt;&lt; std::endl;
&gt; &nbsp; gcry_cipher_encrypt(hd, out, sizeof(key), data, 8);
&gt; &nbsp; if (err) {
&gt; &nbsp; &nbsp; std::cerr &lt;&lt; "Failed to perform cryptography" &lt;&lt; std::endl;
&gt; &nbsp; &nbsp; std::cerr &lt;&lt; " &nbsp;cipher: &nbsp; &nbsp; " &lt;&lt; static_cast<int>(GCRY_CIPHER_DES) &lt;&lt; std::endl;
&gt; &nbsp; &nbsp; std::cerr &lt;&lt; " &nbsp;mode: &nbsp; &nbsp; &nbsp; " &lt;&lt; static_cast<int>(GCRY_CIPHER_MODE_ECB) &lt;&lt; std::endl;
&gt; &nbsp; &nbsp; //std::cerr &lt;&lt; " &nbsp;keyBlock: &nbsp; " &lt;&lt; BinToHex<std::string>(key) &lt;&lt; std::endl;
&gt; &nbsp; &nbsp; //std::cerr &lt;&lt; " &nbsp;out: &nbsp; &nbsp; &nbsp; &nbsp;" &lt;&lt; BinToHex<std::string>(out) &lt;&lt; std::endl;
&gt; &nbsp; &nbsp; //std::cerr &lt;&lt; " &nbsp;data: &nbsp; &nbsp; &nbsp; " &lt;&lt; BinToHex<std::string>(encryptedData) &lt;&lt; std::endl;
&gt; &nbsp; }
&gt;
&gt;
&gt; This blows on:
&gt;
&gt; gpg_err_code: 43
&gt; gpg_strerror: Weak encryption key
&gt; cipher_encrypt: key not set
&gt;
&gt; Tracked back t&nbsp;in a source&nbsp;to libcrypt / cipher / des.c
&gt;
&gt; r. 1384&nbsp;do_des_setkey
&gt; r. 1021 is_weak_key
&gt;
&gt; &nbsp;&nbsp;if (is_weak_key (key)) {
&gt; &nbsp; &nbsp; _gcry_burn_stack (64);
&gt; &nbsp; &nbsp; return GPG_ERR_WEAK_KEY;
&gt; &nbsp; }
&gt;
&gt; cipher.c
&gt; r.797&nbsp;
&gt;
&gt; &nbsp;rc = c-&gt;spec-&gt;setkey (&amp;c-&gt;context.c, key, keylen, c);
&gt; &nbsp; if (!rc) {
&gt;
&gt; &nbsp;&nbsp;} else
&gt; &nbsp; &nbsp; c-&gt;marks.key = 0;
&gt; &nbsp;
&gt; ... then disallows weak key setting completely, resulting in a failure.
&gt;
&gt; This has quite an impact on multiple (still) in-use KCV operations (e.g. KCV_METHOD_VISA) where key needs to be encrypted with a zero key to get its KCV.
&gt;
&gt; May I propose a patch? (See in attachment).
&gt;
&gt; Thanks &amp; Cheers,
&gt; Jan
&gt;
&gt;
&gt; _______________________________________________
&gt; Gcrypt-devel mailing list
&gt; Gcrypt-devel@gnupg.org
&gt; http://lists.gnupg.org/mailman/listinfo/gcrypt-devel
&gt;
</std::string></std::string></std::string></int></int></pre>
</div>
</blockquote>
</div>
</body>
</html>