libgcrypt: Import libgcrypt 1.11

We currently use an old version of libgcrypt which results in us having
fewer ciphers and missing on many other improvements.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Vladimir Serbinenko authored and Daniel Kiper committed 2025-07-11 23:12:50 +02:00
1 parent a0d4c94ef6
commit 3312af6e07
468 files changed
+210508 -33178

No files matched your search

+70 -101
View File
@@ -14,8 +14,8 @@
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
* License along with this program; if not, see <https://www.gnu.org/licenses/>.
* SPDX-License-Identifier: LGPL-2.1-or-later
*
* Based on md5.c in libgcrypt, but rewritten to compute md4 checksums
* using a public domain md4 implementation with the following comments:
@@ -56,28 +56,35 @@
#include "cipher.h"
#include "bithelp.h"
#include "bufhelp.h"
#include "hash-common.h"
typedef struct {
gcry_md_block_ctx_t bctx;
u32 A,B,C,D; /* chaining variables */
u32 nblocks;
byte buf[64];
int count;
} MD4_CONTEXT;
static unsigned int
transform ( void *c, const unsigned char *data, size_t nblks );
static void
md4_init( void *context )
md4_init (void *context, unsigned int flags)
{
MD4_CONTEXT *ctx = context;
(void)flags;
ctx->A = 0x67452301;
ctx->B = 0xefcdab89;
ctx->C = 0x98badcfe;
ctx->D = 0x10325476;
ctx->nblocks = 0;
ctx->count = 0;
ctx->bctx.nblocks = 0;
ctx->bctx.nblocks_high = 0;
ctx->bctx.count = 0;
ctx->bctx.blocksize_shift = _gcry_ctz(64);
ctx->bctx.bwrite = transform;
}
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
@@ -88,31 +95,19 @@ md4_init( void *context )
/****************
* transform 64 bytes
*/
static void
transform ( MD4_CONTEXT *ctx, const unsigned char *data )
static unsigned int
transform_blk ( void *c, const unsigned char *data )
{
MD4_CONTEXT *ctx = c;
u32 in[16];
register u32 A = ctx->A;
register u32 B = ctx->B;
register u32 C = ctx->C;
register u32 D = ctx->D;
int i;
#ifdef WORDS_BIGENDIAN
{
int i;
byte *p2;
const byte *p1;
for(i=0, p1=data, p2=(byte*)in; i < 16; i++, p2 += 4 )
{
p2[3] = *p1++;
p2[2] = *p1++;
p2[1] = *p1++;
p2[0] = *p1++;
}
}
#else
memcpy (in, data, 64);
#endif
for ( i = 0; i < 16; i++ )
in[i] = buf_get_le32(data + i * 4);
/* Round 1. */
#define function(a,b,c,d,k,s) a=rol(a+F(b,c,d)+in[k],s);
@@ -183,54 +178,27 @@ transform ( MD4_CONTEXT *ctx, const unsigned char *data )
ctx->B += B;
ctx->C += C;
ctx->D += D;
return /*burn_stack*/ 80+6*sizeof(void*);
}
/* The routine updates the message-digest context to
* account for the presence of each of the characters inBuf[0..inLen-1]
* in the message whose digest is being computed.
*/
static void
md4_write ( void *context, const void *inbuf_arg, size_t inlen)
static unsigned int
transform ( void *c, const unsigned char *data, size_t nblks )
{
const unsigned char *inbuf = inbuf_arg;
MD4_CONTEXT *hd = context;
unsigned int burn;
if( hd->count == 64 ) /* flush the buffer */
do
{
transform( hd, hd->buf );
_gcry_burn_stack (80+6*sizeof(void*));
hd->count = 0;
hd->nblocks++;
burn = transform_blk (c, data);
data += 64;
}
if( !inbuf )
return;
while (--nblks);
if( hd->count )
{
for( ; inlen && hd->count < 64; inlen-- )
hd->buf[hd->count++] = *inbuf++;
md4_write( hd, NULL, 0 );
if( !inlen )
return;
}
_gcry_burn_stack (80+6*sizeof(void*));
while( inlen >= 64 )
{
transform( hd, inbuf );
hd->count = 0;
hd->nblocks++;
inlen -= 64;
inbuf += 64;
}
for( ; inlen && hd->count < 64; inlen-- )
hd->buf[hd->count++] = *inbuf++;
return burn;
}
/* The routine final terminates the message-digest computation and
* ends with the desired message digest in mdContext->digest[0...15].
* The handle is prepared for a new MD4 cycle.
@@ -241,18 +209,22 @@ static void
md4_final( void *context )
{
MD4_CONTEXT *hd = context;
u32 t, msb, lsb;
u32 t, th, msb, lsb;
byte *p;
unsigned int burn;
md4_write(hd, NULL, 0); /* flush */;
t = hd->bctx.nblocks;
if (sizeof t == sizeof hd->bctx.nblocks)
th = hd->bctx.nblocks_high;
else
th = hd->bctx.nblocks >> 32;
t = hd->nblocks;
/* multiply by 64 to make a byte count */
lsb = t << 6;
msb = t >> 26;
msb = (th << 6) | (t >> 26);
/* add the count */
t = lsb;
if( (lsb += hd->count) < t )
if( (lsb += hd->bctx.count) < t )
msb++;
/* multiply by 8 to make a bit count */
t = lsb;
@@ -260,68 +232,65 @@ md4_final( void *context )
msb <<= 3;
msb |= t >> 29;
if( hd->count < 56 ) /* enough room */
if (hd->bctx.count < 56) /* enough room */
{
hd->buf[hd->count++] = 0x80; /* pad */
while( hd->count < 56 )
hd->buf[hd->count++] = 0; /* pad */
hd->bctx.buf[hd->bctx.count++] = 0x80; /* pad */
if (hd->bctx.count < 56)
memset (&hd->bctx.buf[hd->bctx.count], 0, 56 - hd->bctx.count);
/* append the 64 bit count */
buf_put_le32(hd->bctx.buf + 56, lsb);
buf_put_le32(hd->bctx.buf + 60, msb);
burn = transform (hd, hd->bctx.buf, 1);
}
else /* need one extra block */
{
hd->buf[hd->count++] = 0x80; /* pad character */
while( hd->count < 64 )
hd->buf[hd->count++] = 0;
md4_write(hd, NULL, 0); /* flush */;
memset(hd->buf, 0, 56 ); /* fill next block with zeroes */
}
/* append the 64 bit count */
hd->buf[56] = lsb ;
hd->buf[57] = lsb >> 8;
hd->buf[58] = lsb >> 16;
hd->buf[59] = lsb >> 24;
hd->buf[60] = msb ;
hd->buf[61] = msb >> 8;
hd->buf[62] = msb >> 16;
hd->buf[63] = msb >> 24;
transform( hd, hd->buf );
_gcry_burn_stack (80+6*sizeof(void*));
hd->bctx.buf[hd->bctx.count++] = 0x80; /* pad character */
/* fill pad and next block with zeroes */
memset (&hd->bctx.buf[hd->bctx.count], 0, 64 - hd->bctx.count + 56);
p = hd->buf;
#ifdef WORDS_BIGENDIAN
#define X(a) do { *p++ = hd->a ; *p++ = hd->a >> 8; \
*p++ = hd->a >> 16; *p++ = hd->a >> 24; } while(0)
#else /* little endian */
#define X(a) do { *(u32*)p = (*hd).a ; p += 4; } while(0)
#endif
/* append the 64 bit count */
buf_put_le32(hd->bctx.buf + 64 + 56, lsb);
buf_put_le32(hd->bctx.buf + 64 + 60, msb);
burn = transform (hd, hd->bctx.buf, 2);
}
p = hd->bctx.buf;
#define X(a) do { buf_put_le32(p, hd->a); p += 4; } while(0)
X(A);
X(B);
X(C);
X(D);
#undef X
hd->bctx.count = 0;
_gcry_burn_stack (burn);
}
static byte *
md4_read (void *context)
{
MD4_CONTEXT *hd = context;
return hd->buf;
return hd->bctx.buf;
}
static byte asn[18] = /* Object ID is 1.2.840.113549.2.4 */
static const byte asn[18] = /* Object ID is 1.2.840.113549.2.4 */
{ 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86,0x48,
0x86, 0xf7, 0x0d, 0x02, 0x04, 0x05, 0x00, 0x04, 0x10 };
static gcry_md_oid_spec_t oid_spec_md4[] =
static const gcry_md_oid_spec_t oid_spec_md4[] =
{
/* iso.member-body.us.rsadsi.digestAlgorithm.md4 */
{ "1.2.840.113549.2.4" },
{ NULL },
};
gcry_md_spec_t _gcry_digest_spec_md4 =
const gcry_md_spec_t _gcry_digest_spec_md4 =
{
GCRY_MD_MD4, {0, 0},
"MD4", asn, DIM (asn), oid_spec_md4,16,
md4_init, md4_write, md4_final, md4_read,
md4_init, _gcry_md_block_write, md4_final, md4_read, NULL,
NULL,
sizeof (MD4_CONTEXT)
};