~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to grub-core/lib/libgcrypt/cipher/md4.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* md4.c - MD4 Message-Digest Algorithm
 
2
 * Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 
3
 *
 
4
 * This file is part of Libgcrypt.
 
5
 *
 
6
 * Libgcrypt is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU Lesser General Public License as
 
8
 * published by the Free Software Foundation; either version 2.1 of
 
9
 * the License, or (at your option) any later version.
 
10
 *
 
11
 * Libgcrypt is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
19
 *
 
20
 * Based on md5.c in libgcrypt, but rewritten to compute md4 checksums
 
21
 * using a public domain md4 implementation with the following comments:
 
22
 *
 
23
 * Modified by Wei Dai from Andrew M. Kuchling's md4.c
 
24
 * The original code and all modifications are in the public domain.
 
25
 *
 
26
 * This is the original introductory comment:
 
27
 *
 
28
 *  md4.c : MD4 hash algorithm.
 
29
 *
 
30
 * Part of the Python Cryptography Toolkit, version 1.1
 
31
 *
 
32
 * Distribute and use freely; there are no restrictions on further
 
33
 * dissemination and usage except those imposed by the laws of your
 
34
 * country of residence.
 
35
 *
 
36
 */
 
37
 
 
38
/* MD4 test suite:
 
39
 * MD4 ("") = 31d6cfe0d16ae931b73c59d7e0c089c0
 
40
 * MD4 ("a") = bde52cb31de33e46245e05fbdbd6fb24
 
41
 * MD4 ("abc") = a448017aaf21d8525fc10ae87aa6729d
 
42
 * MD4 ("message digest") = d9130a8164549fe818874806e1c7014b
 
43
 * MD4 ("abcdefghijklmnopqrstuvwxyz") = d79e1c308aa5bbcdeea8ed63df412da9
 
44
 * MD4 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =
 
45
 * 043f8582f241db351ce627e153e7f0e4
 
46
 * MD4 ("123456789012345678901234567890123456789012345678901234567890123456
 
47
 * 78901234567890") = e33b4ddc9c38f2199c3e7b164fcc0536
 
48
 */
 
49
 
 
50
#include <config.h>
 
51
#include <stdio.h>
 
52
#include <stdlib.h>
 
53
#include <string.h>
 
54
 
 
55
#include "g10lib.h"
 
56
#include "memory.h"
 
57
#include "cipher.h"
 
58
 
 
59
#include "bithelp.h"
 
60
 
 
61
 
 
62
typedef struct {
 
63
    u32 A,B,C,D;          /* chaining variables */
 
64
    u32  nblocks;
 
65
    byte buf[64];
 
66
    int  count;
 
67
} MD4_CONTEXT;
 
68
 
 
69
 
 
70
static void
 
71
md4_init( void *context )
 
72
{
 
73
  MD4_CONTEXT *ctx = context;
 
74
 
 
75
  ctx->A = 0x67452301;
 
76
  ctx->B = 0xefcdab89;
 
77
  ctx->C = 0x98badcfe;
 
78
  ctx->D = 0x10325476;
 
79
 
 
80
  ctx->nblocks = 0;
 
81
  ctx->count = 0;
 
82
}
 
83
 
 
84
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
 
85
#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
 
86
#define H(x, y, z) ((x) ^ (y) ^ (z))
 
87
 
 
88
 
 
89
/****************
 
90
 * transform 64 bytes
 
91
 */
 
92
static void
 
93
transform ( MD4_CONTEXT *ctx, const unsigned char *data )
 
