Select Git revision
-
Build system authored
Rev: packaging/debian/changelog:1.97 Rev: src/version.h:1.415
Build system authoredRev: packaging/debian/changelog:1.97 Rev: src/version.h:1.415
der-iterator.c 6.78 KiB
/* der-iterator.c
*
* Parses DER encoded objects.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2005 Niels Mller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#include <stdlib.h>
#if HAVE_LIBGMP
#include "bignum.h"
#endif
#include "asn1.h"
#include "macros.h"
/* Basic DER syntax: (reference: A Layman's Guide to a Subset of ASN.1, BER, and DER,
http://luca.ntop.org/Teaching/Appunti/asn1.html)
The DER header contains a tag and a length. First, the tag. cls is
the class number, c is one if the object is "constructed" and zero
if it is primitive. The tag is represented either using a single
byte,
7 6 5 4 3 2 1 0
_____________________
|_cls_|_c_|_______tag_| 0 <= tag <= 30
or multiple bytes
7 6 5 4 3 2 1 0
_____________________
|_cls_|_c_|_1_1_1_1_1_|
followed by the real tag number, in base 128, with all but the
final byte having the most significant bit set. The tag must be
represented with as few bytes as possible. High tag numbers are
currently *not* supported.
Next, the length, either a single byte with the most significant bit clear, or
7 6 5 4 3 2 1 0
_________________
|_1_|___________k_|
followed by k additional bytes that give the length, in network