linux/crypto/md5.c
<<
>>
Prefs
   1/* 
   2 * Cryptographic API.
   3 *
   4 * MD5 Message Digest Algorithm (RFC1321).
   5 *
   6 * Derived from cryptoapi implementation, originally based on the
   7 * public domain implementation written by Colin Plumb in 1993.
   8 *
   9 * Copyright (c) Cryptoapi developers.
  10 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  11 * 
  12 * This program is free software; you can redistribute it and/or modify it
  13 * under the terms of the GNU General Public License as published by the Free
  14 * Software Foundation; either version 2 of the License, or (at your option) 
  15 * any later version.
  16 *
  17 */
  18#include <crypto/internal/hash.h>
  19#include <crypto/md5.h>
  20#include <linux/init.h>
  21#include <linux/module.h>
  22#include <linux/string.h>
  23#include <linux/types.h>
  24#include <linux/cryptohash.h>
  25#include <asm/byteorder.h>
  26
  27/* XXX: this stuff can be optimized */
  28static inline void le32_to_cpu_array(u32 *buf, unsigned int words)
  29{
  30        while (words--) {
  31                __le32_to_cpus(buf);
  32                buf++;
  33        }
  34}
  35
  36static inline void cpu_to_le32_array(u32 *buf, unsigned int words)
  37{
  38        while (words--) {
  39                __cpu_to_le32s(buf);
  40                buf++;
  41        }
  42}
  43
  44static inline void md5_transform_helper(struct md5_state *ctx)
  45{
  46        le32_to_cpu_array(ctx->block, sizeof(ctx->block) / sizeof(u32));
  47        md5_transform(ctx->hash, ctx->block);
  48}
  49
  50static int md5_init(struct shash_desc *desc)
  51{
  52        struct md5_state *mctx = shash_desc_ctx(desc);
  53
  54        mctx->hash[0] = 0x67452301;
  55        mctx->hash[1] = 0xefcdab89;
  56        mctx->hash[2] = 0x98badcfe;
  57        mctx->hash[3] = 0x10325476;
  58        mctx->byte_count = 0;
  59
  60        return 0;
  61}
  62
  63static int md5_update(struct shash_desc *desc, const u8 *data, unsigned int len)
  64{
  65        struct md5_state *mctx = shash_desc_ctx(desc);
  66        const u32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
  67
  68        mctx->byte_count += len;
  69
  70        if (avail > len) {
  71                memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
  72                       data, len);
  73                return 0;
  74        }
  75
  76        memcpy((char *)mctx->block + (sizeof(mctx->block) - avail),
  77               data, avail);
  78
  79d5_transform_helper(struo73">  73                return 0;
<;a    18to/md5.c8L69" id="L69" class="li8e" na80="L78">  78
mctx                &8t;   78
mctx               ) -8  61}
data<8a>, len{
u32 avail = sizeof(av8ass="lin8" name="L73">  73  8     84sref">len);

u32 avail = sizeof(  5.c#L77" id="L77" class="line"+code=u32" class="sref">u32 avail = sizeof(85sref">len);

  79d5_transform_helper(struo73">  73                return 0;
<;a    18to/md5.c8L75" id="L75" class="li8e" na86sref">len);

u32 avail = sizeof(avail),

u32 avail = sizeof(  67< 0;
len;
  78
u32 avail = sizeof(  5.c#L77" id="L77" class="lineL72">  72                       len;
availdata<9a>,   73  9     94"sref">len;
95="L62">  62
L79" class="line" nfL6">name="L63">  63static int md5_update(struct shash_desc *        e=data" class="sref">data9to/md5.c9L75" id="L75" class="li9e" na96"sref">len)
avail{
  65        struct md5_state *mctx = shash_d9in imple9mentation written by Co9ass="9e="L67">  67<>);
offse>        de=md5_state" class="sf">mctx->block) - (shash_d9"line" naame="L8">   8  78  76        memcpy((char *)offse>        de=mhref="include/crypto/inter0"comment">> * Copyright (c) Cryptoae" noae="L69">  69padme="/a>) - (shash_d1002 James 0Morris <jmorris@inter01" noa1"sref">len;
  11availlen
) - (av10 General 0Public License as publis04" noa4sref">len);

mctx p/a>) - (spadme="/a>) - (
len);

  79d5_transform_helper(struo73">  73                return 0;
<;a    1105 * any06" noa6sref">len);

  76        memcpy((char *)  16avail),

) - (  17  67< 0;
crypto/i09" noa="sref">len;
 * Copyright (c) Cryptooapi 110="L78">  78
mctx p/a>) - (spadme="/a>) - (  78
memcpy((char *)mctx->block) - (  11  78
memcpy((char *)mctx->block) - (mctx->  78
  46        u32 avail = sizeof(mctx->block + (sizeof(mctx->len);
ctxd int  *ctx->block  47    ypto/md5.c#L57" id="L57" class="line" name="L57">  57        sf">u32 avail = sizeof( * anyy lat11e="L75">  75
inline void   57        mctx->bl">  57        ctx->block  16sf">u32 a">  57        mctx->bl">  57        block  17  67
mctx x->  65        struct blockcrypto/iinter11="sref">len;
cr12e="L59">  59
li12       return 0;
  11  61}
linu12e="L62">  62
  63static int md5_update(struct         e=data" class="sref">data1nclude/li1nux/types.h" class="fref1">lin12="sref">len)
lin1ux/cr12="L64">  64{
  65    s="sref">ctx->md5_state *mctx = shash_d1xtensa/by1teorder.h" class="falt">1asm/b1teorder.h>
ss="sref">ctx->  65    /a>(struct shash_d1xne" name=">/* XXX: this stuff can1 be o128="L59">  59
wor9">  49
  63static int md5_update(struct data12_to_cpus1(len)
bufa>{
  65    s="sref">ctx->md5_state *mctx = shash_d1#L33" id=1"L33" class="line" name=1"L33"134"sref">len;
ctx->  65    /a>(struct shash_d1pto/md5.c1#L35" id="L35" class="li1ne" n136="L59">  59
avail);
wor9">  49"L63">  63static int ) - () - (av1_to_le32s1(bufmctx =4" idmctx href="+code=sha4" idmctxsref">buf=x67452301;
av1_include/1    buf.sref">mctx 5.c#L50" id="L50" c="line" hhhhhhhhhhh=x67452301;
av1__to_cpus1"L41" class="line" name=1"L41"142ref">buf.sref">mctx 5.c#L63" id="L63" claline" namehhhhhhhhh=x67452301;
av1_        1L42" id="L42" class="lin1e" na143ref">buf.sref">mctx fL6">L79" class="linfL6">namehhhhhhhhhh=x67452301;
L79" class="line" nfL6">namese=avail" class="sref">av1_ General PPublic License as publishL33"144ref">buf.sref">mctx expor#L50" id="L50" cexpor#namehhhhhhhhh=x67452301;
av1_o/md5.c#1 *buf.sref">mctx 5mpor#L50" id="L50" c5mpor#namehhhhhhhhh=x67452301;
av1_to/md5.c1L45" id="L45" class="lin1e" na1e="L45">  45mctx =sh_mctx href="+code=shash_mctx"L45">  45<=x674523mctx" ca>{
blo1a>) / siz1eof(u32.sref">mctx e" namctx href="+code=she" namctxref">u32{
blo1ane" name=;u32.sref">mctx 6 = sizeof(av1_hile (words--) {
mctx cra_ss="(struct   45<=x6745236">  26
<="L22"">"ref" name="e=block" class="sref">blo1pto/md5.c1#L49" id="L49" class="li1ne" n15"sref">buf);
mctx cra_flag39" class="line"cra_flag3ref">u32mctx CRYPTO_ALG_TYPE_SHASH9" class="line"CRYPTO_ALG_TYPE_SHASHnamese=avail" class="sref">av1sh_desc *len) {
mctx cra_ hrefmctx href="+code=shcra_ hrefmctxref">l=x67452301;
av1s_to_cpus1L51" id="L51" class="lin1e" na15ref">avail),
mctx cra_="L21" href="+code=shcra_="L21"sref">buf=x67452301;
av1s        1a>(buf++;
ha1sh        }
ha1sh  35
data1href="+co1de=hash" class="sref">ha1shwords)
ha1sh  59
mctx cra hr_register_s">  57          ass="lass= 63static ial"/a>) - (shash_d1href="+co1de=byte_count" class="sr1ef">b15sref"  return 0;
  160wor9">  49"line" name="L44">  _sexc#L50" id="L50" c_sexc#ne"  href="crypto/md5.c#="LdfL6iL50" id="L50" class="LdfL6iass=""linta" class="sref">data1to/md5.c#1L61" id="L61" class="lin1e" na16code=f">len)
  78
  57          ass="lass= 63static ial"/a>) - (shash_d1, unsigne1d int         }
        }
mctx x.c#="Ld5.c#L50" id="L50" class="Ld5.c#ass=_ctx" class="sref">shash_d1,ref="+co1count" class="sref">byte1_coun1 &href="crypto/md5"L21"dexc#L50" id="L50" c5"L21"dexc#ass="sref">mctx x.c#="LdfL6iL50" id="L50" class="LdfL6iass=_ctx" class="sref">shash_d1,ref="+co1#L67" id="L67" class="li1ne" n16ref">avail);
  26
<="L22"">"GPL" name="_ctx" class="sref">shash_d1pto/md5.c1#L69" id="L69" class="li1ne" n1me="L601;
  26
<="L22"">"rypto/md5.c#L4" id="L4" clas" name="_ctx" class="sref">shash_d1p"L60" cl1gt; 
    
Theame="L6"> LXR2" class=lass="cox" class=http://sourceforge.net/projects/lxr">LXR2a hru.c#ye=dash5.c#Lexperi"L7" ls="line" assx" class=mailto:lxr@le="L.no">lxr@le="L.noe=da. >
lxr.le="L.no kindly hosted assx" class=http://www.redpill-le=pro.no">Redpill Le=pro ASe=dashprovi/md5of Le=uxh>); ult22">