Annotation of embedaddon/strongswan/src/libstrongswan/plugins/pgp/pgp_encoder.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2009 Martin Willi
        !             3:  * HSR Hochschule fuer Technik Rapperswil
        !             4:  *
        !             5:  * This program is free software; you can redistribute it and/or modify it
        !             6:  * under the terms of the GNU General Public License as published by the
        !             7:  * Free Software Foundation; either version 2 of the License, or (at your
        !             8:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
        !             9:  *
        !            10:  * This program is distributed in the hope that it will be useful, but
        !            11:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
        !            12:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
        !            13:  * for more details.
        !            14:  */
        !            15: 
        !            16: #include "pgp_encoder.h"
        !            17: 
        !            18: #include <library.h>
        !            19: #include <utils/debug.h>
        !            20: 
        !            21: /**
        !            22:  * Build a PGPv3 fingerprint
        !            23:  */
        !            24: static bool build_v3_fingerprint(chunk_t *encoding, va_list args)
        !            25: {
        !            26:        hasher_t *hasher;
        !            27:        chunk_t n, e;
        !            28: 
        !            29:        if (cred_encoding_args(args, CRED_PART_RSA_MODULUS, &n,
        !            30:                                                   CRED_PART_RSA_PUB_EXP, &e, CRED_PART_END))
        !            31:        {
        !            32:                hasher = lib->crypto->create_hasher(lib->crypto, HASH_MD5);
        !            33:                if (!hasher)
        !            34:                {
        !            35:                        DBG1(DBG_LIB, "MD5 hash algorithm not supported, PGP"
        !            36:                                 " fingerprinting failed");
        !            37:                        return FALSE;
        !            38:                }
        !            39:                /* remove leading zero bytes before hashing modulus and exponent */
        !            40:                while (n.len > 0 && n.ptr[0] == 0x00)
        !            41:                {
        !            42:                        n = chunk_skip(n, 1);
        !            43:                }
        !            44:                while (e.len > 0 && e.ptr[0] == 0x00)
        !            45:                {
        !            46:                        e = chunk_skip(e, 1);
        !            47:                }
        !            48:                if (!hasher->allocate_hash(hasher, n, NULL) ||
        !            49:                        !hasher->allocate_hash(hasher, e, encoding))
        !            50:                {
        !            51:                        hasher->destroy(hasher);
        !            52:                        return FALSE;
        !            53:                }
        !            54:                hasher->destroy(hasher);
        !            55:                return TRUE;
        !            56:        }
        !            57:        return FALSE;
        !            58: }
        !            59: 
        !            60: /**
        !            61:  * See header.
        !            62:  */
        !            63: bool pgp_encoder_encode(cred_encoding_type_t type, chunk_t *encoding,
        !            64:                                                va_list args)
        !            65: {
        !            66:        switch (type)
        !            67:        {
        !            68:                case KEYID_PGPV3:
        !            69:                        return build_v3_fingerprint(encoding, args);
        !            70:                default:
        !            71:                        return FALSE;
        !            72:        }
        !            73: }
        !            74: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>