~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/dsig.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2007-2009 Sourcefire, Inc.
 
2
 *  Copyright (C) 2007-2010 Sourcefire, Inc.
3
3
 *
4
4
 *  Authors: Tomasz Kojm
5
5
 *
32
32
#include "dsig.h"
33
33
#include "str.h"
34
34
#include "bignum.h"
 
35
#include "sha256.h"
35
36
 
36
37
#define CLI_NSTR "118640995551645342603070001658453189751527774412027743746599405743243142607464144767361060640655844749760788890022283424922762488917565551002467771109669598189410434699034532232228621591089508178591428456220796841621637175567590476666928698770143328137383952820383197532047771780196576957695822641224262693037"
37
38
 
38
39
#define CLI_ESTR "100001027"
39
40
 
40
 
static unsigned char cli_ndecode(unsigned char value)
 
41
static char cli_ndecode(unsigned char value)
41
42
{
42
43
        unsigned int i;
43
44
        char ncodec[] = {
60
61
    return -1;
61
62
}
62
63
 
63
 
unsigned char *cli_decodesig(const char *sig, unsigned int plen, mp_int e, mp_int n)
 
64
static unsigned char *cli_decodesig(const char *sig, unsigned int plen, mp_int e, mp_int n)
64
65
{
65
66
        int i, slen = strlen(sig), dec;
66
67
        unsigned char *plain;
145
146
    cli_dbgmsg("cli_versig: Digital signature is correct.\n");
146
147
    return CL_SUCCESS;
147
148
}
 
149
 
 
150
#define HASH_LEN    32
 
151
#define SALT_LEN    32
 
152
#define PAD_LEN     (2048 / 8)
 
153
#define BLK_LEN     (PAD_LEN - HASH_LEN - 1)
 
154
int cli_versig2(const unsigned char *sha256, const char *dsig_str, const char *n_str, const char *e_str)
 
155
{
 
156
        unsigned char *decoded, digest1[HASH_LEN], digest2[HASH_LEN], digest3[HASH_LEN], *salt;
 
157
        unsigned char mask[BLK_LEN], data[BLK_LEN], final[8 + 2 * HASH_LEN], c[4];
 
158
        unsigned int i, rounds;
 
159
        SHA256_CTX ctx;
 
160
        mp_int n, e;
 
161
 
 
162
    mp_init(&e);
 
163
    mp_read_radix(&e, e_str, 10);
 
164
    mp_init(&n);
 
165
    mp_read_radix(&n, n_str, 10);
 
166
 
 
167
    decoded = cli_decodesig(dsig_str, PAD_LEN, e, n);
 
168
    mp_clear(&n);
 
169
    mp_clear(&e);
 
170
    if(!decoded)
 
171
        return CL_EVERIFY;
 
172
 
 
173
    if(decoded[PAD_LEN - 1] != 0xbc) {
 
174
        free(decoded);
 
175
        return CL_EVERIFY;
 
176
    }
 
177
 
 
178
    memcpy(mask, decoded, BLK_LEN);
 
179
    memcpy(digest2, &decoded[BLK_LEN], HASH_LEN);
 
180
    free(decoded);
 
181
 
 
182
    c[0] = c[1] = 0;
 
183
    rounds = (BLK_LEN + HASH_LEN - 1) / HASH_LEN;
 
184
    for(i = 0; i < rounds; i++) {
 
185
        c[2] = (unsigned char) (i / 256);
 
186
        c[3] = (unsigned char) i;
 
187
        sha256_init(&ctx);
 
188
        sha256_update(&ctx, digest2, HASH_LEN);
 
189
        sha256_update(&ctx, c, 4);
 
190
        sha256_final(&ctx, digest3);
 
191
        if(i + 1 == rounds)
 
192
            memcpy(&data[i * 32], digest3, BLK_LEN - i * HASH_LEN);
 
193
        else
 
194
            memcpy(&data[i * 32], digest3, HASH_LEN);
 
195
    }
 
196
 
 
197
    for(i = 0; i < BLK_LEN; i++)
 
198
        data[i] ^= mask[i];
 
199
    data[0] &= (0xff >> 1);
 
200
 
 
201
    if(!(salt = memchr(data, 0x01, BLK_LEN)))
 
202
        return CL_EVERIFY;
 
203
    salt++;
 
204
 
 
205
    if(data + BLK_LEN - salt != SALT_LEN)
 
206
        return CL_EVERIFY;
 
207
 
 
208
    memset(final, 0, 8);
 
209
    memcpy(&final[8], sha256, HASH_LEN);
 
210
    memcpy(&final[8 + HASH_LEN], salt, SALT_LEN);
 
211
 
 
212
    sha256_init(&ctx);
 
213
    sha256_update(&ctx, final, sizeof(final));
 
214
    sha256_final(&ctx, digest1);
 
215
 
 
216
    return memcmp(digest1, digest2, HASH_LEN) ? CL_EVERIFY : CL_SUCCESS;
 
217
}