94
{
 
95
  u32 in[16];
 
96
  register u32 A = ctx->A;
 
97
  register u32 B = ctx->B;
 
98
  register u32 C = ctx->C;
 
99
  register u32 D = ctx->D;
 
100
 
 
101
#ifdef WORDS_BIGENDIAN
 
102
  {
 
103
    int i;
 
104
    byte *p2, *p1;
 
105
    for(i=0, p1=data, p2=(byte*)in; i < 16; i++, p2 += 4 )
 
106
      {
 
107
        p2[3] = *p1++;
 
108
        p2[2] = *p1++;
 
109
        p2[1] = *p1++;
 
110
        p2[0] = *p1++;
 
111
      }
 
112
  }
 
113
#else
 
114
  memcpy (in, data, 64);
 
115
#endif
 
116
 
 
117
  /* Round 1.  */
 
118
#define function(a,b,c,d,k,s) a=rol(a+F(b,c,d)+in[k],s);
 
119
  function(A,B,C,D, 0, 3);
 
120
  function(D,A,B,C, 1, 7);
 
121
  function(C,D,A,B, 2,11);
 
122
  function(B,C,D,A, 3,19);
 
123
  function(A,B,C,D, 4, 3);
 
124
  function(D,A,B,C, 5, 7);
 
125
  function(C,D,A,B, 6,11);
 
126
  function(B,C,D,A, 7,19);
 
127
  function(A,B,C,D, 8, 3);
 
128
  function(D,A,B,C, 9, 7);
 
129
  function(C,D,A,B,10,11);
 
130
  function(B,C,D,A,11,19);
 
131
  function(A,B,C,D,12, 3);
 
132
  function(D,A,B,C,13, 7);
 
133
  function(C,D,A,B,14,11);
 
134
  function(B,C,D,A,15,19);
 
135
 
 
136
#undef function
 
137
 
 
138
  /* Round 2.  */
 
139
#define function(a,b,c,d,k,s) a=rol(a+G(b,c,d)+in[k]+0x5a827999,s);
 
140
 
 
141
  function(A,B,C,D, 0, 3);
 
142
  function(D,A,B,C, 4, 5);
 
143
  function(C,D,A,B, 8, 9);
 
144
  function(B,C,D,A,12,13);
 
145
  function(A,B,C,D, 1, 3);
 
146
  function(D,A,B,C, 5, 5);
 
147
  function(C,D,A,B, 9, 9);
 
148
  function(B,C,D,A,13,13);
 
149
  function(A,B,C,D, 2, 3);
 
150
  function(D,A,B,C, 6, 5);
 
151
  function(C,D,A,B,10, 9);
 
152
  function(B,C,D,A,14,13);
 
153
  function(A,B,C,D, 3, 3);
 
154
  function(D,A,B,C, 7, 5);
 
155
  function(C,D,A,B,11, 9);
 
156
  function(B,C,D,A,15,13);
 
157
 
 
158
#undef function
 
159
 
 
160
  /* Round 3.  */
 
161
#define function(a,b,c,d,k,s) a=rol(a+H(b,c,d)+in[k]+0x6ed9eba1,s);
 
162
 
 
163
  function(A,B,C,D, 0, 3);
 
164
  function(D,A,B,C, 8, 9);
 
165
  function(C,D,A,B, 4,11);
 
166
  function(B,C,D,A,12,15);
 
167
  function(A,B,C,D, 2, 3);
 
168
  function(D,A,B,C,10, 9);
 
169
  function(C,D,A,B, 6,11);
 
170
  function(B,C,D,A,14,15);
 
171
  function(A,B,C,D, 1, 3);
 
172
  function(D,A,B,C, 9, 9);
 
173
  function(C,D,A,B, 5,11);
 
174
  function(B,C,D,A,13,15);
 
175
  function(A,B,C,D, 3, 3);
 
176
  function(D,A,B,C,11, 9);
 
177
  function(C,D,A,B, 7,11);
 
178
  function(B,C,D,A,15,15);
 
179
 
 
180
 
 
181
  /* Put checksum in context given as argument.  */
 
182
  ctx->A += A;
 
183
  ctx->B += B;
 
184
  ctx->C += C;
 
185
  ctx->D += D;
 
186
}
 
187
 
 
188
 
 
189
 
 
190
/* The routine updates the message-digest context to
 
191
 * account for the presence of each of the characters inBuf[0..inLen-1]
 
192
 * in the message whose digest is being computed.
 
193
 */
 
194
static void
 
195
md4_write ( void *context, const void *inbuf_arg, size_t inlen)
 
196
{
 
197
  const unsigned char *inbuf = inbuf_arg;
 
198
  MD4_CONTEXT *hd = context;
 
199
 
 
200
  if( hd->count == 64 ) /* flush the buffer */
 
201
    { 
 
202
      transform( hd, hd->buf );
 
203
      _gcry_burn_stack (80+6*sizeof(void*));
 
204
      hd->count = 0;
 
205
      hd->nblocks++;
 
206
    }
 
207
  if( !inbuf )
 
208
    return;
 
209
 
 
210
  if( hd->count )
 
211
    {
 
212
      for( ; inlen && hd->count < 64; inlen-- )
 
213
        hd->buf[hd->count++] = *inbuf++;
 
214
      md4_write( hd, NULL, 0 );
 
215
      if( !inlen )
 
216
        return;
 
217
    }
 
218
  _gcry_burn_stack (80+6*sizeof(void*));
 
219
 
 
220
  while( inlen >= 64 )
 
221
    {
 
222
      transform( hd, inbuf );
 
223
      hd->count = 0;
 
224
      hd->nblocks++;
 
225
      inlen -= 64;
 
226
      inbuf += 64;
 
227
    }
 
228
  for( ; inlen && hd->count < 64; inlen-- )
 
229
    hd->buf[hd->count++] = *inbuf++;
 
230
}
 
