~ubuntu-branches/ubuntu/utopic/dovecot/utopic-proposed

« back to all changes in this revision

Viewing changes to src/lib/hmac.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (4.1.35 sid)
  • Revision ID: package-import@ubuntu.com-20140108093549-i72o93pux8p0dlaf
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * HMAC (RFC-2104) implementation.
 
3
 *
 
4
 * Copyright (c) 2004 Andrey Panin <pazke@donpac.ru>
 
5
 * Copyright (c) 2011-2012 Florian Zeitz <florob@babelmonkeys.de>
 
6
 *
 
7
 * This software is released under the MIT license.
 
8
 */
 
9
 
 
10
#include "lib.h"
 
11
#include "hmac.h"
 
12
#include "safe-memset.h"
 
13
 
 
14
void hmac_init(struct hmac_context *_ctx, const unsigned char *key,
 
15
                size_t key_len, const struct hash_method *meth)
 
16
{
 
17
        struct hmac_context_priv *ctx = &_ctx->u.priv;
 
18
        int i;
 
19
        unsigned char k_ipad[64];
 
20
        unsigned char k_opad[64];
 
21
        unsigned char hashedkey[meth->digest_size];
 
22
 
 
23
        i_assert(meth->context_size <= HMAC_MAX_CONTEXT_SIZE);
 
24
 
 
25
        ctx->hash = meth;
 
26
 
 
27
        if (key_len > 64) {
 
28
                meth->init(ctx->ctx);
 
29
                meth->loop(ctx->ctx, key, key_len);
 
30
                meth->result(ctx->ctx, hashedkey);
 
31
                key = hashedkey;
 
32
                key_len = meth->digest_size;
 
33
        }
 
34
 
 
35
        memcpy(k_ipad, key, key_len);
 
36
        memset(k_ipad + key_len, 0, 64 - key_len);
 
37
        memcpy(k_opad, k_ipad, 64);
 
38
 
 
39
        for (i = 0; i < 64; i++) {
 
40
                k_ipad[i] ^= 0x36;
 
41
                k_opad[i] ^= 0x5c;
 
42
        }
 
43
 
 
44
        meth->init(ctx->ctx);
 
45
        meth->loop(ctx->ctx, k_ipad, 64);
 
46
        meth->init(ctx->ctxo);
 
47
        meth->loop(ctx->ctxo, k_opad, 64);
 
48
 
 
49
        safe_memset(k_ipad, 0, 64);
 
50
        safe_memset(k_opad, 0, 64);
 
51
}
 
52
 
 
53
void hmac_final(struct hmac_context *_ctx, unsigned char *digest)
 
54
{
 
55
        struct hmac_context_priv *ctx = &_ctx->u.priv;
 
56
 
 
57
        ctx->hash->result(ctx->ctx, digest);
 
58
 
 
59
        ctx->hash->loop(ctx->ctxo, digest, ctx->hash->digest_size);
 
60
        ctx->hash->result(ctx->ctxo, digest);
 
61
}