231
 
 
232
 
 
233
 
 
234
/* The routine final terminates the message-digest computation and
 
235
 * ends with the desired message digest in mdContext->digest[0...15].
 
236
 * The handle is prepared for a new MD4 cycle.
 
237
 * Returns 16 bytes representing the digest.
 
238
 */
 
239
 
 
240
static void
 
241
md4_final( void *context )
 
242
{
 
243
  MD4_CONTEXT *hd = context;
 
244
  u32 t, msb, lsb;
 
245
  byte *p;
 
246
 
 
247
  md4_write(hd, NULL, 0); /* flush */;
 
248
 
 
249
  t = hd->nblocks;
 
250
  /* multiply by 64 to make a byte count */
 
251
  lsb = t << 6;
 
252
  msb = t >> 26;
 
253
  /* add the count */
 
254
  t = lsb;
 
255
  if( (lsb += hd->count) < t )
 
256
    msb++;
 
257
  /* multiply by 8 to make a bit count */
 
258
  t = lsb;
 
259
  lsb <<= 3;
 
260
  msb <<= 3;
 
261
  msb |= t >> 29;
 
262
  
 
263
  if( hd->count < 56 )  /* enough room */
 
264
    {
 
265
      hd->buf[hd->count++] = 0x80; /* pad */
 
266
      while( hd->count < 56 )
 
267
        hd->buf[hd->count++] = 0;  /* pad */
 
268
    }
 
269
  else /* need one extra block */ 
 
270
    { 
 
271
      hd->buf[hd->count++] = 0x80; /* pad character */
 
272
      while( hd->count < 64 )
 
273
        hd->buf[hd->count++] = 0;
 
274
      md4_write(hd, NULL, 0);  /* flush */;
 
275
      memset(hd->buf, 0, 56 ); /* fill next block with zeroes */
 
276
    }
 
277
  /* append the 64 bit count */
 
278
  hd->buf[56] = lsb        ;
 
279
  hd->buf[57] = lsb >>  8;
 
280
  hd->buf[58] = lsb >> 16;
 
281
  hd->buf[59] = lsb >> 24;
 
282
  hd->buf[60] = msb        ;
 
283
  hd->buf[61] = msb >>  8;
 
284
  hd->buf[62] = msb >> 16;
 
285
  hd->buf[63] = msb >> 24;
 
286
  transform( hd, hd->buf );
 
287
  _gcry_burn_stack (80+6*sizeof(void*));
 
288
 
 
289
  p = hd->buf;
 
290
#ifdef WORDS_BIGENDIAN
 
291
#define X(a) do { *p++ = hd->a      ; *p++ = hd->a >> 8;      \
 
292
                  *p++ = hd->a >> 16; *p++ = hd->a >> 24; } while(0)
 
293
#else /* little endian */
 
294
#define X(a) do { *(u32*)p = (*hd).a ; p += 4; } while(0)
 
295
#endif
 
296
  X(A);
 
297
  X(B);
 
298
  X(C);
 
299
  X(D);
 
300
#undef X
 
301
 
 
302
}
 
303
 
 
304
static byte *
 
305
md4_read (void *context)
 
306
{
 
307
  MD4_CONTEXT *hd = context;
 
308
  return hd->buf;
 
309
}
 
310
 
 
311
static byte asn[18] = /* Object ID is 1.2.840.113549.2.4 */
 
312
  { 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86,0x48,
 
313
    0x86, 0xf7, 0x0d, 0x02, 0x04, 0x05, 0x00, 0x04, 0x10 };
 
314
 
 
315
static gcry_md_oid_spec_t oid_spec_md4[] =
 
316
  {
 
317
    /* iso.member-body.us.rsadsi.digestAlgorithm.md4 */
 
318
    { "1.2.840.113549.2.4" },
 
319
    { NULL },
 
320
  };
 
321
 
 
322
gcry_md_spec_t _gcry_digest_spec_md4 =
 
323
  {
 
324
    "MD4", asn, DIM (asn), oid_spec_md4,16,
 
325
    md4_init, md4_write, md4_final, md4_read,
 
326
    sizeof (MD4_CONTEXT)
 
327
  };
 
328