diff options
author | Rao Shoaib <Rao.Shoaib@Sun.COM> | 2009-11-11 08:45:41 -0800 |
---|---|---|
committer | Rao Shoaib <Rao.Shoaib@Sun.COM> | 2009-11-11 08:45:41 -0800 |
commit | 9525b14bcdeb5b5f6f95ab27c2f48f18bd2ec829 (patch) | |
tree | df51891a276edf456c1481f49653a76cdfedee53 /usr/src | |
parent | 0324f02a004039d6377111191fdd7134452d7817 (diff) | |
download | illumos-gate-9525b14bcdeb5b5f6f95ab27c2f48f18bd2ec829.tar.gz |
6289479 libresolv2 clean up and alignment with libbind.6.0
Diffstat (limited to 'usr/src')
416 files changed, 7549 insertions, 42542 deletions
diff --git a/usr/src/head/arpa/inet.h b/usr/src/head/arpa/inet.h index f2ebe1075b..a72d573899 100644 --- a/usr/src/head/arpa/inet.h +++ b/usr/src/head/arpa/inet.h @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -34,8 +34,6 @@ #ifndef _ARPA_INET_H #define _ARPA_INET_H -#pragma ident "%Z%%M% %I% %E% SMI" - #include <sys/feature_tests.h> #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) @@ -76,8 +74,18 @@ extern struct in_addr inet_makeaddr(in_addr_t, in_addr_t); extern in_addr_t inet_netof(struct in_addr); extern in_addr_t inet_network(const char *); + +extern char *inet_neta(ulong_t, char *, size_t); +extern char *inet_net_ntop(int, const void *, int, char *, size_t); + +extern char *inet_cidr_ntop(int, const void *, int, char *, size_t); +extern int inet_cidr_pton(int, const char *, void *, int *); extern char *inet_ntoa(struct in_addr); extern int inet_aton(const char *, struct in_addr *); + +extern uint_t inet_nsap_addr(const char *, uchar_t *, int); +extern char *inet_nsap_ntoa(int, const uchar_t *, char *); + #else unsigned long inet_addr(); char *inet_ntoa(); @@ -93,6 +101,7 @@ extern unsigned long inet_netof(); extern int inet_pton(); extern const char *inet_ntop(); extern int inet_aton(); + #endif #ifdef __cplusplus diff --git a/usr/src/head/arpa/nameser.h b/usr/src/head/arpa/nameser.h index 60b8734b63..db1ece7a68 100644 --- a/usr/src/head/arpa/nameser.h +++ b/usr/src/head/arpa/nameser.h @@ -1,5 +1,5 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -37,20 +37,21 @@ */ /* - * Copyright (c) 1996-1999 by Internet Software Consortium. + * Portions Copyright (C) 2004, 2005, 2008, 2009 + * Internet Systems Consortium, Inc. ("ISC") + * Portions Copyright (C) 1996-2003 Internet Software Consortium. * - * Permission to use, copy, modify, and distribute this software for any + * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ /* @@ -60,8 +61,6 @@ #ifndef _ARPA_NAMESER_H #define _ARPA_NAMESER_H -#pragma ident "%Z%%M% %I% %E% SMI" - #include <sys/isa_defs.h> @@ -79,7 +78,7 @@ extern "C" { * contains a new enough lib/nameser/ to support the feature you need. */ -#define __NAMESER 19991006 /* New interface version stamp. */ +#define __NAMESER 20090302 /* New interface version stamp. */ /* * Define constants based on RFC 883, RFC 1034, RFC 1035 @@ -89,6 +88,9 @@ extern "C" { #define NS_MAXMSG 65535 /* maximum message size */ #define NS_MAXCDNAME 255 /* maximum compressed domain name */ #define NS_MAXLABEL 63 /* maximum length of domain label */ +#define NS_MAXLABELS 128 /* theoretical max #/labels per domain name */ +#define NS_MAXNNAME 256 /* maximum uncompressed (binary) domain name */ +#define NS_MAXPADDR (sizeof ("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")) #define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */ #define NS_QFIXEDSZ 4 /* #/bytes of fixed data in query */ #define NS_RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ @@ -116,6 +118,18 @@ typedef enum __ns_sect { } ns_sect; /* + * Network name (compressed or not) type. Equivalent to a pointer when used + * in a function prototype. Can be const'd. + */ +typedef uchar_t ns_nname[NS_MAXNNAME]; +typedef const uchar_t *ns_nname_ct; +typedef uchar_t *ns_nname_t; + +struct ns_namemap { ns_nname_ct base; int len; }; +typedef struct ns_namemap *ns_namemap_t; +typedef const struct ns_namemap *ns_namemap_ct; + +/* * This is a message handle. It is caller allocated and has no dynamic data. * This structure is intended to be opaque to all but ns_parse.c, thus the * leading _'s on the member names. Use the accessor functions, not the _'s. @@ -129,6 +143,17 @@ typedef struct __ns_msg { const uchar_t *_msg_ptr; } ns_msg; +/* + * This is a newmsg handle, used when constructing new messages with + * ns_newmsg_init, et al. + */ +struct ns_newmsg { + ns_msg msg; + const uchar_t *dnptrs[25]; + const uchar_t **lastdnptr; +}; +typedef struct ns_newmsg ns_newmsg; + /* Private data structure - do not use from outside library. */ struct _ns_flagdata { int mask, shift; }; extern struct _ns_flagdata _ns_flagdata[]; @@ -152,8 +177,23 @@ typedef struct __ns_rr { const uchar_t *rdata; } ns_rr; +/* + * Same thing, but using uncompressed network binary names, and real C types. + */ +typedef struct __ns_rr2 { + ns_nname nname; + size_t nnamel; + int type; + int rr_class; + uint_t ttl; + int rdlength; + const uchar_t *rdata; +} ns_rr2; + /* Accessor macros - this is part of the public interface. */ #define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".") +#define ns_rr_nname(rr) ((const ns_nname_t)(rr).nname) +#define ns_rr_nnamel(rr) ((rr).nnamel + 0) #define ns_rr_type(rr) ((ns_type)((rr).type + 0)) #define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0)) #define ns_rr_ttl(rr) ((rr).ttl + 0) @@ -230,7 +270,7 @@ typedef enum __ns_update_operation { struct ns_updrec { struct ns_updrec *r_prev; /* prev record */ struct ns_updrec *r_next; /* next record */ - uint8_t r_section; /* ZONE/PREREQUISITE/UPDATE */ + uint8_t r_section; /* ZONE/PREREQUISITE/UPDATE */ char *r_dname; /* owner of the RR */ uint16_t r_class; /* class number */ uint16_t r_type; /* type number */ @@ -323,6 +363,17 @@ typedef enum __ns_type { ns_t_sink = 40, /* Kitchen sink (experimentatl) */ ns_t_opt = 41, /* EDNS0 option (meta-RR) */ ns_t_apl = 42, /* Address prefix list (RFC 3123) */ + ns_t_ds = 43, /* Delegation Signer */ + ns_t_sshfp = 44, /* SSH Fingerprint */ + ns_t_ipseckey = 45, /* IPSEC Key */ + ns_t_rrsig = 46, /* RRset Signature */ + ns_t_nsec = 47, /* Negative security */ + ns_t_dnskey = 48, /* DNS Key */ + ns_t_dhcid = 49, /* Dynamic host configuratin identifier */ + ns_t_nsec3 = 50, /* Negative security type 3 */ + ns_t_nsec3param = 51, /* Negative security type 3 parameters */ + ns_t_hip = 55, /* Host Identity Protocol */ + ns_t_spf = 99, /* Sender Policy Framework */ ns_t_tkey = 249, /* Transaction key */ ns_t_tsig = 250, /* Transaction signature. */ ns_t_ixfr = 251, /* Incremental zone transfer. */ @@ -331,6 +382,7 @@ typedef enum __ns_type { ns_t_maila = 254, /* Transfer mail agent records. */ ns_t_any = 255, /* Wildcard match. */ ns_t_zxfr = 256, /* BIND-specific, nonstandard. */ + ns_t_dlv = 32769, /* DNSSEC look-aside validatation. */ ns_t_max = 65536 } ns_type; @@ -463,6 +515,7 @@ typedef enum __ns_cert_types { * EDNS0 extended flags, host order. */ #define NS_OPT_DNSSEC_OK 0x8000U +#define NS_OPT_NSID 3 /* * Inline versions of get/put short/long. Pointer is advanced. @@ -514,6 +567,7 @@ typedef enum __ns_cert_types { #define ns_initparse __ns_initparse #define ns_skiprr __ns_skiprr #define ns_parserr __ns_parserr +#define ns_parserr2 __ns_parserr2 #define ns_sprintrr __ns_sprintrr #define ns_sprintrrf __ns_sprintrrf #define ns_format_ttl __ns_format_ttl @@ -528,6 +582,11 @@ typedef enum __ns_cert_types { #define ns_name_uncompress __ns_name_uncompress #define ns_name_skip __ns_name_skip #define ns_name_rollback __ns_name_rollback +#define ns_name_length __ns_name_length +#define ns_name_eq __ns_name_eq +#define ns_name_owned __ns_name_owned +#define ns_name_map __ns_name_map +#define ns_name_labels __ns_name_labels #define ns_sign __ns_sign #define ns_sign2 __ns_sign2 #define ns_sign_tcp __ns_sign_tcp @@ -541,6 +600,16 @@ typedef enum __ns_cert_types { #define ns_subdomain __ns_subdomain #define ns_makecanon __ns_makecanon #define ns_samename __ns_samename +#define ns_newmsg_init __ns_newmsg_init +#define ns_newmsg_copy __ns_newmsg_copy +#define ns_newmsg_id __ns_newmsg_id +#define ns_newmsg_flag __ns_newmsg_flag +#define ns_newmsg_q __ns_newmsg_q +#define ns_newmsg_rr __ns_newmsg_rr +#define ns_newmsg_done __ns_newmsg_done +#define ns_rdata_unpack __ns_rdata_unpack +#define ns_rdata_equal __ns_rdata_equal +#define ns_rdata_refers __ns_rdata_refers int ns_msg_getflag(ns_msg, int); uint_t ns_get16(const uchar_t *); @@ -550,6 +619,7 @@ void ns_put32(ulong_t, uchar_t *); int ns_initparse(const uchar_t *, int, ns_msg *); int ns_skiprr(const uchar_t *, const uchar_t *, ns_sect, int); int ns_parserr(ns_msg *, ns_sect, int, ns_rr *); +int ns_parserr2(ns_msg *, ns_sect, int, ns_rr2 *); int ns_sprintrr(const ns_msg *, const ns_rr *, const char *, const char *, char *, size_t); int ns_sprintrrf(const uchar_t *, size_t, const char *, @@ -573,6 +643,11 @@ int ns_name_compress(const char *, uchar_t *, size_t, int ns_name_skip(const uchar_t **, const uchar_t *); void ns_name_rollback(const uchar_t *, const uchar_t **, const uchar_t **); +ssize_t ns_name_length(ns_nname_ct, size_t); +int ns_name_eq(ns_nname_ct, size_t, ns_nname_ct, size_t); +int ns_name_owned(ns_namemap_ct, int, ns_namemap_ct, int); +int ns_name_map(ns_nname_ct, size_t, ns_namemap_t, int); +int ns_name_labels(ns_nname_ct, size_t); int ns_sign(uchar_t *, int *, int, int, void *, const uchar_t *, int, uchar_t *, int *, time_t); int ns_sign2(uchar_t *, int *, int, int, void *, @@ -596,6 +671,24 @@ int ns_samedomain(const char *, const char *); int ns_subdomain(const char *, const char *); int ns_makecanon(const char *, char *, size_t); int ns_samename(const char *, const char *); +int ns_newmsg_init(uchar_t *buffer, size_t bufsiz, ns_newmsg *); +int ns_newmsg_copy(ns_newmsg *, ns_msg *); +void ns_newmsg_id(ns_newmsg *handle, uint16_t id); +void ns_newmsg_flag(ns_newmsg *handle, ns_flag flag, uint_t value); +int ns_newmsg_q(ns_newmsg *handle, ns_nname_ct qname, + ns_type qtype, ns_class qclass); +int ns_newmsg_rr(ns_newmsg *handle, ns_sect sect, + ns_nname_ct name, ns_type type, + ns_class rr_class, uint32_t ttl, + uint16_t rdlen, const uchar_t *rdata); +size_t ns_newmsg_done(ns_newmsg *handle); +ssize_t ns_rdata_unpack(const uchar_t *, const uchar_t *, ns_type, + const uchar_t *, size_t, uchar_t *, size_t); +int ns_rdata_equal(ns_type, const uchar_t *, size_t, + const uchar_t *, size_t); +int ns_rdata_refers(ns_type, + const uchar_t *, size_t, + const uchar_t *); #ifdef BIND_4_COMPAT #include <arpa/nameser_compat.h> diff --git a/usr/src/head/netdb.h b/usr/src/head/netdb.h index 81a9da0aff..8c912d3ffa 100644 --- a/usr/src/head/netdb.h +++ b/usr/src/head/netdb.h @@ -120,6 +120,8 @@ struct addrinfo { struct sockaddr *ai_addr; /* binary address */ struct addrinfo *ai_next; /* next structure in linked list */ }; + + /* addrinfo flags */ #define AI_PASSIVE 0x0008 /* intended for bind() + listen() */ #define AI_CANONNAME 0x0010 /* return canonical version of host */ @@ -131,6 +133,7 @@ struct addrinfo { #define AI_ALL 0x0002 /* IPv6 and IPv4 mapped addresses */ #define AI_ADDRCONFIG 0x0004 /* AAAA or A records only if IPv6/IPv4 cnfg'd */ + /* * These were defined in RFC 2553 but not SUSv3 * or RFC 3493 which obsoleted 2553. @@ -152,6 +155,8 @@ struct addrinfo { #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ #define EAI_SYSTEM 11 /* system error in errno */ #define EAI_OVERFLOW 12 /* argument buffer overflow */ +#define EAI_PROTOCOL 13 +#define EAI_MAX 14 /* getnameinfo flags */ #define NI_NOFQDN 0x0001 @@ -172,6 +177,12 @@ struct addrinfo { #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */ /* + * Scope delimit character + */ +#define SCOPE_DELIMITER '%' + + +/* * Algorithm entry for /etc/inet/ipsecalgs which defines IPsec protocols * and algorithms. */ @@ -438,6 +449,10 @@ extern int *__h_errno(); #endif /* NO_H_ERRNO_DEFINE */ #endif /* _REENTRANT */ +/* + * Error return codes from gethostbyname() and gethostbyaddr() + * (left in extern int h_errno). + */ #define HOST_NOT_FOUND 1 /* Authoritive Answer Host not found */ #define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */ #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ diff --git a/usr/src/head/resolv.h b/usr/src/head/resolv.h index 235af69e0b..90149fe77d 100644 --- a/usr/src/head/resolv.h +++ b/usr/src/head/resolv.h @@ -1,5 +1,5 @@ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * * Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T @@ -95,8 +95,6 @@ #ifndef _RESOLV_H_ #define _RESOLV_H_ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <sys/param.h> #include <stdio.h> @@ -115,7 +113,7 @@ extern "C" { * is new enough to contain a certain feature. */ -#define __RES 20030124 +#define __RES 20090302 #define RES_SET_H_ERRNO(r, x) __h_errno_set(r, x) struct __res_state; /* forward */ @@ -228,6 +226,7 @@ struct __res_state { uint16_t nstimes[MAXNS]; /* ms. */ int nssocks[MAXNS]; struct __res_state_ext *ext; /* extention for IPv6 */ + uchar_t _rnd[16]; /* PRIVATE: random state */ } _ext; } _u; }; @@ -383,7 +382,9 @@ int dn_comp __P((const char *, uchar_t *, int, uchar_t **, uchar_t **)); int dn_expand __P((const uchar_t *, const uchar_t *, const uchar_t *, char *, int)); +void res_rndinit __P((res_state)); uint_t res_randomid __P((void)); +uint_t res_nrandomid __P((res_state)); int res_nameinquery __P((const char *, int, int, const uchar_t *, const uchar_t *)); int res_queriesmatch __P((const uchar_t *, const uchar_t *, @@ -420,6 +421,8 @@ int res_findzonecut2 __P((res_state, const char *, ns_class, int, int)); void res_nclose __P((res_state)); int res_nopt __P((res_state, int, uchar_t *, int, int)); +int res_nopt_rdata __P((res_state, int, uchar_t *, int, uchar_t *, + ushort_t, ushort_t, uchar_t *)); void res_send_setqhook __P((res_send_qhook hook)); void res_send_setrhook __P((res_send_rhook hook)); int __res_vinit __P((res_state, int)); diff --git a/usr/src/lib/libresolv2/Makefile b/usr/src/lib/libresolv2/Makefile index 3a671c5aae..70e7158eda 100644 --- a/usr/src/lib/libresolv2/Makefile +++ b/usr/src/lib/libresolv2/Makefile @@ -24,6 +24,7 @@ # # + include ../../Makefile.master include ../Makefile.lib @@ -37,13 +38,6 @@ CHKMANIFEST= $(MANIFEST:%.xml=%.xmlchk) SUBDIRS= include $(MACH) $(BUILD64)SUBDIRS += $(MACH64) -SUBDIRS += .WAIT irs - -# EXPORT DELETE START -# CRYPT DELETE START -SUBDIRS += cylink dnssafe -# CRYPT DELETE END -# EXPORT DELETE END all := TARGET= all clean := TARGET= clean @@ -83,31 +77,6 @@ install_h: $(ROOTHDRS) check: $(CHECKHDRS) $(CHKMANIFEST) -# EXPORT DELETE START -# CRYPT DELETE START -# Special targets to clean up the source tree for export distribution -# Warning: These target change the source tree -EXPORT_SRC: - $(RM) Makefile+ - $(SED) -e "/^# EXPORT DELETE START/,/^# EXPORT DELETE END/d" \ - < Makefile > Makefile+ - $(MV) Makefile+ Makefile - $(CHMOD) 444 Makefile - /usr/bin/find cylink dnssafe common/cylink common/dnssafe \ - -name SCCS -prune -o -type f -exec $(RM) {} \; - -CRYPT_SRC: - $(RM) Makefile+ - $(SED) -e "/^# CRYPT DELETE START/,/^# CRYPT DELETE END/d" \ - < Makefile > Makefile+ - $(MV) Makefile+ Makefile - $(CHMOD) 444 Makefile - /usr/bin/find cylink dnssafe common/cylink common/dnssafe \ - -name SCCS -prune -o -type f -exec $(RM) {} \; - -# CRYPT DELETE END -# EXPORT DELETE END - _msg: $(MSGDOMAIN) $(POFILE) $(RM) $(MSGDOMAIN)/$(POFILE) $(CP) $(POFILE) $(MSGDOMAIN) @@ -126,3 +95,4 @@ $(SUBDIRS): FRC @cd $@; pwd; $(MAKE) $(TARGET); echo FRC: + diff --git a/usr/src/lib/libresolv2/Makefile.com b/usr/src/lib/libresolv2/Makefile.com index b37e4ba50d..3c69a169b6 100644 --- a/usr/src/lib/libresolv2/Makefile.com +++ b/usr/src/lib/libresolv2/Makefile.com @@ -19,10 +19,9 @@ # CDDL HEADER END # # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# ident "%Z%%M% %I% %E% SMI" # LIBRARY= libresolv.a @@ -33,70 +32,48 @@ BSDOBJS= daemon.o putenv.o strcasecmp.o strsep.o \ gettimeofday.o setenv.o strerror.o utimes.o \ mktemp.o setitimer.o strpbrk.o writev.o -DSTOBJS= dst_api.o prandom.o support.o - -DSTLINKOBJS= bsafe_link.o cylink_link.o eay_dss_link.o hmac_link.o \ - rsaref_link.o - -INETOBJS= inet_net_pton.o inet_ntop.o \ - inet_neta.o inet_pton.o inet_lnaof.o inet_netof.o \ - nsap_addr.o inet_makeaddr.o inet_network.o \ - inet_net_ntop.o inet_ntoa.o inet_cidr_ntop.o \ - inet_cidr_pton.o inet_data.o - -IRSOBJS= dns.o gen_ho.o getnetgrent.o lcl_ng.o \ - nis_nw.o dns_gr.o gen_ng.o getprotoent.o \ - lcl_nw.o nis_pr.o dns_ho.o gen_nw.o \ - getpwent.o lcl_pr.o nis_pw.o dns_nw.o \ - gen_pr.o getservent.o lcl_pw.o nis_sv.o \ - dns_pr.o gen_pw.o hesiod.o lcl_sv.o \ - nul_ng.o dns_pw.o gen_sv.o irs_data.o \ - nis.o util.o dns_sv.o getgrent.o \ - lcl.o nis_gr.o gen.o gethostent.o \ - lcl_gr.o nis_ho.o gen_gr.o getnetent.o \ - lcl_ho.o nis_ng.o getpwent_r.o \ - getservent_r.o gai_strerror.o getgrent_r.o \ - gethostent_r.o getnetent_r.o getnetgrent_r.o \ - getprotoent_r.o getnameinfo.o irp.o irpmarshall.o \ - irp_ho.o irp_nw.o irp_pr.o irp_sv.o \ - irp_gr.o irp_ng.o irp_pw.o - -IRSRESOBJS= dns.o gen_ho.o lcl_ng.o dns_gr.o \ - gen_ng.o lcl_nw.o dns_ho.o gen_nw.o \ - lcl_pr.o dns_nw.o gen_pr.o lcl_pw.o \ - dns_pr.o gen_pw.o hesiod.o lcl_sv.o \ - nul_ng.o dns_pw.o gen_sv.o irs_data.o \ - util.o dns_sv.o lcl.o gen.o \ - gethostent.o lcl_gr.o gen_gr.o lcl_ho.o \ - gethostent_r.o getaddrinfo.o - -IRSDYNOBJS= nis_nw.o nis_pr.o nis_pw.o nis_sv.o \ - nis.o nis_gr.o nis_ho.o nis_ng.o \ - irp.o irpmarshall.o irp_ho.o irp_nw.o \ - irp_pr.o irp_sv.o irp_gr.o irp_ng.o \ - irp_pw.o getnetent.o getpwent_r.o getgrent_r.o \ - getservent_r.o getnetent_r.o getnetgrent_r.o getgrent.o \ - getnetgrent.o getprotoent.o getpwent.o getservent.o \ - getprotoent_r.o getnameinfo.o gai_strerror.o - -ISCOBJS= base64.o ev_files.o ev_waits.o logging.o \ - bitncmp.o ev_streams.o eventlib.o tree.o \ - ev_connects.o ev_timers.o heap.o assertions.o \ - memcluster.o ctl_p.o ctl_clnt.o ctl_srvr.o \ - hex.o - -NAMESEROBJS= ns_name.o ns_netint.o ns_parse.o ns_print.o \ - ns_ttl.o ns_sign.o ns_verify.o ns_date.o \ - ns_samedomain.o - -RESOLVOBJS= herror.o res_debug.o res_data.o res_comp.o \ - res_init.o res_mkquery.o res_mkupdate.o res_query.o \ - res_send.o res_update.o res_sendsigned.o \ - res_findzonecut.o - -SUNWOBJS= sunw_mtctxres.o sunw_dst_init.o sunw_irs_init.o sunw_updrec.o - -OBJECTS= $(BSDOBJS) $(DSTOBJS) $(INETOBJS) $(IRSRESOBJS) $(ISCOBJS) \ +DSTOBJS= dst_api.o support.o hmac_link.o + +# inet_addr, inet_pton, inet_ntop, and inet_ntoa removed due to overlap with +# libnsl +INETOBJS= inet_net_pton.o inet_neta.o inet_lnaof.o \ + inet_netof.o nsap_addr.o inet_makeaddr.o \ + inet_network.o inet_net_ntop.o inet_cidr_ntop.o \ + inet_cidr_pton.o inet_data.o + +# build only the IRS objects that the ISC libbind's make would +IRSTHROBJS= gethostent_r.o getnetent_r.o getnetgrent_r.o \ + getprotoent_r.o getservent_r.o +IRSOBJS= ${IRSTHROBJS} \ + dns.o dns_ho.o dns_nw.o dns_pr.o \ + dns_sv.o gai_strerror.o gen.o gen_ho.o \ + gen_ng.o gen_nw.o gen_pr.o gen_sv.o \ + getaddrinfo.o gethostent.o getnameinfo.o getnetent.o \ + getnetgrent.o getprotoent.o getservent.o hesiod.o \ + irp.o irp_ho.o irp_ng.o irp_nw.o \ + irp_pr.o irp_sv.o irpmarshall.o irs_data.o \ + lcl.o lcl_ho.o lcl_ng.o lcl_nw.o \ + lcl_pr.o lcl_sv.o nis.o nul_ng.o \ + util.o + +ISCOBJS= assertions.o base64.o bitncmp.o ctl_clnt.o \ + ctl_p.o ctl_srvr.o ev_connects.o ev_files.o \ + ev_streams.o ev_timers.o ev_waits.o eventlib.o \ + heap.o hex.o logging.o memcluster.o \ + movefile.o tree.o + +NAMESEROBJS= ns_date.o ns_name.o ns_netint.o ns_parse.o \ + ns_print.o ns_samedomain.o ns_sign.o ns_ttl.o \ + ns_verify.o ns_rdata.o ns_newmsg.o + +RESOLVOBJS= herror.o mtctxres.o res_comp.o res_data.o \ + res_debug.o res_findzonecut.o res_init.o \ + res_mkquery.o res_mkupdate.o res_query.o res_send.o \ + res_sendsigned.o res_update.o + +SUNWOBJS= sunw_mtctxres.o sunw_updrec.o sunw_wrappers.o + +OBJECTS= $(BSDOBJS) $(DSTOBJS) $(INETOBJS) $(IRSOBJS) $(ISCOBJS) \ $(NAMESEROBJS) $(RESOLVOBJS) $(SUNWOBJS) # include library definitions @@ -105,11 +82,14 @@ include ../../Makefile.lib # install this library in the root filesystem include ../../Makefile.rootfs +# CC -v complains about things we aren't going to change in the ISC code +CCVERBOSE= + SRCDIR = ../common SRCS= $(BSDOBJS:%.o=../common/bsd/%.c) \ $(DSTOBJS:%.o=../common/dst/%.c) \ $(INETOBJS:%.o=../common/inet/%.c) \ - $(IRSRESOBJS:%.o=../common/irs/%.c) \ + $(IRSOBJS:%.o=../common/irs/%.c) \ $(ISCOBJS:%.o=../common/isc/%.c) \ $(NAMESEROBJS:%.o=../common/nameser/%.c) \ $(RESOLVOBJS:%.o=../common/resolv/%.c) \ @@ -120,20 +100,9 @@ LIBS = $(DYNLIB) $(LINTLIB) $(LINTLIB):= SRCS = ../common/llib-lresolv # Local Libresolv definitions -SOLCOMPAT = -Dgethostbyname=res_gethostbyname \ - -Dgethostbyaddr=res_gethostbyaddr -Dgetnetbyname=res_getnetbyname \ - -Dgethostbyname2=res_gethostbyname2\ - -Dgetnetbyaddr=res_getnetbyaddr -Dsethostent=res_sethostent \ - -Dendhostent=res_endhostent -Dgethostent=res_gethostent \ - -Dsetnetent=res_setnetent -Dendnetent=res_endnetent \ - -Dgetnetent=res_getnetent -Dsocket=_socket \ - -Dgetipnodebyname=res_getipnodebyname \ - -Dgetipnodebyaddr=res_getipnodebyaddr \ - -Dfreehostent=res_freehostent \ - -Dgetaddrinfo=res_getaddrinfo \ - -Dfreeaddrinfo=res_freeaddrinfo - -CRYPTFLAGS= -DCYLINK_DSS -DHMAC_MD5 -DUSE_MD5 -DDNSSAFE + +SOLCOMPAT = -Dsocket=_socket +CRYPTFLAGS= -DHMAC_MD5 -DUSE_MD5 LOCFLAGS += $(CRYPTFLAGS) LOCFLAGS += -D_SYS_STREAM_H -D_REENTRANT -DSVR4 -DSUNW_OPTIONS \ @@ -141,7 +110,8 @@ LOCFLAGS += -D_SYS_STREAM_H -D_REENTRANT -DSVR4 -DSUNW_OPTIONS \ CPPFLAGS += $(LOCFLAGS) DYNFLAGS += $(ZNODELETE) -LDLIBS += -lsocket -lnsl -lc + +LDLIBS += -lsocket -lnsl -lc -lmd .KEEP_STATE: diff --git a/usr/src/lib/libresolv2/common/bsd/daemon.c b/usr/src/lib/libresolv2/common/bsd/daemon.c index aeb4f2c083..54ff83b753 100644 --- a/usr/src/lib/libresolv2/common/bsd/daemon.c +++ b/usr/src/lib/libresolv2/common/bsd/daemon.c @@ -1,11 +1,6 @@ -/* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: daemon.c,v 8.2 1999/10/13 16:39:20 vixie Exp $"; +static const char rcsid[] = "$Id: daemon.c,v 1.2 2005/04/27 04:56:10 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -41,8 +36,6 @@ static const char rcsid[] = "$Id: daemon.c,v 8.2 1999/10/13 16:39:20 vixie Exp $ * SUCH DAMAGE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include <fcntl.h> @@ -84,3 +77,5 @@ daemon(int nochdir, int noclose) { return (0); } #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/bsd/ftruncate.c b/usr/src/lib/libresolv2/common/bsd/ftruncate.c index 98b953b312..5ac4ebac9b 100644 --- a/usr/src/lib/libresolv2/common/bsd/ftruncate.c +++ b/usr/src/lib/libresolv2/common/bsd/ftruncate.c @@ -1,15 +1,9 @@ -/* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - #ifndef LINT -static const char rcsid[] = "$Id: ftruncate.c,v 8.4 1999/10/13 16:39:21 vixie Exp $"; +static const char rcsid[] = "$Id: ftruncate.c,v 1.3 2005/04/27 18:16:45 sra Exp $"; #endif -#pragma ident "%Z%%M% %I% %E% SMI" - -/* +/*! \file + * \brief * ftruncate - set file size, BSD Style * * shortens or enlarges the file as neeeded diff --git a/usr/src/lib/libresolv2/common/bsd/gettimeofday.c b/usr/src/lib/libresolv2/common/bsd/gettimeofday.c index 68b5ca39a0..2926a3575e 100644 --- a/usr/src/lib/libresolv2/common/bsd/gettimeofday.c +++ b/usr/src/lib/libresolv2/common/bsd/gettimeofday.c @@ -1,20 +1,47 @@ -/* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - #ifndef LINT -static const char rcsid[] = "$Id: gettimeofday.c,v 8.4 1999/10/13 16:39:21 vixie Exp $"; +static const char rcsid[] = "$Id: gettimeofday.c,v 1.4 2005/04/27 04:56:11 sra Exp $"; #endif - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" +#include <stdio.h> +#include <syslog.h> +#include <sys/time.h> #include "port_after.h" #if !defined(NEED_GETTIMEOFDAY) -int __bindcompat_gettimeofday; +/*% + * gettimeofday() occasionally returns invalid tv_usec on some platforms. + */ +#define MILLION 1000000 +#undef gettimeofday + +int +isc__gettimeofday(struct timeval *tp, struct timezone *tzp) { + int res; + + res = gettimeofday(tp, tzp); + if (res < 0) + return (res); + if (tp == NULL) + return (res); + if (tp->tv_usec < 0) { + do { + tp->tv_usec += MILLION; + tp->tv_sec--; + } while (tp->tv_usec < 0); + goto log; + } else if (tp->tv_usec > MILLION) { + do { + tp->tv_usec -= MILLION; + tp->tv_sec++; + } while (tp->tv_usec > MILLION); + goto log; + } + return (res); + log: + syslog(LOG_ERR, "gettimeofday: tv_usec out of range\n"); + return (res); +} #else int gettimeofday(struct timeval *tvp, struct _TIMEZONE *tzp) { diff --git a/usr/src/lib/libresolv2/common/bsd/mktemp.c b/usr/src/lib/libresolv2/common/bsd/mktemp.c index b29ae93d51..001b24b58f 100644 --- a/usr/src/lib/libresolv2/common/bsd/mktemp.c +++ b/usr/src/lib/libresolv2/common/bsd/mktemp.c @@ -1,11 +1,6 @@ -/* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: mktemp.c,v 8.4 1999/10/13 16:39:21 vixie Exp $"; +static const char rcsid[] = "$Id: mktemp.c,v 1.2 2005/04/27 04:56:11 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -61,9 +56,6 @@ static const char rcsid[] = "$Id: mktemp.c,v 8.4 1999/10/13 16:39:21 vixie Exp $ * SOFTWARE. */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include <sys/types.h> @@ -104,7 +96,7 @@ gettemp(char *path, int *doopen) { u_int pid; pid = getpid(); - for (trv = path; *trv; ++trv); /* extra X's get set to 0's */ + for (trv = path; *trv; ++trv); /*%< extra X's get set to 0's */ while (*--trv == 'X') { *trv = (pid % 10) + '0'; pid /= 10; @@ -160,3 +152,5 @@ gettemp(char *path, int *doopen) { } #endif /*NEED_MKTEMP*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/bsd/putenv.c b/usr/src/lib/libresolv2/common/bsd/putenv.c index 08ef44463e..2dcbc57e6c 100644 --- a/usr/src/lib/libresolv2/common/bsd/putenv.c +++ b/usr/src/lib/libresolv2/common/bsd/putenv.c @@ -1,19 +1,11 @@ -/* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - #ifndef LINT -static const char rcsid[] = "$Id: putenv.c,v 8.4 1999/10/13 16:39:21 vixie Exp $"; +static const char rcsid[] = "$Id: putenv.c,v 1.2 2005/04/27 04:56:11 sra Exp $"; #endif - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include "port_after.h" -/* +/*% * To give a little credit to Sun, SGI, * and many vendors in the SysV world. */ @@ -31,3 +23,5 @@ putenv(char *str) { return (setenv(str, tmp, 1)); } #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/bsd/readv.c b/usr/src/lib/libresolv2/common/bsd/readv.c index 5852e2e20a..5fa691a92f 100644 --- a/usr/src/lib/libresolv2/common/bsd/readv.c +++ b/usr/src/lib/libresolv2/common/bsd/readv.c @@ -1,15 +1,7 @@ -/* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - #ifndef LINT -static const char rcsid[] = "$Id: readv.c,v 8.2 1999/10/13 16:39:21 vixie Exp $"; +static const char rcsid[] = "$Id: readv.c,v 1.2 2005/04/27 04:56:11 sra Exp $"; #endif - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include <sys/types.h> @@ -44,3 +36,4 @@ __readv(fd, vp, vpcount) return (count); } #endif /* NEED_READV */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/bsd/setenv.c b/usr/src/lib/libresolv2/common/bsd/setenv.c index 963d0e6e1b..baf00f6ff2 100644 --- a/usr/src/lib/libresolv2/common/bsd/setenv.c +++ b/usr/src/lib/libresolv2/common/bsd/setenv.c @@ -1,11 +1,6 @@ -/* - * Copyright (c) 1997, by Sun Microsystems, Inc. - * All rights reserved. - */ - #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)setenv.c 8.1 (Berkeley) 6/4/93"; -static char rcsid[] = "$Id: setenv.c,v 8.4 1997/04/24 22:00:38 vixie Exp $"; +static const char sccsid[] = "@(#)setenv.c 8.1 (Berkeley) 6/4/93"; +static const char rcsid[] = "$Id: setenv.c,v 1.2 2005/04/27 04:56:11 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -41,9 +36,6 @@ static char rcsid[] = "$Id: setenv.c,v 8.4 1997/04/24 22:00:38 vixie Exp $"; * SUCH DAMAGE. */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include <stddef.h> @@ -60,40 +52,40 @@ extern char **environ; static char *findenv(const char *name, int *offset); -/* +/*% * setenv -- * Set the value of the environmental variable "name" to be * "value". If rewrite is set, replace any current value. */ setenv(const char *name, const char *value, int rewrite) { extern char **environ; - static int alloced; /* if allocated space before */ + static int alloced; /*%< if allocated space before */ char *c; int l_value, offset; - if (*value == '=') /* no `=' in value */ + if (*value == '=') /*%< no `=' in value */ ++value; l_value = strlen(value); - if ((c = findenv(name, &offset))) { /* find if already exists */ + if ((c = findenv(name, &offset))) { /*%< find if already exists */ if (!rewrite) return (0); - if (strlen(c) >= l_value) { /* old larger; copy over */ + if (strlen(c) >= l_value) { /*%< old larger; copy over */ while (*c++ = *value++); return (0); } - } else { /* create new slot */ + } else { /*%< create new slot */ int cnt; char **p; for (p = environ, cnt = 0; *p; ++p, ++cnt); - if (alloced) { /* just increase size */ + if (alloced) { /*%< just increase size */ environ = (char **)realloc((char *)environ, (size_t)(sizeof(char *) * (cnt + 2))); if (!environ) return (-1); } - else { /* get new space */ - alloced = 1; /* copy old entries into it */ + else { /*%< get new space */ + alloced = 1; /*%< copy old entries into it */ p = malloc((size_t)(sizeof(char *) * (cnt + 2))); if (!p) return (-1); @@ -103,8 +95,8 @@ setenv(const char *name, const char *value, int rewrite) { environ[cnt + 1] = NULL; offset = cnt; } - for (c = (char *)name; *c && *c != '='; ++c); /* no `=' in name */ - if (!(environ[offset] = /* name + `=' + value */ + for (c = (char *)name; *c && *c != '='; ++c); /*%< no `=' in name */ + if (!(environ[offset] = /*%< name + `=' + value */ malloc((size_t)((int)(c - name) + l_value + 2)))) return (-1); for (c = environ[offset]; (*c = *name++) && *c != '='; ++c); @@ -112,7 +104,7 @@ setenv(const char *name, const char *value, int rewrite) { return (0); } -/* +/*% * unsetenv(name) -- * Delete environmental variable "name". */ @@ -121,13 +113,13 @@ unsetenv(const char *name) { char **p; int offset; - while (findenv(name, &offset)) /* if set multiple times */ + while (findenv(name, &offset)) /*%< if set multiple times */ for (p = &environ[offset];; ++p) if (!(*p = *(p + 1))) break; } -/* +/*% * findenv -- * Returns pointer to value associated with name, if any, else NULL. * Sets offset to be the offset of the name/value combination in the @@ -155,3 +147,5 @@ findenv(const char *name, int *offset) { return (NULL); } #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/bsd/setitimer.c b/usr/src/lib/libresolv2/common/bsd/setitimer.c index a0185c9c1d..67881d7ca8 100644 --- a/usr/src/lib/libresolv2/common/bsd/setitimer.c +++ b/usr/src/lib/libresolv2/common/bsd/setitimer.c @@ -1,22 +1,14 @@ -/* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - #ifndef LINT -static const char rcsid[] = "$Id: setitimer.c,v 8.4 1999/10/13 16:39:21 vixie Exp $"; +static const char rcsid[] = "$Id: setitimer.c,v 1.2 2005/04/27 04:56:12 sra Exp $"; #endif - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include <sys/time.h> #include "port_after.h" -/* +/*% * Setitimer emulation routine. */ #ifndef NEED_SETITIMER @@ -33,3 +25,5 @@ __setitimer(int which, const struct itimerval *value, return (-1); } #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/bsd/strcasecmp.c b/usr/src/lib/libresolv2/common/bsd/strcasecmp.c index 69e71760f0..0c9f0dccf0 100644 --- a/usr/src/lib/libresolv2/common/bsd/strcasecmp.c +++ b/usr/src/lib/libresolv2/common/bsd/strcasecmp.c @@ -1,11 +1,6 @@ -/* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: strcasecmp.c,v 8.5 1999/10/13 16:39:21 vixie Exp $"; +static const char rcsid[] = "$Id: strcasecmp.c,v 1.2 2005/04/27 04:56:12 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -41,9 +36,6 @@ static const char rcsid[] = "$Id: strcasecmp.c,v 8.5 1999/10/13 16:39:21 vixie E * SUCH DAMAGE. */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include <sys/param.h> @@ -58,7 +50,7 @@ static const char rcsid[] = "$Id: strcasecmp.c,v 8.5 1999/10/13 16:39:21 vixie E int __strcasecmp_unneeded__; #else -/* +/*% * This array is designed for mapping upper and lower case letter * together for a case independent comparison. The mappings are * based upon ascii character sequences. @@ -128,3 +120,5 @@ strncasecmp(const char *s1, const char *s2, size_t n) { } #endif /*NEED_STRCASECMP*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/bsd/strdup.c b/usr/src/lib/libresolv2/common/bsd/strdup.c index d92ed9e91d..a8d31e9587 100644 --- a/usr/src/lib/libresolv2/common/bsd/strdup.c +++ b/usr/src/lib/libresolv2/common/bsd/strdup.c @@ -1,11 +1,3 @@ -/* - * Copyright (c) 1997, by Sun Microsystems, Inc. - * All rights reserved. - */ - - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include <stdlib.h> @@ -24,3 +16,5 @@ strdup(const char *src) { return (dst); } #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/bsd/strerror.c b/usr/src/lib/libresolv2/common/bsd/strerror.c index 4d650edfc1..5973e63d5b 100644 --- a/usr/src/lib/libresolv2/common/bsd/strerror.c +++ b/usr/src/lib/libresolv2/common/bsd/strerror.c @@ -1,11 +1,6 @@ -/* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)strerror.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: strerror.c,v 8.7 2001/08/28 11:48:10 marka Exp $"; +static const char rcsid[] = "$Id: strerror.c,v 1.6 2008/02/18 03:49:08 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -41,8 +36,6 @@ static const char rcsid[] = "$Id: strerror.c,v 8.7 2001/08/28 11:48:10 marka Exp * SUCH DAMAGE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include <sys/param.h> @@ -64,19 +57,21 @@ extern char *sys_errlist[]; const char * isc_strerror(int num) { #define UPREFIX "Unknown error: " - static char ebuf[40] = UPREFIX; /* 64-bit number + slop */ + static char ebuf[40] = UPREFIX; /*%< 64-bit number + slop */ u_int errnum; char *p, *t; +#ifndef USE_SYSERROR_LIST const char *ret; +#endif char tmp[40]; - errnum = num; /* convert to unsigned */ + errnum = num; /*%< convert to unsigned */ #ifdef USE_SYSERROR_LIST - if (errnum < sys_nerr) + if (errnum < (u_int)sys_nerr) return (sys_errlist[errnum]); #else #undef strerror - ret = strerror(num); /* call strerror() in libc */ + ret = strerror(num); /*%< call strerror() in libc */ if (ret != NULL) return(ret); #endif @@ -95,3 +90,5 @@ isc_strerror(int num) { } #endif /*NEED_STRERROR*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/bsd/strpbrk.c b/usr/src/lib/libresolv2/common/bsd/strpbrk.c index d001f28d31..4c12d88e1c 100644 --- a/usr/src/lib/libresolv2/common/bsd/strpbrk.c +++ b/usr/src/lib/libresolv2/common/bsd/strpbrk.c @@ -1,11 +1,6 @@ -/* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)strpbrk.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: strpbrk.c,v 8.4 1999/10/13 16:39:21 vixie Exp $"; +static const char rcsid[] = "$Id: strpbrk.c,v 1.2 2005/04/27 04:56:12 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -41,9 +36,6 @@ static const char rcsid[] = "$Id: strpbrk.c,v 8.4 1999/10/13 16:39:21 vixie Exp * SUCH DAMAGE. */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include <sys/param.h> @@ -57,7 +49,7 @@ static const char rcsid[] = "$Id: strpbrk.c,v 8.4 1999/10/13 16:39:21 vixie Exp int __strpbrk_unneeded__; #else -/* +/*% * Find the first occurrence in s1 of a character in s2 (excluding NUL). */ char * @@ -74,3 +66,5 @@ strpbrk(const char *s1, const char *s2) { } #endif /*NEED_STRPBRK*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/bsd/strsep.c b/usr/src/lib/libresolv2/common/bsd/strsep.c index bbbdf3bc75..c7969f0028 100644 --- a/usr/src/lib/libresolv2/common/bsd/strsep.c +++ b/usr/src/lib/libresolv2/common/bsd/strsep.c @@ -1,11 +1,6 @@ -/* - * Copyright (c) 1997, by Sun Microsystems, Inc. - * All rights reserved. - */ - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "strsep.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: strsep.c,v 8.5 1996/11/18 09:09:04 vixie Exp $"; +static const char rcsid[] = "$Id: strsep.c,v 1.2 2005/04/27 04:56:12 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -41,8 +36,6 @@ static const char rcsid[] = "$Id: strsep.c,v 8.5 1996/11/18 09:09:04 vixie Exp $ * SUCH DAMAGE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include <sys/cdefs.h> #include <string.h> @@ -53,7 +46,7 @@ static const char rcsid[] = "$Id: strsep.c,v 8.5 1996/11/18 09:09:04 vixie Exp $ int __strsep_unneeded__; #else -/* +/*% * Get next token from string *stringp, where tokens are possibly-empty * strings separated by characters from delim. * @@ -91,3 +84,5 @@ strsep(char **stringp, const char *delim) { } #endif /*NEED_STRSEP*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/bsd/strtoul.c b/usr/src/lib/libresolv2/common/bsd/strtoul.c index 41e23c1124..b37ff72729 100644 --- a/usr/src/lib/libresolv2/common/bsd/strtoul.c +++ b/usr/src/lib/libresolv2/common/bsd/strtoul.c @@ -1,11 +1,6 @@ -/* - * Copyright 2003 by Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)strtoul.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: strtoul.c,v 8.5 2002/07/06 02:35:04 marka Exp $"; +static const char rcsid[] = "$Id: strtoul.c,v 1.4 2008/02/18 03:49:08 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -41,9 +36,6 @@ static const char rcsid[] = "$Id: strtoul.c,v 8.5 2002/07/06 02:35:04 marka Exp * SUCH DAMAGE. */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include <sys/types.h> @@ -60,7 +52,7 @@ static const char rcsid[] = "$Id: strtoul.c,v 8.5 2002/07/06 02:35:04 marka Exp int __strtoul_unneeded__; #else -/* +/*% * Convert a string to an unsigned long integer. * * Ignores `locale' stuff. Assumes that the upper and lower case @@ -78,7 +70,7 @@ strtoul(const char *nptr, char **endptr, int base) { * See strtol for comments as to the logic used. */ do { - c = *(unsigned char *)s++; + c = *(const unsigned char *)s++; } while (isspace(c)); if (c == '-') { neg = 1; @@ -95,7 +87,7 @@ strtoul(const char *nptr, char **endptr, int base) { base = c == '0' ? 8 : 10; cutoff = (u_long)ULONG_MAX / (u_long)base; cutlim = (u_long)ULONG_MAX % (u_long)base; - for (acc = 0, any = 0;; c = *(unsigned char*)s++) { + for (acc = 0, any = 0;; c = *(const unsigned char*)s++) { if (isdigit(c)) c -= '0'; else if (isalpha(c)) @@ -104,7 +96,7 @@ strtoul(const char *nptr, char **endptr, int base) { break; if (c >= base) break; - if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) any = -1; else { any = 1; @@ -118,8 +110,10 @@ strtoul(const char *nptr, char **endptr, int base) { } else if (neg) acc = -acc; if (endptr != 0) - *endptr = (char *)(any ? s - 1 : nptr); + DE_CONST((any ? s - 1 : nptr), *endptr); return (acc); } #endif /*NEED_STRTOUL*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/bsd/utimes.c b/usr/src/lib/libresolv2/common/bsd/utimes.c index 8a461ddbd0..2f65cffe25 100644 --- a/usr/src/lib/libresolv2/common/bsd/utimes.c +++ b/usr/src/lib/libresolv2/common/bsd/utimes.c @@ -1,28 +1,20 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1997,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include <sys/types.h> @@ -45,3 +37,4 @@ __utimes(char *filename, struct timeval *tvp) { } #endif /* NEED_UTIMES */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/bsd/writev.c b/usr/src/lib/libresolv2/common/bsd/writev.c index 6e348810ec..65baa71cfc 100644 --- a/usr/src/lib/libresolv2/common/bsd/writev.c +++ b/usr/src/lib/libresolv2/common/bsd/writev.c @@ -1,15 +1,7 @@ -/* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - #ifndef LINT -static const char rcsid[] = "$Id: writev.c,v 8.6 2003/04/30 05:21:18 marka Exp $"; +static const char rcsid[] = "$Id: writev.c,v 1.3 2005/04/27 04:56:13 sra Exp $"; #endif - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include <sys/types.h> @@ -36,7 +28,7 @@ __writev(int fd, struct iovec *iov, int iovlen) /* * Allow for atomic writes to network. */ - if (S_ISSOCK(statbuf.st_mode)) { + if (statbuf.st_mode & S_IFSOCK) { struct msghdr mesg; memset(&mesg, 0, sizeof(mesg)); @@ -93,3 +85,5 @@ __writev(fd, vp, vpcount) #endif /*_CRAY*/ #endif /*NEED_WRITEV*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/cylink/bits.c b/usr/src/lib/libresolv2/common/cylink/bits.c deleted file mode 100644 index 21cadf7a50..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/bits.c +++ /dev/null @@ -1,366 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/**************************************************************************** -* FILENAME: bit.c PRODUCT NAME: CRYPTOGRAPHIC TOOLKIT -* -* FILE STATUS: -* -* DESCRIPTION: Bit Utility Functions -* -* PUBLIC FUNCTIONS: -* -* -* PRIVATE FUNCTIONS: -* -* REVISION HISTORY: -* -* -****************************************************************************/ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/**************************************************************************** -* INCLUDE FILES -****************************************************************************/ -/* bn files */ -#include "port_before.h" -#include <sys/types.h> -#include "bn.h" -/* system files */ -#ifdef VXD -#include <vtoolsc.h> -#else -#include <stdlib.h> -#include <string.h> -#endif -/* program files */ -#include "cylink.h" -#include "ctk_endian.h" -#include "c_asm.h" -#include "port_after.h" - - -/**************************************************************************** -* NAME: void RShiftL( ord *X, -* u_int32_t len_X, -* u_int32_t n_bit ) -* -* DESCRIPTION: Shift array to the right by n_bit. -* -* INPUTS: -* PARAMETERS: -* ord *X Pointer to array -* u_int32_t len_X Length of array -* u_int32_t n_bit Number of bits -* OUTPUT: -* PARAMETERS: -* ord *X Pointer to array -* -* RETURN: -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - -void RShiftL_big( ord *X, - u_int32_t len_X, - u_int32_t n_bit ) -{ - -struct BigNum dest; -bnInit(); -bnBegin(&dest); - -dest.ptr = X; -dest.size = len_X; -dest.allocated = len_X; - -bnRShift(&dest,n_bit); - -} - -/**************************************************************************** -* NAME: void LShiftL( ord *X, -* u_int32_t len_X, -* u_int32_t n_bit ) -* -* DESCRIPTION: Shifts array to the left by n_bit. -* -* INPUTS: -* PARAMETERS: -* ord *X Pointer to array -* u_int32_t len_X Length of array -* u_int32_t n_bit Number of bits -* OUTPUT: -* PARAMETERS: -* ord *X Pointer to array -* -* RETURN: -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - -void LShiftL_big( ord *X, - u_int32_t len_X, - u_int32_t n_bit ) -{ -struct BigNum dest; -bnInit(); -bnBegin(&dest); - -dest.ptr = X; -dest.size = len_X; -dest.allocated = len_X; - -bnLShift(&dest,n_bit); -} - -/************9**************************************************************** -* NAME: int RShiftMostBit( ord *a, -* u_int32_t len ) -* -* DESCRIPTION: Find a least significant non zero bit -* and sfift array to the right -* -* INPUTS: -* PARAMETERS: -* ord *a Pointer to array -* u_int32_t len Number of elements in number -* OUTPUT: -* -* RETURN: -* Number of shifted bits -* -* REVISION HISTORY: -* -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - -int RShiftMostBit( ord *a, - u_int32_t len ) -{ - -struct BigNum n; -bnInit(); -bnBegin(&n); - -n.size = len; -n.ptr = a; -n.allocated = len; - -return (bnMakeOdd(&n)); - -} - - -/**************************************************************************** -* NAME: void ByteLong (uchar *X, u_int32_t X_bytes, -* u_int32_t *Y ) -* -* -* DESCRIPTION: Transfer bytes to u_int32_t. -* -* INPUTS: -* PARAMETERS: -* uchar *X Pointer to byte array -* u_int32_t X_bytes Number of bytes in array -* OUTPUT: -* PARAMETERS: -* u_int32_t *Y Pointer to long arrray -* -* RETURN: -* -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - -void ByteLong( uchar *X, - u_int32_t X_bytes, - u_int32_t *Y ) -{ - u_int32_t i, j; /* counters */ - for ( i = 0, j = 0; j < X_bytes; i++, j += 4) - { - Y[i] = ( (u_int32_t)X[j] ) | ( ((u_int32_t)X[j+1]) << 8 ) | - ( ((u_int32_t)X[j+2]) << 16 ) | ( ((u_int32_t)X[j+3]) << 24 ); - } -} - -/**************************************************************************** -* NAME: void ByteOrd (uchar *X, u_int32_t X_bytes, -* ord *Y ) -* -* -* DESCRIPTION: Transfer bytes to ord. -* -* INPUTS: -* PARAMETERS: -* uchar *X Pointer to byte array -* u_int32_t X_bytes Number of bytes in array -* OUTPUT: -* PARAMETERS: -* ord *Y Pointer to long array -* -* RETURN: -* -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - -void ByteOrd( uchar *X, - u_int32_t X_bytes, - ord *Y ) -{ - u_int32_t i, j; /* counters */ - for ( i = 0, j = 0; j < X_bytes; i++, j += sizeof(ord)) - { - Y[i] = ( (ord)X[j] ) | ( ((ord)X[j+1]) << 8 ) -#ifdef ORD_32 - | ( ((ord)X[j+2]) << 16 ) | ( ((ord)X[j+3]) << 24 ) -#endif - ; - } -} - -/**************************************************************************** -* NAME: void OrdByte (ord *X, u_int32_t X_bytes, -* uchar *Y ) -* -* -* DESCRIPTION: Transfer ord to bytes. -* -* INPUTS: -* PARAMETERS: -* ord *X Pointer to ord array -* u_int32_t X_bytes Number of bytes in array -* OUTPUT: -* PARAMETERS: -* uchar *Y Pointer to byte array -* -* RETURN: -* -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - -void OrdByte( ord *X, - u_int32_t X_bytes, - uchar *Y ) -{ - u_int32_t i, j; /* counters */ - for ( i=0, j=0; j < X_bytes; i++, j += sizeof(ord)) - { - Y[j] = (uchar ) ( X[i] & 0xff ); - Y[j+1] = (uchar)( (X[i] >> 8) & 0xff ); -#ifdef ORD_32 - Y[j+2] = (uchar)( (X[i] >> 16) & 0xff ); - Y[j+3] = (uchar)( (X[i] >> 24) & 0xff ); -#endif - } -} - -/**************************************************************************** -* NAME: void LongByte( u_int32_t *X, -* u_int32_t X_bytes, -* uchar *Y ) -* -* DESCRIPTION: Transfer u_int32_t to bytes. -* -* INPUTS: -* PARAMETERS: -* u_int32_t *X Pointer to long array -* u_int32_t X_bytes Number of longs in array -* OUTPUT: -* PARAMETERS: -* uchar *Y Pointer to bytes array -* -* RETURN: -* -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - -void LongByte( u_int32_t *X, - u_int32_t X_bytes, - uchar *Y ) -{ - u_int32_t i, j; /* counters */ - for ( i=0, j=0; j < X_bytes; i++, j += 4) - { - Y[j] = (uchar ) ( X[i] & 0xff ); - Y[j+1] = (uchar)( (X[i] >> 8) & 0xff ); - Y[j+2] = (uchar)( (X[i] >> 16) & 0xff ); - Y[j+3] = (uchar)( (X[i] >> 24) & 0xff ); - } -} - - diff --git a/usr/src/lib/libresolv2/common/cylink/bn.c b/usr/src/lib/libresolv2/common/cylink/bn.c deleted file mode 100644 index 8825e1dba6..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/bn.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * bn.c - the high-level bignum interface - * - * Copyright (c) 1995 Colin Plumb. All rights reserved. - * For licensing and other legal details, see the file legal.c. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "port_before.h" -#include "bn.h" -#include "port_after.h" - -/* Functions */ -void -bnBegin(struct BigNum *bn) -{ - static int bninit = 0; - - if (!bninit) { - bnInit(); - bninit = 1; - } - - bn->ptr = 0; - bn->size = 0; - bn->allocated = 0; -} - -void -bnSwap(struct BigNum *a, struct BigNum *b) -{ - void *p; - unsigned t; - - p = a->ptr; - a->ptr = b->ptr; - b->ptr = p; - - t = a->size; - a->size = b->size; - b->size = t; - - t = a->allocated; - a->allocated = b->allocated; - b->allocated = t; -} - -void (*bnEnd)(struct BigNum *bn); -int (*bnPrealloc)(struct BigNum *bn, unsigned bits); -int (*bnCopy)(struct BigNum *dest, struct BigNum const *src); -void (*bnNorm)(struct BigNum *bn); -void (*bnExtractBigBytes)(struct BigNum const *bn, unsigned char *dest, - unsigned lsbyte, unsigned len); -int (*bnInsertBigBytes)(struct BigNum *bn, unsigned char const *src, - unsigned lsbyte, unsigned len); -void (*bnExtractLittleBytes)(struct BigNum const *bn, unsigned char *dest, - unsigned lsbyte, unsigned len); -int (*bnInsertLittleBytes)(struct BigNum *bn, unsigned char const *src, - unsigned lsbyte, unsigned len); -unsigned (*bnLSWord)(struct BigNum const *src); -unsigned (*bnBits)(struct BigNum const *src); -int (*bnAdd)(struct BigNum *dest, struct BigNum const *src); -int (*bnSub)(struct BigNum *dest, struct BigNum const *src); -int (*bnCmpQ)(struct BigNum const *a, unsigned b); -int (*bnSetQ)(struct BigNum *dest, unsigned src); -int (*bnAddQ)(struct BigNum *dest, unsigned src); -int (*bnSubQ)(struct BigNum *dest, unsigned src); -int (*bnCmp)(struct BigNum const *a, struct BigNum const *b); -int (*bnSquare)(struct BigNum *dest, struct BigNum const *src); -int (*bnMul)(struct BigNum *dest, struct BigNum const *a, - struct BigNum const *b); -int (*bnMulQ)(struct BigNum *dest, struct BigNum const *a, unsigned b); -int (*bnDivMod)(struct BigNum *q, struct BigNum *r, struct BigNum const *n, - struct BigNum const *d); -int (*bnMod)(struct BigNum *dest, struct BigNum const *src, - struct BigNum const *d); -unsigned (*bnModQ)(struct BigNum const *src, unsigned d); -int (*bnExpMod)(struct BigNum *result, struct BigNum const *n, - struct BigNum const *exp, struct BigNum const *mod); -int (*bnDoubleExpMod)(struct BigNum *dest, - struct BigNum const *n1, struct BigNum const *e1, - struct BigNum const *n2, struct BigNum const *e2, - struct BigNum const *mod); -int (*bnTwoExpMod)(struct BigNum *n, struct BigNum const *exp, - struct BigNum const *mod); -int (*bnGcd)(struct BigNum *dest, struct BigNum const *a, - struct BigNum const *b); -int (*bnInv)(struct BigNum *dest, struct BigNum const *src, - struct BigNum const *mod); -int (*bnLShift)(struct BigNum *dest, unsigned amt); -void (*bnRShift)(struct BigNum *dest, unsigned amt); -unsigned (*bnMakeOdd)(struct BigNum *n); diff --git a/usr/src/lib/libresolv2/common/cylink/bn.h b/usr/src/lib/libresolv2/common/cylink/bn.h deleted file mode 100644 index 9246388117..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/bn.h +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * bn.h - the interface to the bignum routines. - * All functions which return ints can potentially allocate memory - * and return -1 if they are unable to. All "const" arguments - * are unmodified. - * - * This is not particularly asymmetric, as some operations are of the - * form a = b @ c, while others do a @= b. In general, outputs may not - * point to the same struct BigNums as inputs, except as specified - * below. This relationship is referred to as "being the same as". - * This is not numerical equivalence. - * - * The "Q" operations take "unsigned" inputs. Higher values of the - * extra input may work on some implementations, but 65535 is the - * highest portable value. Just because UNSIGNED_MAX is larger than - * that, or you know that the word size of the library is larger than that, - * that, does *not* mean it's allowed. - */ -#ifndef BN_H -#define BN_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -struct BigNum { - void *ptr; - unsigned size; /* Note: in (variable-sized) words */ - unsigned allocated; -}; - -/* Functions */ - -/* - * You usually never have to call this function explicitly, as - * bnBegin() takes care of it. If the program jumps to address 0, - * this function has bot been called. - */ -void bnInit(void); - -/* - * This initializes an empty struct BigNum to a zero value. - * Do not use this on a BigNum which has had a value stored in it! - */ -void bnBegin(struct BigNum *bn); - -/* Swap two BigNums. Cheap. */ -void bnSwap(struct BigNum *a, struct BigNum *b); - -/* Reset an initialized bigNum to empty, pending deallocation. */ -extern void (*bnEnd)(struct BigNum *bn); - -/* - * If you know you'll need space in the number soon, you can use this function - * to ensure that there is room for at least "bits" bits. Optional. - * Returns <0 on out of memory, but the value is unaffected. - */ -extern int (*bnPrealloc)(struct BigNum *bn, unsigned bits); - -/* Hopefully obvious. dest = src. dest may be the same as src. */ -extern int (*bnCopy)(struct BigNum *dest, struct BigNum const *src); - -/* - * Mostly done automatically, but this removes leading zero words from - * the internal representation of the BigNum. Use is unclear. - */ -extern void (*bnNorm)(struct BigNum *bn); - -/* - * Move bytes between the given buffer and the given BigNum encoded in - * base 256. I.e. after either of these, the buffer will be equal to - * (bn / 256^lsbyte) % 256^len. The difference is which is altered to - * match the other! - */ -extern void (*bnExtractBigBytes)(struct BigNum const *bn, - unsigned char *dest, unsigned lsbyte, unsigned len); -extern int (*bnInsertBigBytes)(struct BigNum *bn, unsigned char const *src, - unsigned lsbyte, unsigned len); - -/* The same, but the buffer is little-endian. */ -extern void (*bnExtractLittleBytes)(struct BigNum const *bn, - unsigned char *dest, unsigned lsbyte, unsigned len); -extern int (*bnInsertLittleBytes)(struct BigNum *bn, unsigned char const *src, - unsigned lsbyte, unsigned len); - -/* Return the least-significant bits (at least 16) of the BigNum */ -extern unsigned (*bnLSWord)(struct BigNum const *src); - -/* - * Return the number of significant bits in the BigNum. - * 0 or 1+floor(log2(src)) - */ -extern unsigned (*bnBits)(struct BigNum const *src); - -/* - * dest += src. dest and src may be the same. Guaranteed not to - * allocate memory unnecessarily, so if you're sure bnBits(dest) - * won't change, you don't need to check the return value. - */ -extern int (*bnAdd)(struct BigNum *dest, struct BigNum const *src); - -/* - * dest -= src. dest and src may be the same, but bnSetQ(dest, 0) is faster. - * if dest < src, returns +1 and sets dest = src-dest. - */ -extern int (*bnSub)(struct BigNum *dest, struct BigNum const *src); - -/* Return sign (-1, 0, +1) of a-b. a <=> b --> bnCmpQ(a, b) <=> 0 */ -extern int (*bnCmpQ)(struct BigNum const *a, unsigned b); - -/* dest = src, where 0 <= src < 2^16. */ -extern int (*bnSetQ)(struct BigNum *dest, unsigned src); - -/* dest += src, where 0 <= src < 2^16 */ -extern int (*bnAddQ)(struct BigNum *dest, unsigned src); - -/* dest -= src, where 0 <= src < 2^16 */ -extern int (*bnSubQ)(struct BigNum *dest, unsigned src); - -/* Return sign (-1, 0, +1) of a-b. a <=> b --> bnCmp(a, b) <=> 0 */ -extern int (*bnCmp)(struct BigNum const *a, struct BigNum const *b); - -/* dest = src^2. dest may be the same as src, but it costs time. */ -extern int (*bnSquare)(struct BigNum *dest, struct BigNum const *src); - -/* dest = a * b. dest may be the same as a or b, but it costs time. */ -extern int (*bnMul)(struct BigNum *dest, struct BigNum const *a, - struct BigNum const *b); - -/* dest = a * b, where 0 <= b < 2^16. dest and a may be the same. */ -extern int (*bnMulQ)(struct BigNum *dest, struct BigNum const *a, unsigned b); - -/* - * q = n/d, r = n%d. r may be the same as n, but not d, - * and q may not be the same as n or d. - * re-entrancy issue: this temporarily modifies d, but restores - * it for return. - */ -extern int (*bnDivMod)(struct BigNum *q, struct BigNum *r, - struct BigNum const *n, struct BigNum const *d); -/* - * dest = src % d. dest and src may be the same, but not dest and d. - * re-entrancy issue: this temporarily modifies d, but restores - * it for return. - */ -extern int (*bnMod)(struct BigNum *dest, struct BigNum const *src, - struct BigNum const *d); - -/* return src % d, where 0 <= d < 2^16. */ -extern unsigned int (*bnModQ)(struct BigNum const *src, unsigned d); - -/* n = n^exp, modulo "mod" "mod" *must* be odd */ -extern int (*bnExpMod)(struct BigNum *result, struct BigNum const *n, - struct BigNum const *exp, struct BigNum const *mod); - -/* - * dest = n1^e1 * n2^e2, modulo "mod". "mod" *must* be odd. - * dest may be the same as n1 or n2. - */ -extern int (*bnDoubleExpMod)(struct BigNum *dest, - struct BigNum const *n1, struct BigNum const *e1, - struct BigNum const *n2, struct BigNum const *e2, - struct BigNum const *mod); - -/* n = 2^exp, modulo "mod" "mod" *must* be odd */ -extern int (*bnTwoExpMod)(struct BigNum *n, struct BigNum const *exp, - struct BigNum const *mod); - -/* dest = gcd(a, b). The inputs may overlap arbitrarily. */ -extern int (*bnGcd)(struct BigNum *dest, struct BigNum const *a, - struct BigNum const *b); - -/* dest = src^-1, modulo "mod". dest may be the same as src. */ -extern int (*bnInv)(struct BigNum *dest, struct BigNum const *src, - struct BigNum const *mod); - -/* Shift dest left "amt" places */ -extern int (*bnLShift)(struct BigNum *dest, unsigned amt); -/* Shift dest right "amt" places, discarding low-order bits */ -extern void (*bnRShift)(struct BigNum *dest, unsigned amt); - -/* For the largest 2^k that divides n, divide n by it and return k. */ -extern unsigned (*bnMakeOdd)(struct BigNum *n); - -#endif/* !BN_H */ diff --git a/usr/src/lib/libresolv2/common/cylink/bn00.c b/usr/src/lib/libresolv2/common/cylink/bn00.c deleted file mode 100644 index affc76dc64..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/bn00.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2001 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * bn00.c - auto-size-detecting bn??.c file. - * - * Written in 1995 by Colin Plumb. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "port_before.h" -#include "bnsize00.h" - - -#if BNSIZE64 - -/* Include all of the C source file by reference */ -#include "bn64.c" -#include "bninit64.c" - -#elif BNSIZE32 - -/* Include all of the C source file by reference */ -#include "bn32.c" -#include "bninit32.c" - -#else /* BNSIZE16 */ - -/* Include all of the C source file by reference */ -#include "bn16.c" -#include "bninit16.c" - -#endif diff --git a/usr/src/lib/libresolv2/common/cylink/bn16.c b/usr/src/lib/libresolv2/common/cylink/bn16.c deleted file mode 100644 index 3afa8f4751..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/bn16.c +++ /dev/null @@ -1,956 +0,0 @@ -/* - * Copyright (c) 2001 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * bn16.c - the high-level bignum interface - * - * Like lbn16.c, this reserves the string "16" for textual replacement. - * The string must not appear anywhere unless it is intended to be replaced - * to generate other bignum interface functions. - * - * Copyright (c) 1995 Colin Plumb. All rights reserved. - * For licensing and other legal details, see the file legal.c. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifndef HAVE_CONFIG_H -#define HAVE_CONFIG_H 0 -#endif -#if HAVE_CONFIG_H -#include "config.h" -#endif - -/* - * Some compilers complain about #if FOO if FOO isn't defined, - * so do the ANSI-mandated thing explicitly... - */ -#ifndef NO_ASSERT_H -#define NO_ASSERT_H 0 -#endif -#ifndef NO_STRING_H -#define NO_STRING_H 0 -#endif -#ifndef HAVE_STRINGS_H -#define HAVE_STRINGS_H 0 -#endif -#ifndef NEED_MEMORY_H -#define NEED_MEMORY_H 0 -#endif - -#if !NO_ASSERT_H -#include <assert.h> -#else -#define assert(x) (void)0 -#endif - -#if !NO_STRING_H -#include <string.h> /* for memmove() in bnMakeOdd */ -#elif HAVE_STRINGS_H -#include <strings.h> -#endif -#if NEED_MEMORY_H -#include <memory.h> -#endif - -/* - * This was useful during debugging, so it's left in here. - * You can ignore it. DBMALLOC is generally undefined. - */ -#ifndef DBMALLOC -#define DBAMLLOC 0 -#endif -#if DBMALLOC -#include "../dbmalloc/malloc.h" -#define MALLOCDB malloc_chain_check(1) -#else -#define MALLOCDB (void)0 -#endif - -#include "lbn.h" -#include "lbn16.h" -#include "lbnmem.h" -#include "bn16.h" -#include "bn.h" - -/* Work-arounds for some particularly broken systems */ -#include "kludge.h" /* For memmove() */ -#include <port_after.h> - -/* Functions */ -void -bnInit_16(void) -{ - bnEnd = bnEnd_16; - bnPrealloc = bnPrealloc_16; - bnCopy = bnCopy_16; - bnNorm = bnNorm_16; - bnExtractBigBytes = bnExtractBigBytes_16; - bnInsertBigBytes = bnInsertBigBytes_16; - bnExtractLittleBytes = bnExtractLittleBytes_16; - bnInsertLittleBytes = bnInsertLittleBytes_16; - bnLSWord = bnLSWord_16; - bnBits = bnBits_16; - bnAdd = bnAdd_16; - bnSub = bnSub_16; - bnCmpQ = bnCmpQ_16; - bnSetQ = bnSetQ_16; - bnAddQ = bnAddQ_16; - bnSubQ = bnSubQ_16; - bnCmp = bnCmp_16; - bnSquare = bnSquare_16; - bnMul = bnMul_16; - bnMulQ = bnMulQ_16; - bnDivMod = bnDivMod_16; - bnMod = bnMod_16; - bnModQ = bnModQ_16; - bnExpMod = bnExpMod_16; - bnDoubleExpMod = bnDoubleExpMod_16; - bnTwoExpMod = bnTwoExpMod_16; - bnGcd = bnGcd_16; - bnInv = bnInv_16; - bnLShift = bnLShift_16; - bnRShift = bnRShift_16; - bnMakeOdd = bnMakeOdd_16; -} - -void -bnEnd_16(struct BigNum *bn) -{ - if (bn->ptr) { - LBNFREE((BNWORD16 *)bn->ptr, bn->allocated); - bn->ptr = 0; - } - bn->size = 0; - bn->allocated = 0; - - MALLOCDB; -} - -/* Internal function. It operates in words. */ -static int -bnResize_16(struct BigNum *bn, unsigned len) -{ - void *p; - - /* Round size up: most mallocs impose 8-byte granularity anyway */ - len = (len + (8/sizeof(BNWORD16) - 1)) & ~(8/sizeof(BNWORD16) - 1); - p = LBNREALLOC((BNWORD16 *)bn->ptr, bn->allocated, len); - if (!p) - return -1; - bn->ptr = p; - bn->allocated = len; - - MALLOCDB; - - return 0; -} - -#define bnSizeCheck(bn, size) \ - if (bn->allocated < size && bnResize_16(bn, size) < 0) \ - return -1 - -int -bnPrealloc_16(struct BigNum *bn, unsigned bits) -{ - bits = (bits + 16-1)/16; - bnSizeCheck(bn, bits); - MALLOCDB; - return 0; -} - -int -bnCopy_16(struct BigNum *dest, struct BigNum const *src) -{ - bnSizeCheck(dest, src->size); - dest->size = src->size; - lbnCopy_16((BNWORD16 *)dest->ptr, (BNWORD16 *)src->ptr, src->size); - MALLOCDB; - return 0; -} - -void -bnNorm_16(struct BigNum *bn) -{ - bn->size = lbnNorm_16((BNWORD16 *)bn->ptr, bn->size); -} - -/* - * Convert a bignum to big-endian bytes. Returns, in big-endian form, a - * substring of the bignum starting from lsbyte and "len" bytes long. - * Unused high-order (leading) bytes are filled with 0. - */ -void -bnExtractBigBytes_16(struct BigNum const *bn, unsigned char *dest, - unsigned lsbyte, unsigned len) -{ - unsigned s = bn->size * (16 / 8); - - /* Fill unused leading bytes with 0 */ - while (s < lsbyte+len) { - *dest++ = 0; - len--; - } - - if (len) - lbnExtractBigBytes_16((BNWORD16 *)bn->ptr, dest, lsbyte, len); - MALLOCDB; -} - -int -bnInsertBigBytes_16(struct BigNum *bn, unsigned char const *src, - unsigned lsbyte, unsigned len) -{ - unsigned s = bn->size; - unsigned words = (len+lsbyte+sizeof(BNWORD16)-1) / sizeof(BNWORD16); - - /* Pad with zeros as required */ - bnSizeCheck(bn, words); - - if (s < words) { - lbnZero_16((BNWORD16 *)bn->ptr BIGLITTLE(-s,+s), words-s); - s = words; - } - - lbnInsertBigBytes_16((BNWORD16 *)bn->ptr, src, lsbyte, len); - - bn->size = lbnNorm_16((BNWORD16 *)bn->ptr, s); - - MALLOCDB; - return 0; -} - - -/* - * Convert a bignum to little-endian bytes. Returns, in little-endian form, a - * substring of the bignum starting from lsbyte and "len" bytes long. - * Unused high-order (trailing) bytes are filled with 0. - */ -void -bnExtractLittleBytes_16(struct BigNum const *bn, unsigned char *dest, - unsigned lsbyte, unsigned len) -{ - unsigned s = bn->size * (16 / 8); - - /* Fill unused leading bytes with 0 */ - while (s < lsbyte+len) - dest[--len] = 0; - - if (len) - lbnExtractLittleBytes_16((BNWORD16 *)bn->ptr, dest, - lsbyte, len); - MALLOCDB; -} - -int -bnInsertLittleBytes_16(struct BigNum *bn, unsigned char const *src, - unsigned lsbyte, unsigned len) -{ - unsigned s = bn->size; - unsigned words = (len+lsbyte+sizeof(BNWORD16)-1) / sizeof(BNWORD16); - - /* Pad with zeros as required */ - bnSizeCheck(bn, words); - - if (s < words) { - lbnZero_16((BNWORD16 *)bn->ptr BIGLITTLE(-s,+s), words-s); - s = words; - } - - lbnInsertLittleBytes_16((BNWORD16 *)bn->ptr, src, lsbyte, len); - - bn->size = lbnNorm_16((BNWORD16 *)bn->ptr, s); - - MALLOCDB; - return 0; -} - -/* Return the least-significant word of the input. */ -unsigned -bnLSWord_16(struct BigNum const *src) -{ - return src->size ? (unsigned)((BNWORD16 *)src->ptr)[BIGLITTLE(-1,0)]: 0; -} - -unsigned -bnBits_16(struct BigNum const *src) -{ - return lbnBits_16((BNWORD16 *)src->ptr, src->size); -} - -int -bnAdd_16(struct BigNum *dest, struct BigNum const *src) -{ - unsigned s = src->size, d = dest->size; - BNWORD16 t; - - if (!s) - return 0; - - bnSizeCheck(dest, s); - - if (d < s) { - lbnZero_16((BNWORD16 *)dest->ptr BIGLITTLE(-d,+d), s-d); - dest->size = d = s; - MALLOCDB; - } - t = lbnAddN_16((BNWORD16 *)dest->ptr, (BNWORD16 *)src->ptr, s); - MALLOCDB; - if (t) { - if (d > s) { - t = lbnAdd1_16((BNWORD16 *)dest->ptr BIGLITTLE(-s,+s), - d-s, t); - MALLOCDB; - } - if (t) { - bnSizeCheck(dest, d+1); - ((BNWORD16 *)dest->ptr)[BIGLITTLE(-1-d,d)] = t; - dest->size = d+1; - } - } - return 0; -} - -/* - * dest -= src. - * If dest goes negative, this produces the absolute value of - * the difference (the negative of the true value) and returns 1. - * Otherwise, it returls 0. - */ -int -bnSub_16(struct BigNum *dest, struct BigNum const *src) -{ - unsigned s = src->size, d = dest->size; - BNWORD16 t; - - if (d < s && d < (s = lbnNorm_16((BNWORD16 *)src->ptr, s))) { - bnSizeCheck(dest, s); - lbnZero_16((BNWORD16 *)dest->ptr BIGLITTLE(-d,+d), s-d); - dest->size = d = s; - MALLOCDB; - } - if (!s) - return 0; - t = lbnSubN_16((BNWORD16 *)dest->ptr, (BNWORD16 *)src->ptr, s); - MALLOCDB; - if (t) { - if (d > s) { - t = lbnSub1_16((BNWORD16 *)dest->ptr BIGLITTLE(-s,+s), - d-s, t); - MALLOCDB; - } - if (t) { - lbnNeg_16((BNWORD16 *)dest->ptr, d); - dest->size = lbnNorm_16((BNWORD16 *)dest->ptr, - dest->size); - MALLOCDB; - return 1; - } - } - dest->size = lbnNorm_16((BNWORD16 *)dest->ptr, dest->size); - return 0; -} - -/* - * Compare the BigNum to the given value, which must be < 65536. - * Returns -1. 0 or 1 if a<b, a == b or a>b. - * a <=> b --> bnCmpQ(a,b) <=> 0 - */ -int -bnCmpQ_16(struct BigNum const *a, unsigned b) -{ - unsigned t; - BNWORD16 v; - - t = lbnNorm_16((BNWORD16 *)a->ptr, a->size); - /* If a is more than one word long or zero, it's easy... */ - if (t != 1) - return (t > 1) ? 1 : (b ? -1 : 0); - v = (unsigned)((BNWORD16 *)a->ptr)[BIGLITTLE(-1,0)]; - return (v > b) ? 1 : ((v < b) ? -1 : 0); -} - -int -bnSetQ_16(struct BigNum *dest, unsigned src) -{ - if (src) { - bnSizeCheck(dest, 1); - - ((BNWORD16 *)dest->ptr)[BIGLITTLE(-1,0)] = (BNWORD16)src; - dest->size = 1; - } else { - dest->size = 0; - } - return 0; -} - -int -bnAddQ_16(struct BigNum *dest, unsigned src) -{ - BNWORD16 t; - - if (!dest->size) - return bnSetQ(dest, src); - - t = lbnAdd1_16((BNWORD16 *)dest->ptr, dest->size, (BNWORD16)src); - MALLOCDB; - if (t) { - src = dest->size; - bnSizeCheck(dest, src+1); - ((BNWORD16 *)dest->ptr)[BIGLITTLE(-1-src,src)] = t; - dest->size = src+1; - } - return 0; -} - -/* - * Return value as for bnSub: 1 if subtract underflowed, in which - * case the return is the negative of the computed value. - */ -int -bnSubQ_16(struct BigNum *dest, unsigned src) -{ - BNWORD16 t; - - if (!dest->size) - return bnSetQ(dest, src) < 0 ? -1 : (src != 0); - - t = lbnSub1_16((BNWORD16 *)dest->ptr, dest->size, (BNWORD16)src); - MALLOCDB; - if (t) { - /* Underflow. <= 1 word, so do it simply. */ - lbnNeg_16((BNWORD16 *)dest->ptr, 1); - dest->size = 1; - return 1; - } -/* Try to normalize? Needing this is going to be very rare. */ -/* dest->size = lbnNorm_16((BNWORD16 *)dest->ptr, dest->size); */ - return 0; -} - -/* - * Compare two BigNums. Returns -1. 0 or 1 if a<b, a == b or a>b. - * a <=> b --> bnCmp(a,b) <=> 0 - */ -int -bnCmp_16(struct BigNum const *a, struct BigNum const *b) -{ - unsigned s, t; - - s = lbnNorm_16((BNWORD16 *)a->ptr, a->size); - t = lbnNorm_16((BNWORD16 *)b->ptr, b->size); - - if (s != t) - return s > t ? 1 : -1; - return lbnCmp_16((BNWORD16 *)a->ptr, (BNWORD16 *)b->ptr, s); -} - -int -bnSquare_16(struct BigNum *dest, struct BigNum const *src) -{ - unsigned s; - BNWORD16 *srcbuf; - - s = lbnNorm_16((BNWORD16 *)src->ptr, src->size); - if (!s) { - dest->size = 0; - return 0; - } - bnSizeCheck(dest, 2*s); - - if (src == dest) { - LBNALLOC(srcbuf, s); - if (!srcbuf) - return -1; - lbnCopy_16(srcbuf, (BNWORD16 *)src->ptr, s); - lbnSquare_16((BNWORD16 *)dest->ptr, (BNWORD16 *)srcbuf, s); - LBNFREE(srcbuf, s); - } else { - lbnSquare_16((BNWORD16 *)dest->ptr, (BNWORD16 *)src->ptr, s); - } - - dest->size = lbnNorm_16((BNWORD16 *)dest->ptr, 2*s); - MALLOCDB; - return 0; -} - -int -bnMul_16(struct BigNum *dest, struct BigNum const *a, struct BigNum const *b) -{ - unsigned s, t; - BNWORD16 *srcbuf; - - s = lbnNorm_16((BNWORD16 *)a->ptr, a->size); - t = lbnNorm_16((BNWORD16 *)b->ptr, b->size); - - if (!s || !t) { - dest->size = 0; - return 0; - } - - if (a == b) - return bnSquare_16(dest, a); - - bnSizeCheck(dest, s+t); - - if (dest == a) { - LBNALLOC(srcbuf, s); - if (!srcbuf) - return -1; - lbnCopy_16(srcbuf, (BNWORD16 *)a->ptr, s); - lbnMul_16((BNWORD16 *)dest->ptr, srcbuf, s, - (BNWORD16 *)b->ptr, t); - LBNFREE(srcbuf, s); - } else if (dest == b) { - LBNALLOC(srcbuf, t); - if (!srcbuf) - return -1; - lbnCopy_16(srcbuf, (BNWORD16 *)b->ptr, t); - lbnMul_16((BNWORD16 *)dest->ptr, (BNWORD16 *)a->ptr, s, - srcbuf, t); - LBNFREE(srcbuf, t); - } else { - lbnMul_16((BNWORD16 *)dest->ptr, (BNWORD16 *)a->ptr, s, - (BNWORD16 *)b->ptr, t); - } - dest->size = lbnNorm_16((BNWORD16 *)dest->ptr, s+t); - MALLOCDB; - return 0; -} - -int -bnMulQ_16(struct BigNum *dest, struct BigNum const *a, unsigned b) -{ - unsigned s; - - s = lbnNorm_16((BNWORD16 *)a->ptr, a->size); - if (!s || !b) { - dest->size = 0; - return 0; - } - if (b == 1) - return bnCopy_16(dest, a); - bnSizeCheck(dest, s+1); - lbnMulN1_16((BNWORD16 *)dest->ptr, (BNWORD16 *)a->ptr, s, (BNWORD16)b); - dest->size = lbnNorm_16((BNWORD16 *)dest->ptr, s+1); - MALLOCDB; - return 0; -} - -int -bnDivMod_16(struct BigNum *q, struct BigNum *r, struct BigNum const *n, - struct BigNum const *d) -{ - unsigned dsize, nsize; - BNWORD16 qhigh; - - dsize = lbnNorm_16((BNWORD16 *)d->ptr, d->size); - nsize = lbnNorm_16((BNWORD16 *)n->ptr, n->size); - - if (nsize < dsize) { - q->size = 0; /* No quotient */ - r->size = nsize; - return 0; /* Success */ - } - - bnSizeCheck(q, nsize-dsize); - - if (r != n) { /* You are allowed to reduce in place */ - bnSizeCheck(r, nsize); - lbnCopy_16((BNWORD16 *)r->ptr, (BNWORD16 *)n->ptr, nsize); - } - - qhigh = lbnDiv_16((BNWORD16 *)q->ptr, (BNWORD16 *)r->ptr, nsize, - (BNWORD16 *)d->ptr, dsize); - nsize -= dsize; - if (qhigh) { - bnSizeCheck(q, nsize+1); - *((BNWORD16 *)q->ptr BIGLITTLE(-nsize-1,+nsize)) = qhigh; - q->size = nsize+1; - } else { - q->size = lbnNorm_16((BNWORD16 *)q->ptr, nsize); - } - r->size = lbnNorm_16((BNWORD16 *)r->ptr, dsize); - MALLOCDB; - return 0; -} - -int -bnMod_16(struct BigNum *dest, struct BigNum const *src, struct BigNum const *d) -{ - unsigned dsize, nsize; - - nsize = lbnNorm_16((BNWORD16 *)src->ptr, src->size); - dsize = lbnNorm_16((BNWORD16 *)d->ptr, d->size); - - - if (dest != src) { - bnSizeCheck(dest, nsize); - lbnCopy_16((BNWORD16 *)dest->ptr, (BNWORD16 *)src->ptr, nsize); - } - - if (nsize < dsize) { - dest->size = nsize; /* No quotient */ - return 0; - } - - (void)lbnDiv_16((BNWORD16 *)dest->ptr BIGLITTLE(-dsize,+dsize), - (BNWORD16 *)dest->ptr, nsize, - (BNWORD16 *)d->ptr, dsize); - dest->size = lbnNorm_16((BNWORD16 *)dest->ptr, dsize); - MALLOCDB; - return 0; -} - -unsigned -bnModQ_16(struct BigNum const *src, unsigned d) -{ - unsigned s; - - s = lbnNorm_16((BNWORD16 *)src->ptr, src->size); - if (!s) - return 0; - - return lbnModQ_16((BNWORD16 *)src->ptr, s, d); -} - -int -bnExpMod_16(struct BigNum *dest, struct BigNum const *n, - struct BigNum const *exp, struct BigNum const *mod) -{ - unsigned nsize, esize, msize; - - nsize = lbnNorm_16((BNWORD16 *)n->ptr, n->size); - esize = lbnNorm_16((BNWORD16 *)exp->ptr, exp->size); - msize = lbnNorm_16((BNWORD16 *)mod->ptr, mod->size); - - if (!msize || (((BNWORD16 *)mod->ptr)[BIGLITTLE(-1,0)] & 1) == 0) - return -1; /* Illegal modulus! */ - - bnSizeCheck(dest, msize); - - /* Special-case base of 2 */ - if (nsize == 1 && ((BNWORD16 *)n->ptr)[BIGLITTLE(-1,0)] == 2) { - if (lbnTwoExpMod_16((BNWORD16 *)dest->ptr, - (BNWORD16 *)exp->ptr, esize, - (BNWORD16 *)mod->ptr, msize) < 0) - return -1; - } else { - if (lbnExpMod_16((BNWORD16 *)dest->ptr, - (BNWORD16 *)n->ptr, nsize, - (BNWORD16 *)exp->ptr, esize, - (BNWORD16 *)mod->ptr, msize) < 0) - return -1; - } - - dest->size = lbnNorm_16((BNWORD16 *)dest->ptr, msize); - MALLOCDB; - return 0; -} - -int -bnDoubleExpMod_16(struct BigNum *dest, - struct BigNum const *n1, struct BigNum const *e1, - struct BigNum const *n2, struct BigNum const *e2, - struct BigNum const *mod) -{ - unsigned n1size, e1size, n2size, e2size, msize; - - n1size = lbnNorm_16((BNWORD16 *)n1->ptr, n1->size); - e1size = lbnNorm_16((BNWORD16 *)e1->ptr, e1->size); - n2size = lbnNorm_16((BNWORD16 *)n2->ptr, n2->size); - e2size = lbnNorm_16((BNWORD16 *)e2->ptr, e2->size); - msize = lbnNorm_16((BNWORD16 *)mod->ptr, mod->size); - - if (!msize || (((BNWORD16 *)mod->ptr)[BIGLITTLE(-1,0)] & 1) == 0) - return -1; /* Illegal modulus! */ - - bnSizeCheck(dest, msize); - - if (lbnDoubleExpMod_16((BNWORD16 *)dest->ptr, - (BNWORD16 *)n1->ptr, n1size, (BNWORD16 *)e1->ptr, e1size, - (BNWORD16 *)n2->ptr, n2size, (BNWORD16 *)e2->ptr, e2size, - (BNWORD16 *)mod->ptr, msize) < 0) - return -1; - - dest->size = lbnNorm_16((BNWORD16 *)dest->ptr, msize); - MALLOCDB; - return 0; -} - -int -bnTwoExpMod_16(struct BigNum *n, struct BigNum const *exp, - struct BigNum const *mod) -{ - unsigned esize, msize; - - esize = lbnNorm_16((BNWORD16 *)exp->ptr, exp->size); - msize = lbnNorm_16((BNWORD16 *)mod->ptr, mod->size); - - if (!msize || (((BNWORD16 *)mod->ptr)[BIGLITTLE(-1,0)] & 1) == 0) - return -1; /* Illegal modulus! */ - - bnSizeCheck(n, msize); - - if (lbnTwoExpMod_16((BNWORD16 *)n->ptr, (BNWORD16 *)exp->ptr, esize, - (BNWORD16 *)mod->ptr, msize) < 0) - return -1; - - n->size = lbnNorm_16((BNWORD16 *)n->ptr, msize); - MALLOCDB; - return 0; -} - -int -bnGcd_16(struct BigNum *dest, struct BigNum const *a, struct BigNum const *b) -{ - BNWORD16 *tmp; - unsigned asize, bsize; - int i; - - /* Kind of silly, but we might as well permit it... */ - if (a == b) - return dest == a ? 0 : bnCopy(dest, a); - - /* Ensure a is not the same as "dest" */ - if (a == dest) { - a = b; - b = dest; - } - - asize = lbnNorm_16((BNWORD16 *)a->ptr, a->size); - bsize = lbnNorm_16((BNWORD16 *)b->ptr, b->size); - - bnSizeCheck(dest, bsize+1); - - /* Copy a to tmp */ - LBNALLOC(tmp, asize+1); - if (!tmp) - return -1; - lbnCopy_16(tmp, (BNWORD16 *)a->ptr, asize); - - /* Copy b to dest,if necessary */ - if (dest != b) - lbnCopy_16((BNWORD16 *)dest->ptr, - (BNWORD16 *)b->ptr, bsize); - if (bsize > asize || (bsize == asize && - lbnCmp_16((BNWORD16 *)b->ptr, (BNWORD16 *)a->ptr, asize) > 0)) - { - i = lbnGcd_16((BNWORD16 *)dest->ptr, bsize, tmp, asize); - if (i >= 0) { - dest->size = (unsigned)i; - } else { - lbnCopy_16((BNWORD16 *)dest->ptr, tmp, - (unsigned)-i); - dest->size = (unsigned)-i; - } - } else { - i = lbnGcd_16(tmp, asize, (BNWORD16 *)dest->ptr, bsize); - if (i <= 0) { - dest->size = (unsigned)-i; - } else { - lbnCopy_16((BNWORD16 *)dest->ptr, tmp, - (unsigned)i); - dest->size = (unsigned)i; - } - } - LBNFREE(tmp, asize+1); - MALLOCDB; - return 0; -} - -int -bnInv_16(struct BigNum *dest, struct BigNum const *src, - struct BigNum const *mod) -{ - unsigned s, m; - int i; - - s = lbnNorm_16((BNWORD16 *)src->ptr, src->size); - m = lbnNorm_16((BNWORD16 *)mod->ptr, mod->size); - - /* lbnInv_16 requires that the input be less than the modulus */ - if (m < s || - (m==s && lbnCmp_16((BNWORD16 *)src->ptr, (BNWORD16 *)mod->ptr, s))) - { - bnSizeCheck(dest, s + (m==s)); - if (dest != src) - lbnCopy_16((BNWORD16 *)dest->ptr, - (BNWORD16 *)src->ptr, s); - /* Pre-reduce modulo the modulus */ - (void)lbnDiv_16((BNWORD16 *)dest->ptr BIGLITTLE(-m,+m), - (BNWORD16 *)dest->ptr, s, - (BNWORD16 *)mod->ptr, m); - s = lbnNorm_16((BNWORD16 *)dest->ptr, m); - MALLOCDB; - } else { - bnSizeCheck(dest, m+1); - if (dest != src) - lbnCopy_16((BNWORD16 *)dest->ptr, - (BNWORD16 *)src->ptr, s); - } - - i = lbnInv_16((BNWORD16 *)dest->ptr, s, (BNWORD16 *)mod->ptr, m); - if (i == 0) - dest->size = lbnNorm_16((BNWORD16 *)dest->ptr, m); - - MALLOCDB; - return i; -} - -/* - * Shift a bignum left the appropriate number of bits, - * multiplying by 2^amt. - */ -int -bnLShift_16(struct BigNum *dest, unsigned amt) -{ - unsigned s = dest->size; - BNWORD16 carry; - - if (amt % 16) { - carry = lbnLshift_16(dest->ptr, s, amt % 16); - if (carry) { - s++; - bnSizeCheck(dest, s); - ((BNWORD16 *)dest->ptr)[BIGLITTLE(-s,s-1)] = carry; - } - } - - amt /= 16; - if (amt) { - bnSizeCheck(dest, s+amt); - memmove((BNWORD16 *)dest->ptr BIGLITTLE(-s-amt, +amt), - (BNWORD16 *)dest->ptr BIG(-s), - s * sizeof(BNWORD16)); - lbnZero_16((BNWORD16 *)dest->ptr, amt); - s += amt; - } - dest->size = s; - MALLOCDB; - return 0; -} - -/* - * Shift a bignum right the appropriate number of bits, - * dividing by 2^amt. - */ -void bnRShift_16(struct BigNum *dest, unsigned amt) -{ - unsigned s = dest->size; - - if (amt >= 16) { - memmove( - (BNWORD16 *)dest->ptr BIG(-s+amt/16), - (BNWORD16 *)dest->ptr BIGLITTLE(-s, +amt/16), - s-amt/16 * sizeof(BNWORD16)); - s -= amt/16; - amt %= 16; - } - - if (amt) - (void)lbnRshift_16(dest->ptr, s, amt); - - dest->size = lbnNorm_16(dest->ptr, s); - MALLOCDB; -} - -/* - * Shift a bignum right until it is odd, and return the number of - * bits shifted. n = d * 2^s. Replaces n with d and returns s. - * Returns 0 when given 0. (Another valid answer is infinity.) - */ -unsigned -bnMakeOdd_16(struct BigNum *n) -{ - unsigned size; - unsigned s; /* shift amount */ - BNWORD16 *p; - BNWORD16 t; - - p = (BNWORD16 *)n->ptr; - size = lbnNorm_16(p, n->size); - if (!size) - return 0; - - t = BIGLITTLE(p[-1],p[0]); - s = 0; - - /* See how many words we have to shift */ - if (!t) { - /* Shift by words */ - do { - - s++; - BIGLITTLE(--p,p++); - } while ((t = BIGLITTLE(p[-1],p[0])) == 0); - size -= s; - s *= 16; - memmove((BNWORD16 *)n->ptr BIG(-size), p BIG(-size), - size * sizeof(BNWORD16)); - p = (BNWORD16 *)n->ptr; - MALLOCDB; - } - - assert(t); - - /* Now count the bits */ - while ((t & 1) == 0) { - t >>= 1; - s++; - } - - /* Shift the bits */ - if (s & (16-1)) { - lbnRshift_16(p, size, s & (16-1)); - /* Renormalize */ - if (BIGLITTLE(*(p-size),*(p+(size-1))) == 0) - --size; - } - n->size = size; - - MALLOCDB; - return s; -} diff --git a/usr/src/lib/libresolv2/common/cylink/bn16.h b/usr/src/lib/libresolv2/common/cylink/bn16.h deleted file mode 100644 index 8f8402534e..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/bn16.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * bn16.h - interface to 16-bit bignum routines. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -struct BigNum; - -void bnInit_16(void); -void bnEnd_16(struct BigNum *bn); -int bnPrealloc_16(struct BigNum *bn, unsigned bits); -int bnCopy_16(struct BigNum *dest, struct BigNum const *src); -int bnSwap_16(struct BigNum *a, struct BigNum *b); -void bnNorm_16(struct BigNum *bn); -void bnExtractBigBytes_16(struct BigNum const *bn, unsigned char *dest, - unsigned lsbyte, unsigned dlen); -int bnInsertBigBytes_16(struct BigNum *bn, unsigned char const *src, - unsigned lsbyte, unsigned len); -void bnExtractLittleBytes_16(struct BigNum const *bn, unsigned char *dest, - unsigned lsbyte, unsigned dlen); -int bnInsertLittleBytes_16(struct BigNum *bn, unsigned char const *src, - unsigned lsbyte, unsigned len); -unsigned bnLSWord_16(struct BigNum const *src); -unsigned bnBits_16(struct BigNum const *src); -int bnAdd_16(struct BigNum *dest, struct BigNum const *src); -int bnSub_16(struct BigNum *dest, struct BigNum const *src); -int bnCmpQ_16(struct BigNum const *a, unsigned b); -int bnSetQ_16(struct BigNum *dest, unsigned src); -int bnAddQ_16(struct BigNum *dest, unsigned src); -int bnSubQ_16(struct BigNum *dest, unsigned src); -int bnCmp_16(struct BigNum const *a, struct BigNum const *b); -int bnSquare_16(struct BigNum *dest, struct BigNum const *src); -int bnMul_16(struct BigNum *dest, struct BigNum const *a, - struct BigNum const *b); -int bnMulQ_16(struct BigNum *dest, struct BigNum const *a, unsigned b); -int bnDivMod_16(struct BigNum *q, struct BigNum *r, struct BigNum const *n, - struct BigNum const *d); -int bnMod_16(struct BigNum *dest, struct BigNum const *src, - struct BigNum const *d); -unsigned bnModQ_16(struct BigNum const *src, unsigned d); -int bnExpMod_16(struct BigNum *dest, struct BigNum const *n, - struct BigNum const *exp, struct BigNum const *mod); -int bnDoubleExpMod_16(struct BigNum *dest, - struct BigNum const *n1, struct BigNum const *e1, - struct BigNum const *n2, struct BigNum const *e2, - struct BigNum const *mod); -int bnTwoExpMod_16(struct BigNum *n, struct BigNum const *exp, - struct BigNum const *mod); -int bnGcd_16(struct BigNum *dest, struct BigNum const *a, - struct BigNum const *b); -int bnInv_16(struct BigNum *dest, struct BigNum const *src, - struct BigNum const *mod); -int bnLShift_16(struct BigNum *dest, unsigned amt); -void bnRShift_16(struct BigNum *dest, unsigned amt); -unsigned bnMakeOdd_16(struct BigNum *n); diff --git a/usr/src/lib/libresolv2/common/cylink/bn32.c b/usr/src/lib/libresolv2/common/cylink/bn32.c deleted file mode 100644 index 449cb90567..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/bn32.c +++ /dev/null @@ -1,956 +0,0 @@ -/* - * Copyright (c) 2001 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * bn32.c - the high-level bignum interface - * - * Like lbn32.c, this reserves the string "32" for textual replacement. - * The string must not appear anywhere unless it is intended to be replaced - * to generate other bignum interface functions. - * - * Copyright (c) 1995 Colin Plumb. All rights reserved. - * For licensing and other legal details, see the file legal.c. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifndef HAVE_CONFIG_H -#define HAVE_CONFIG_H 0 -#endif -#if HAVE_CONFIG_H -#include "config.h" -#endif - -/* - * Some compilers complain about #if FOO if FOO isn't defined, - * so do the ANSI-mandated thing explicitly... - */ -#ifndef NO_ASSERT_H -#define NO_ASSERT_H 0 -#endif -#ifndef NO_STRING_H -#define NO_STRING_H 0 -#endif -#ifndef HAVE_STRINGS_H -#define HAVE_STRINGS_H 0 -#endif -#ifndef NEED_MEMORY_H -#define NEED_MEMORY_H 0 -#endif - -#if !NO_ASSERT_H -#include <assert.h> -#else -#define assert(x) (void)0 -#endif - -#if !NO_STRING_H -#include <string.h> /* for memmove() in bnMakeOdd */ -#elif HAVE_STRINGS_H -#include <strings.h> -#endif -#if NEED_MEMORY_H -#include <memory.h> -#endif - -/* - * This was useful during debugging, so it's left in here. - * You can ignore it. DBMALLOC is generally undefined. - */ -#ifndef DBMALLOC -#define DBAMLLOC 0 -#endif -#if DBMALLOC -#include "../dbmalloc/malloc.h" -#define MALLOCDB malloc_chain_check(1) -#else -#define MALLOCDB (void)0 -#endif - -#include "lbn.h" -#include "lbn32.h" -#include "lbnmem.h" -#include "bn32.h" -#include "bn.h" - -/* Work-arounds for some particularly broken systems */ -#include "kludge.h" /* For memmove() */ -#include <port_after.h> - -/* Functions */ -void -bnInit_32(void) -{ - bnEnd = bnEnd_32; - bnPrealloc = bnPrealloc_32; - bnCopy = bnCopy_32; - bnNorm = bnNorm_32; - bnExtractBigBytes = bnExtractBigBytes_32; - bnInsertBigBytes = bnInsertBigBytes_32; - bnExtractLittleBytes = bnExtractLittleBytes_32; - bnInsertLittleBytes = bnInsertLittleBytes_32; - bnLSWord = bnLSWord_32; - bnBits = bnBits_32; - bnAdd = bnAdd_32; - bnSub = bnSub_32; - bnCmpQ = bnCmpQ_32; - bnSetQ = bnSetQ_32; - bnAddQ = bnAddQ_32; - bnSubQ = bnSubQ_32; - bnCmp = bnCmp_32; - bnSquare = bnSquare_32; - bnMul = bnMul_32; - bnMulQ = bnMulQ_32; - bnDivMod = bnDivMod_32; - bnMod = bnMod_32; - bnModQ = bnModQ_32; - bnExpMod = bnExpMod_32; - bnDoubleExpMod = bnDoubleExpMod_32; - bnTwoExpMod = bnTwoExpMod_32; - bnGcd = bnGcd_32; - bnInv = bnInv_32; - bnLShift = bnLShift_32; - bnRShift = bnRShift_32; - bnMakeOdd = bnMakeOdd_32; -} - -void -bnEnd_32(struct BigNum *bn) -{ - if (bn->ptr) { - LBNFREE((BNWORD32 *)bn->ptr, bn->allocated); - bn->ptr = 0; - } - bn->size = 0; - bn->allocated = 0; - - MALLOCDB; -} - -/* Internal function. It operates in words. */ -static int -bnResize_32(struct BigNum *bn, unsigned len) -{ - void *p; - - /* Round size up: most mallocs impose 8-byte granularity anyway */ - len = (len + (8/sizeof(BNWORD32) - 1)) & ~(8/sizeof(BNWORD32) - 1); - p = LBNREALLOC((BNWORD32 *)bn->ptr, bn->allocated, len); - if (!p) - return -1; - bn->ptr = p; - bn->allocated = len; - - MALLOCDB; - - return 0; -} - -#define bnSizeCheck(bn, size) \ - if (bn->allocated < size && bnResize_32(bn, size) < 0) \ - return -1 - -int -bnPrealloc_32(struct BigNum *bn, unsigned bits) -{ - bits = (bits + 32-1)/32; - bnSizeCheck(bn, bits); - MALLOCDB; - return 0; -} - -int -bnCopy_32(struct BigNum *dest, struct BigNum const *src) -{ - bnSizeCheck(dest, src->size); - dest->size = src->size; - lbnCopy_32((BNWORD32 *)dest->ptr, (BNWORD32 *)src->ptr, src->size); - MALLOCDB; - return 0; -} - -void -bnNorm_32(struct BigNum *bn) -{ - bn->size = lbnNorm_32((BNWORD32 *)bn->ptr, bn->size); -} - -/* - * Convert a bignum to big-endian bytes. Returns, in big-endian form, a - * substring of the bignum starting from lsbyte and "len" bytes long. - * Unused high-order (leading) bytes are filled with 0. - */ -void -bnExtractBigBytes_32(struct BigNum const *bn, unsigned char *dest, - unsigned lsbyte, unsigned len) -{ - unsigned s = bn->size * (32 / 8); - - /* Fill unused leading bytes with 0 */ - while (s < lsbyte+len) { - *dest++ = 0; - len--; - } - - if (len) - lbnExtractBigBytes_32((BNWORD32 *)bn->ptr, dest, lsbyte, len); - MALLOCDB; -} - -int -bnInsertBigBytes_32(struct BigNum *bn, unsigned char const *src, - unsigned lsbyte, unsigned len) -{ - unsigned s = bn->size; - unsigned words = (len+lsbyte+sizeof(BNWORD32)-1) / sizeof(BNWORD32); - - /* Pad with zeros as required */ - bnSizeCheck(bn, words); - - if (s < words) { - lbnZero_32((BNWORD32 *)bn->ptr BIGLITTLE(-s,+s), words-s); - s = words; - } - - lbnInsertBigBytes_32((BNWORD32 *)bn->ptr, src, lsbyte, len); - - bn->size = lbnNorm_32((BNWORD32 *)bn->ptr, s); - - MALLOCDB; - return 0; -} - - -/* - * Convert a bignum to little-endian bytes. Returns, in little-endian form, a - * substring of the bignum starting from lsbyte and "len" bytes long. - * Unused high-order (trailing) bytes are filled with 0. - */ -void -bnExtractLittleBytes_32(struct BigNum const *bn, unsigned char *dest, - unsigned lsbyte, unsigned len) -{ - unsigned s = bn->size * (32 / 8); - - /* Fill unused leading bytes with 0 */ - while (s < lsbyte+len) - dest[--len] = 0; - - if (len) - lbnExtractLittleBytes_32((BNWORD32 *)bn->ptr, dest, - lsbyte, len); - MALLOCDB; -} - -int -bnInsertLittleBytes_32(struct BigNum *bn, unsigned char const *src, - unsigned lsbyte, unsigned len) -{ - unsigned s = bn->size; - unsigned words = (len+lsbyte+sizeof(BNWORD32)-1) / sizeof(BNWORD32); - - /* Pad with zeros as required */ - bnSizeCheck(bn, words); - - if (s < words) { - lbnZero_32((BNWORD32 *)bn->ptr BIGLITTLE(-s,+s), words-s); - s = words; - } - - lbnInsertLittleBytes_32((BNWORD32 *)bn->ptr, src, lsbyte, len); - - bn->size = lbnNorm_32((BNWORD32 *)bn->ptr, s); - - MALLOCDB; - return 0; -} - -/* Return the least-significant word of the input. */ -unsigned -bnLSWord_32(struct BigNum const *src) -{ - return src->size ? (unsigned)((BNWORD32 *)src->ptr)[BIGLITTLE(-1,0)]: 0; -} - -unsigned -bnBits_32(struct BigNum const *src) -{ - return lbnBits_32((BNWORD32 *)src->ptr, src->size); -} - -int -bnAdd_32(struct BigNum *dest, struct BigNum const *src) -{ - unsigned s = src->size, d = dest->size; - BNWORD32 t; - - if (!s) - return 0; - - bnSizeCheck(dest, s); - - if (d < s) { - lbnZero_32((BNWORD32 *)dest->ptr BIGLITTLE(-d,+d), s-d); - dest->size = d = s; - MALLOCDB; - } - t = lbnAddN_32((BNWORD32 *)dest->ptr, (BNWORD32 *)src->ptr, s); - MALLOCDB; - if (t) { - if (d > s) { - t = lbnAdd1_32((BNWORD32 *)dest->ptr BIGLITTLE(-s,+s), - d-s, t); - MALLOCDB; - } - if (t) { - bnSizeCheck(dest, d+1); - ((BNWORD32 *)dest->ptr)[BIGLITTLE(-1-d,d)] = t; - dest->size = d+1; - } - } - return 0; -} - -/* - * dest -= src. - * If dest goes negative, this produces the absolute value of - * the difference (the negative of the true value) and returns 1. - * Otherwise, it returls 0. - */ -int -bnSub_32(struct BigNum *dest, struct BigNum const *src) -{ - unsigned s = src->size, d = dest->size; - BNWORD32 t; - - if (d < s && d < (s = lbnNorm_32((BNWORD32 *)src->ptr, s))) { - bnSizeCheck(dest, s); - lbnZero_32((BNWORD32 *)dest->ptr BIGLITTLE(-d,+d), s-d); - dest->size = d = s; - MALLOCDB; - } - if (!s) - return 0; - t = lbnSubN_32((BNWORD32 *)dest->ptr, (BNWORD32 *)src->ptr, s); - MALLOCDB; - if (t) { - if (d > s) { - t = lbnSub1_32((BNWORD32 *)dest->ptr BIGLITTLE(-s,+s), - d-s, t); - MALLOCDB; - } - if (t) { - lbnNeg_32((BNWORD32 *)dest->ptr, d); - dest->size = lbnNorm_32((BNWORD32 *)dest->ptr, - dest->size); - MALLOCDB; - return 1; - } - } - dest->size = lbnNorm_32((BNWORD32 *)dest->ptr, dest->size); - return 0; -} - -/* - * Compare the BigNum to the given value, which must be < 65536. - * Returns -1. 0 or 1 if a<b, a == b or a>b. - * a <=> b --> bnCmpQ(a,b) <=> 0 - */ -int -bnCmpQ_32(struct BigNum const *a, unsigned b) -{ - unsigned t; - BNWORD32 v; - - t = lbnNorm_32((BNWORD32 *)a->ptr, a->size); - /* If a is more than one word long or zero, it's easy... */ - if (t != 1) - return (t > 1) ? 1 : (b ? -1 : 0); - v = (unsigned)((BNWORD32 *)a->ptr)[BIGLITTLE(-1,0)]; - return (v > b) ? 1 : ((v < b) ? -1 : 0); -} - -int -bnSetQ_32(struct BigNum *dest, unsigned src) -{ - if (src) { - bnSizeCheck(dest, 1); - - ((BNWORD32 *)dest->ptr)[BIGLITTLE(-1,0)] = (BNWORD32)src; - dest->size = 1; - } else { - dest->size = 0; - } - return 0; -} - -int -bnAddQ_32(struct BigNum *dest, unsigned src) -{ - BNWORD32 t; - - if (!dest->size) - return bnSetQ(dest, src); - - t = lbnAdd1_32((BNWORD32 *)dest->ptr, dest->size, (BNWORD32)src); - MALLOCDB; - if (t) { - src = dest->size; - bnSizeCheck(dest, src+1); - ((BNWORD32 *)dest->ptr)[BIGLITTLE(-1-src,src)] = t; - dest->size = src+1; - } - return 0; -} - -/* - * Return value as for bnSub: 1 if subtract underflowed, in which - * case the return is the negative of the computed value. - */ -int -bnSubQ_32(struct BigNum *dest, unsigned src) -{ - BNWORD32 t; - - if (!dest->size) - return bnSetQ(dest, src) < 0 ? -1 : (src != 0); - - t = lbnSub1_32((BNWORD32 *)dest->ptr, dest->size, src); - MALLOCDB; - if (t) { - /* Underflow. <= 1 word, so do it simply. */ - lbnNeg_32((BNWORD32 *)dest->ptr, 1); - dest->size = 1; - return 1; - } -/* Try to normalize? Needing this is going to be very rare. */ -/* dest->size = lbnNorm_32((BNWORD32 *)dest->ptr, dest->size); */ - return 0; -} - -/* - * Compare two BigNums. Returns -1. 0 or 1 if a<b, a == b or a>b. - * a <=> b --> bnCmp(a,b) <=> 0 - */ -int -bnCmp_32(struct BigNum const *a, struct BigNum const *b) -{ - unsigned s, t; - - s = lbnNorm_32((BNWORD32 *)a->ptr, a->size); - t = lbnNorm_32((BNWORD32 *)b->ptr, b->size); - - if (s != t) - return s > t ? 1 : -1; - return lbnCmp_32((BNWORD32 *)a->ptr, (BNWORD32 *)b->ptr, s); -} - -int -bnSquare_32(struct BigNum *dest, struct BigNum const *src) -{ - unsigned s; - BNWORD32 *srcbuf; - - s = lbnNorm_32((BNWORD32 *)src->ptr, src->size); - if (!s) { - dest->size = 0; - return 0; - } - bnSizeCheck(dest, 2*s); - - if (src == dest) { - LBNALLOC(srcbuf, s); - if (!srcbuf) - return -1; - lbnCopy_32(srcbuf, (BNWORD32 *)src->ptr, s); - lbnSquare_32((BNWORD32 *)dest->ptr, (BNWORD32 *)srcbuf, s); - LBNFREE(srcbuf, s); - } else { - lbnSquare_32((BNWORD32 *)dest->ptr, (BNWORD32 *)src->ptr, s); - } - - dest->size = lbnNorm_32((BNWORD32 *)dest->ptr, 2*s); - MALLOCDB; - return 0; -} - -int -bnMul_32(struct BigNum *dest, struct BigNum const *a, struct BigNum const *b) -{ - unsigned s, t; - BNWORD32 *srcbuf; - - s = lbnNorm_32((BNWORD32 *)a->ptr, a->size); - t = lbnNorm_32((BNWORD32 *)b->ptr, b->size); - - if (!s || !t) { - dest->size = 0; - return 0; - } - - if (a == b) - return bnSquare_32(dest, a); - - bnSizeCheck(dest, s+t); - - if (dest == a) { - LBNALLOC(srcbuf, s); - if (!srcbuf) - return -1; - lbnCopy_32(srcbuf, (BNWORD32 *)a->ptr, s); - lbnMul_32((BNWORD32 *)dest->ptr, srcbuf, s, - (BNWORD32 *)b->ptr, t); - LBNFREE(srcbuf, s); - } else if (dest == b) { - LBNALLOC(srcbuf, t); - if (!srcbuf) - return -1; - lbnCopy_32(srcbuf, (BNWORD32 *)b->ptr, t); - lbnMul_32((BNWORD32 *)dest->ptr, (BNWORD32 *)a->ptr, s, - srcbuf, t); - LBNFREE(srcbuf, t); - } else { - lbnMul_32((BNWORD32 *)dest->ptr, (BNWORD32 *)a->ptr, s, - (BNWORD32 *)b->ptr, t); - } - dest->size = lbnNorm_32((BNWORD32 *)dest->ptr, s+t); - MALLOCDB; - return 0; -} - -int -bnMulQ_32(struct BigNum *dest, struct BigNum const *a, unsigned b) -{ - unsigned s; - - s = lbnNorm_32((BNWORD32 *)a->ptr, a->size); - if (!s || !b) { - dest->size = 0; - return 0; - } - if (b == 1) - return bnCopy_32(dest, a); - bnSizeCheck(dest, s+1); - lbnMulN1_32((BNWORD32 *)dest->ptr, (BNWORD32 *)a->ptr, s, b); - dest->size = lbnNorm_32((BNWORD32 *)dest->ptr, s+1); - MALLOCDB; - return 0; -} - -int -bnDivMod_32(struct BigNum *q, struct BigNum *r, struct BigNum const *n, - struct BigNum const *d) -{ - unsigned dsize, nsize; - BNWORD32 qhigh; - - dsize = lbnNorm_32((BNWORD32 *)d->ptr, d->size); - nsize = lbnNorm_32((BNWORD32 *)n->ptr, n->size); - - if (nsize < dsize) { - q->size = 0; /* No quotient */ - r->size = nsize; - return 0; /* Success */ - } - - bnSizeCheck(q, nsize-dsize); - - if (r != n) { /* You are allowed to reduce in place */ - bnSizeCheck(r, nsize); - lbnCopy_32((BNWORD32 *)r->ptr, (BNWORD32 *)n->ptr, nsize); - } - - qhigh = lbnDiv_32((BNWORD32 *)q->ptr, (BNWORD32 *)r->ptr, nsize, - (BNWORD32 *)d->ptr, dsize); - nsize -= dsize; - if (qhigh) { - bnSizeCheck(q, nsize+1); - *((BNWORD32 *)q->ptr BIGLITTLE(-nsize-1,+nsize)) = qhigh; - q->size = nsize+1; - } else { - q->size = lbnNorm_32((BNWORD32 *)q->ptr, nsize); - } - r->size = lbnNorm_32((BNWORD32 *)r->ptr, dsize); - MALLOCDB; - return 0; -} - -int -bnMod_32(struct BigNum *dest, struct BigNum const *src, struct BigNum const *d) -{ - unsigned dsize, nsize; - - nsize = lbnNorm_32((BNWORD32 *)src->ptr, src->size); - dsize = lbnNorm_32((BNWORD32 *)d->ptr, d->size); - - - if (dest != src) { - bnSizeCheck(dest, nsize); - lbnCopy_32((BNWORD32 *)dest->ptr, (BNWORD32 *)src->ptr, nsize); - } - - if (nsize < dsize) { - dest->size = nsize; /* No quotient */ - return 0; - } - - (void)lbnDiv_32((BNWORD32 *)dest->ptr BIGLITTLE(-dsize,+dsize), - (BNWORD32 *)dest->ptr, nsize, - (BNWORD32 *)d->ptr, dsize); - dest->size = lbnNorm_32((BNWORD32 *)dest->ptr, dsize); - MALLOCDB; - return 0; -} - -unsigned -bnModQ_32(struct BigNum const *src, unsigned d) -{ - unsigned s; - - s = lbnNorm_32((BNWORD32 *)src->ptr, src->size); - if (!s) - return 0; - - return lbnModQ_32((BNWORD32 *)src->ptr, s, d); -} - -int -bnExpMod_32(struct BigNum *dest, struct BigNum const *n, - struct BigNum const *exp, struct BigNum const *mod) -{ - unsigned nsize, esize, msize; - - nsize = lbnNorm_32((BNWORD32 *)n->ptr, n->size); - esize = lbnNorm_32((BNWORD32 *)exp->ptr, exp->size); - msize = lbnNorm_32((BNWORD32 *)mod->ptr, mod->size); - - if (!msize || (((BNWORD32 *)mod->ptr)[BIGLITTLE(-1,0)] & 1) == 0) - return -1; /* Illegal modulus! */ - - bnSizeCheck(dest, msize); - - /* Special-case base of 2 */ - if (nsize == 1 && ((BNWORD32 *)n->ptr)[BIGLITTLE(-1,0)] == 2) { - if (lbnTwoExpMod_32((BNWORD32 *)dest->ptr, - (BNWORD32 *)exp->ptr, esize, - (BNWORD32 *)mod->ptr, msize) < 0) - return -1; - } else { - if (lbnExpMod_32((BNWORD32 *)dest->ptr, - (BNWORD32 *)n->ptr, nsize, - (BNWORD32 *)exp->ptr, esize, - (BNWORD32 *)mod->ptr, msize) < 0) - return -1; - } - - dest->size = lbnNorm_32((BNWORD32 *)dest->ptr, msize); - MALLOCDB; - return 0; -} - -int -bnDoubleExpMod_32(struct BigNum *dest, - struct BigNum const *n1, struct BigNum const *e1, - struct BigNum const *n2, struct BigNum const *e2, - struct BigNum const *mod) -{ - unsigned n1size, e1size, n2size, e2size, msize; - - n1size = lbnNorm_32((BNWORD32 *)n1->ptr, n1->size); - e1size = lbnNorm_32((BNWORD32 *)e1->ptr, e1->size); - n2size = lbnNorm_32((BNWORD32 *)n2->ptr, n2->size); - e2size = lbnNorm_32((BNWORD32 *)e2->ptr, e2->size); - msize = lbnNorm_32((BNWORD32 *)mod->ptr, mod->size); - - if (!msize || (((BNWORD32 *)mod->ptr)[BIGLITTLE(-1,0)] & 1) == 0) - return -1; /* Illegal modulus! */ - - bnSizeCheck(dest, msize); - - if (lbnDoubleExpMod_32((BNWORD32 *)dest->ptr, - (BNWORD32 *)n1->ptr, n1size, (BNWORD32 *)e1->ptr, e1size, - (BNWORD32 *)n2->ptr, n2size, (BNWORD32 *)e2->ptr, e2size, - (BNWORD32 *)mod->ptr, msize) < 0) - return -1; - - dest->size = lbnNorm_32((BNWORD32 *)dest->ptr, msize); - MALLOCDB; - return 0; -} - -int -bnTwoExpMod_32(struct BigNum *n, struct BigNum const *exp, - struct BigNum const *mod) -{ - unsigned esize, msize; - - esize = lbnNorm_32((BNWORD32 *)exp->ptr, exp->size); - msize = lbnNorm_32((BNWORD32 *)mod->ptr, mod->size); - - if (!msize || (((BNWORD32 *)mod->ptr)[BIGLITTLE(-1,0)] & 1) == 0) - return -1; /* Illegal modulus! */ - - bnSizeCheck(n, msize); - - if (lbnTwoExpMod_32((BNWORD32 *)n->ptr, (BNWORD32 *)exp->ptr, esize, - (BNWORD32 *)mod->ptr, msize) < 0) - return -1; - - n->size = lbnNorm_32((BNWORD32 *)n->ptr, msize); - MALLOCDB; - return 0; -} - -int -bnGcd_32(struct BigNum *dest, struct BigNum const *a, struct BigNum const *b) -{ - BNWORD32 *tmp; - unsigned asize, bsize; - int i; - - /* Kind of silly, but we might as well permit it... */ - if (a == b) - return dest == a ? 0 : bnCopy(dest, a); - - /* Ensure a is not the same as "dest" */ - if (a == dest) { - a = b; - b = dest; - } - - asize = lbnNorm_32((BNWORD32 *)a->ptr, a->size); - bsize = lbnNorm_32((BNWORD32 *)b->ptr, b->size); - - bnSizeCheck(dest, bsize+1); - - /* Copy a to tmp */ - LBNALLOC(tmp, asize+1); - if (!tmp) - return -1; - lbnCopy_32(tmp, (BNWORD32 *)a->ptr, asize); - - /* Copy b to dest,if necessary */ - if (dest != b) - lbnCopy_32((BNWORD32 *)dest->ptr, - (BNWORD32 *)b->ptr, bsize); - if (bsize > asize || (bsize == asize && - lbnCmp_32((BNWORD32 *)b->ptr, (BNWORD32 *)a->ptr, asize) > 0)) - { - i = lbnGcd_32((BNWORD32 *)dest->ptr, bsize, tmp, asize); - if (i >= 0) { - dest->size = (unsigned)i; - } else { - lbnCopy_32((BNWORD32 *)dest->ptr, tmp, - (unsigned)-i); - dest->size = (unsigned)-i; - } - } else { - i = lbnGcd_32(tmp, asize, (BNWORD32 *)dest->ptr, bsize); - if (i <= 0) { - dest->size = (unsigned)-i; - } else { - lbnCopy_32((BNWORD32 *)dest->ptr, tmp, - (unsigned)i); - dest->size = (unsigned)i; - } - } - LBNFREE(tmp, asize+1); - MALLOCDB; - return 0; -} - -int -bnInv_32(struct BigNum *dest, struct BigNum const *src, - struct BigNum const *mod) -{ - unsigned s, m; - int i; - - s = lbnNorm_32((BNWORD32 *)src->ptr, src->size); - m = lbnNorm_32((BNWORD32 *)mod->ptr, mod->size); - - /* lbnInv_32 requires that the input be less than the modulus */ - if (m < s || - (m==s && lbnCmp_32((BNWORD32 *)src->ptr, (BNWORD32 *)mod->ptr, s))) - { - bnSizeCheck(dest, s + (m==s)); - if (dest != src) - lbnCopy_32((BNWORD32 *)dest->ptr, - (BNWORD32 *)src->ptr, s); - /* Pre-reduce modulo the modulus */ - (void)lbnDiv_32((BNWORD32 *)dest->ptr BIGLITTLE(-m,+m), - (BNWORD32 *)dest->ptr, s, - (BNWORD32 *)mod->ptr, m); - s = lbnNorm_32((BNWORD32 *)dest->ptr, m); - MALLOCDB; - } else { - bnSizeCheck(dest, m+1); - if (dest != src) - lbnCopy_32((BNWORD32 *)dest->ptr, - (BNWORD32 *)src->ptr, s); - } - - i = lbnInv_32((BNWORD32 *)dest->ptr, s, (BNWORD32 *)mod->ptr, m); - if (i == 0) - dest->size = lbnNorm_32((BNWORD32 *)dest->ptr, m); - - MALLOCDB; - return i; -} - -/* - * Shift a bignum left the appropriate number of bits, - * multiplying by 2^amt. - */ -int -bnLShift_32(struct BigNum *dest, unsigned amt) -{ - unsigned s = dest->size; - BNWORD32 carry; - - if (amt % 32) { - carry = lbnLshift_32(dest->ptr, s, amt % 32); - if (carry) { - s++; - bnSizeCheck(dest, s); - ((BNWORD32 *)dest->ptr)[BIGLITTLE(-s,s-1)] = carry; - } - } - - amt /= 32; - if (amt) { - bnSizeCheck(dest, s+amt); - memmove((BNWORD32 *)dest->ptr BIGLITTLE(-s-amt, +amt), - (BNWORD32 *)dest->ptr BIG(-s), - s * sizeof(BNWORD32)); - lbnZero_32((BNWORD32 *)dest->ptr, amt); - s += amt; - } - dest->size = s; - MALLOCDB; - return 0; -} - -/* - * Shift a bignum right the appropriate number of bits, - * dividing by 2^amt. - */ -void bnRShift_32(struct BigNum *dest, unsigned amt) -{ - unsigned s = dest->size; - - if (amt >= 32) { - memmove( - (BNWORD32 *)dest->ptr BIG(-s+amt/32), - (BNWORD32 *)dest->ptr BIGLITTLE(-s, +amt/32), - s-amt/32 * sizeof(BNWORD32)); - s -= amt/32; - amt %= 32; - } - - if (amt) - (void)lbnRshift_32(dest->ptr, s, amt); - - dest->size = lbnNorm_32(dest->ptr, s); - MALLOCDB; -} - -/* - * Shift a bignum right until it is odd, and return the number of - * bits shifted. n = d * 2^s. Replaces n with d and returns s. - * Returns 0 when given 0. (Another valid answer is infinity.) - */ -unsigned -bnMakeOdd_32(struct BigNum *n) -{ - unsigned size; - unsigned s; /* shift amount */ - BNWORD32 *p; - BNWORD32 t; - - p = (BNWORD32 *)n->ptr; - size = lbnNorm_32(p, n->size); - if (!size) - return 0; - - t = BIGLITTLE(p[-1],p[0]); - s = 0; - - /* See how many words we have to shift */ - if (!t) { - /* Shift by words */ - do { - - s++; - BIGLITTLE(--p,p++); - } while ((t = BIGLITTLE(p[-1],p[0])) == 0); - size -= s; - s *= 32; - memmove((BNWORD32 *)n->ptr BIG(-size), p BIG(-size), - size * sizeof(BNWORD32)); - p = (BNWORD32 *)n->ptr; - MALLOCDB; - } - - assert(t); - - /* Now count the bits */ - while ((t & 1) == 0) { - t >>= 1; - s++; - } - - /* Shift the bits */ - if (s & (32-1)) { - lbnRshift_32(p, size, s & (32-1)); - /* Renormalize */ - if (BIGLITTLE(*(p-size),*(p+(size-1))) == 0) - --size; - } - n->size = size; - - MALLOCDB; - return s; -} diff --git a/usr/src/lib/libresolv2/common/cylink/bn32.h b/usr/src/lib/libresolv2/common/cylink/bn32.h deleted file mode 100644 index d6bdc189f6..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/bn32.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * bn32.h - interface to 32-bit bignum routines. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -struct BigNum; - -void bnInit_32(void); -void bnEnd_32(struct BigNum *bn); -int bnPrealloc_32(struct BigNum *bn, unsigned bits); -int bnCopy_32(struct BigNum *dest, struct BigNum const *src); -int bnSwap_32(struct BigNum *a, struct BigNum *b); -void bnNorm_32(struct BigNum *bn); -void bnExtractBigBytes_32(struct BigNum const *bn, unsigned char *dest, - unsigned lsbyte, unsigned dlen); -int bnInsertBigBytes_32(struct BigNum *bn, unsigned char const *src, - unsigned lsbyte, unsigned len); -void bnExtractLittleBytes_32(struct BigNum const *bn, unsigned char *dest, - unsigned lsbyte, unsigned dlen); -int bnInsertLittleBytes_32(struct BigNum *bn, unsigned char const *src, - unsigned lsbyte, unsigned len); -unsigned bnLSWord_32(struct BigNum const *src); -unsigned bnBits_32(struct BigNum const *src); -int bnAdd_32(struct BigNum *dest, struct BigNum const *src); -int bnSub_32(struct BigNum *dest, struct BigNum const *src); -int bnCmpQ_32(struct BigNum const *a, unsigned b); -int bnSetQ_32(struct BigNum *dest, unsigned src); -int bnAddQ_32(struct BigNum *dest, unsigned src); -int bnSubQ_32(struct BigNum *dest, unsigned src); -int bnCmp_32(struct BigNum const *a, struct BigNum const *b); -int bnSquare_32(struct BigNum *dest, struct BigNum const *src); -int bnMul_32(struct BigNum *dest, struct BigNum const *a, - struct BigNum const *b); -int bnMulQ_32(struct BigNum *dest, struct BigNum const *a, unsigned b); -int bnDivMod_32(struct BigNum *q, struct BigNum *r, struct BigNum const *n, - struct BigNum const *d); -int bnMod_32(struct BigNum *dest, struct BigNum const *src, - struct BigNum const *d); -unsigned bnModQ_32(struct BigNum const *src, unsigned d); -int bnExpMod_32(struct BigNum *dest, struct BigNum const *n, - struct BigNum const *exp, struct BigNum const *mod); -int bnDoubleExpMod_32(struct BigNum *dest, - struct BigNum const *n1, struct BigNum const *e1, - struct BigNum const *n2, struct BigNum const *e2, - struct BigNum const *mod); -int bnTwoExpMod_32(struct BigNum *n, struct BigNum const *exp, - struct BigNum const *mod); -int bnGcd_32(struct BigNum *dest, struct BigNum const *a, - struct BigNum const *b); -int bnInv_32(struct BigNum *dest, struct BigNum const *src, - struct BigNum const *mod); -int bnLShift_32(struct BigNum *dest, unsigned amt); -void bnRShift_32(struct BigNum *dest, unsigned amt); -unsigned bnMakeOdd_32(struct BigNum *n); diff --git a/usr/src/lib/libresolv2/common/cylink/bn68000.c b/usr/src/lib/libresolv2/common/cylink/bn68000.c deleted file mode 100644 index 91bcd1d7af..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/bn68000.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * bn68000.c - bnInit() for Motorola 680x0 family, 16 or 32-bit. - * - * Written in 1995 by Colin Plumb. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "lbn.h" -#include "bn16.h" -#include "bn32.h" - -#ifndef BNINCLUDE -#error You must define BNINCLUDE to lbn68000.h to use assembly primitives. -#endif - -void -bnInit(void) -{ - if (is68020()) - bnInit_32(); - else - bnInit_16(); -} diff --git a/usr/src/lib/libresolv2/common/cylink/bn8086.c b/usr/src/lib/libresolv2/common/cylink/bn8086.c deleted file mode 100644 index b50aab6ad6..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/bn8086.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * bn8086.c - bnInit() for Intel x86 family in 16-bit mode. - * - * Written in 1995 by Colin Plumb. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "lbn.h" -#include "bn16.h" -#include "bn32.h" - -#ifndef BNINCLUDE -#error You must define BNINCLUDE to lbn8086.h to use assembly primitives. -#endif - -void -bnInit(void) -{ -/* if (not386()) - bnInit_16(); - else */ - bnInit_32(); -} diff --git a/usr/src/lib/libresolv2/common/cylink/bninit16.c b/usr/src/lib/libresolv2/common/cylink/bninit16.c deleted file mode 100644 index efe5bd3475..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/bninit16.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * bninit16.c - Provide an init function that sets things up for 16-bit - * operation. This is a seaparate tiny file so you can compile two bn - * packages into the library and write a custom init routine. - * - * Written in 1995 by Colin Plumb. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "bn.h" -#include "bn16.h" - -void -bnInit(void) -{ - bnInit_16(); -} diff --git a/usr/src/lib/libresolv2/common/cylink/bninit32.c b/usr/src/lib/libresolv2/common/cylink/bninit32.c deleted file mode 100644 index 1f90d66780..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/bninit32.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * bninit32.c - Provide an init function that sets things up for 32-bit - * operation. This is a seaparate tiny file so you can compile two bn - * packages into the library and write a custom init routine. - * - * Written in 1995 by Colin Plumb. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "bn.h" -#include "bn32.h" - -void -bnInit(void) -{ - bnInit_32(); -} diff --git a/usr/src/lib/libresolv2/common/cylink/bnsize00.h b/usr/src/lib/libresolv2/common/cylink/bnsize00.h deleted file mode 100644 index d59f9f40ff..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/bnsize00.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * bnsize00.h - pick the correct machine word size to use. - * - * Copyright (c) 1995 Colin Plumb. All rights reserved. - * For licensing and other legal details, see the file legal.c. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "lbn.h" /* Get basic information */ - -#if !BNSIZE64 && !BNSIZE32 && !BNSIZE16 && defined(BNWORD64) -# if defined(BNWORD128) || (defined(lbnMulAdd1_64) && defined(lbnMulSub1_64)) -# define BNSIZE64 1 -# elif defined(mul64_ppmm) || defined(mul64_ppmma) || defined(mul64_ppmmaa) -# define BNSIZE64 1 -# endif -#endif - -#if !BNSIZE64 && !BNSIZE32 && !BNSIZE16 && defined(BNWORD32) -# if defined(BNWORD64) || (defined(lbnMulAdd1_32) && defined(lbnMulSub1_32)) -# define BNSIZE32 1 -# elif defined(mul32_ppmm) || defined(mul32_ppmma) || defined(mul32_ppmmaa) -# define BNSIZE32 1 -# endif -#endif - -#if !BNSIZE64 && !BNSIZE32 && !BNSIZE16 && defined(BNWORD16) -# if defined(BNWORD32) || (defined(lbnMulAdd1_16) && defined(lbnMulSub1_16)) -# define BNSIZE16 1 -# elif defined(mul16_ppmm) || defined(mul16_ppmma) || defined(mul16_ppmmaa) -# define BNSIZE16 1 -# endif -#endif - -#if !BNSIZE64 && !BNSIZE32 && !BNSIZE16 -#error Unable to find a viable word size to compile bignum library. -#endif diff --git a/usr/src/lib/libresolv2/common/cylink/c_asm.h b/usr/src/lib/libresolv2/common/cylink/c_asm.h deleted file mode 100644 index c22bc614fb..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/c_asm.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/**************************************************************************** -* FILENAME: c_asm.h PRODUCT NAME: CRYPTOGRAPHIC TOOLKIT -* -* FILE STATUS: -* -* DESCRIPTION: C / ASM Header File -* -* USAGE: File should be included to use Toolkit Functions -* -* -* Copyright (c) Cylink Corporation 1994. All rights reserved. -* -* REVISION HISTORY: -* -* 14 Oct 94 GKL For Second version (big endian support) -* 26 Oct 94 GKL (alignment for big endian support ) -* -****************************************************************************/ -#if !defined( C_ASM_H ) -#define C_ASM_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <sys/types.h> -#include "cylink.h" -#include "ctk_endian.h" - -#ifdef __cplusplus -extern "C" { -#endif - - - int Sum_big (ord *X, - ord *Y, - ord *Z, - int len_X ); - int Sum (ord *X, ord *Y, ushort len_X ); - int Sub_big (ord *X, - ord *Y, - ord *Z, - int len_X ); -/* - void Mul_big( ord *X, ord *Y,ord *XY, - ushort lx, ushort ly, - ushort elements_in_X, - ushort elements_in_Y);*/ - void Mul_big( ord *X, ord *Y,ord *XY, - ushort lx, ushort ly); - - void PReLo_big( ord *X, ord *P, - ushort len_X, ushort el); - - void Div_big( ord *X, ord *P, - ushort len_X, ushort el, - ord *div); - -int LeftMostBit_big ( ord X ); -int LeftMostEl_big( ord *X, ushort len_X ); -void RShiftL_big( ord *X, u_int32_t len_X, u_int32_t n_bit ); -void LShiftL_big( ord *X, u_int32_t len_X, u_int32_t n_bit ); -int RShiftMostBit(ord *a, u_int32_t len); -void ByteLong(uchar *X, u_int32_t X_bytes, u_int32_t *Y); -void ByteOrd(uchar *X, u_int32_t X_bytes, ord *Y); -void OrdByte(ord *X, u_int32_t X_bytes, uchar *Y); -void LongByte(u_int32_t *X, u_int32_t X_bytes, uchar *Y); -int BitValue_big( ord *X, ushort n_bits ); -int BitsValue_big( ord *X, ushort n_bits, ushort bit_count ); -void ByteSwap32_big( uchar *X, ushort X_len ); -void Complement_big( ord *X, ushort X_longs); -void Diagonal_big (ord *X, ushort X_len, ord *X2); -void Square_big( ord *X, ushort X_len, ord *X2); -void Mul_big_1( ord X, ord *Y, ord *XY, ushort ly ); -int Sum_Q(ord *X, ushort src, ushort len_X ); - - - -/* In-place DES encryption */ - void DES_encrypt(uchar *keybuf, uchar *block); - -/* In-place DES decryption */ - void DES_decrypt(uchar *keybuf, uchar *block); - -/* In-place KAPPA encryption */ - void KAPPA_encrypt(uchar *a, uchar *k, ushort r); - -/* In-place KAPPA decryption */ - void KAPPA_decrypt(uchar *a, uchar *k, ushort r); - -#ifdef __cplusplus -} -#endif - - -#endif /*C_ASM_H*/ - diff --git a/usr/src/lib/libresolv2/common/cylink/cencrint.h b/usr/src/lib/libresolv2/common/cylink/cencrint.h deleted file mode 100644 index 16adb10348..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/cencrint.h +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/**************************************************************************** -* FILENAME: cencrint.h PRODUCT NAME: CRYPTOGRAPHIC TOOLKIT -* -* FILE STATUS: -* -* DESCRIPTION: Cryptographic Toolkit Internal Functions Header File -* -* USAGE: File should be included to use Toolkit Functions -* -* -* Copyright (c) Cylink Corporation 1994. All rights reserved. -* -* REVISION HISTORY: -* -* 23 Aug 94 KPZ Initial release -* 24 Sep 94 KPZ Added prototypes of internal functions -* 14 Oct 94 GKL Second version (big endian support) -* 08 Dec 94 GKL Added YIELD_context to Expo, VerPrime and GenPrime -* -****************************************************************************/ - -#ifndef CENCRINT_H /* Prevent multiple inclusions of same header file */ -#define CENCRINT_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -/**************************************************************************** -* INCLUDE FILES -****************************************************************************/ - -/* system files */ -#include <sys/types.h> -#include "cylink.h" -#include "ctk_endian.h" -#include "toolkit.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Compute a modulo */ - int PartReduct( u_int16_t X_bytes, ord *X, - u_int16_t P_bytes, ord *P, - ord *Z ); - -/* Compute a modulo product */ - int Mul( u_int16_t X_bytes, ord *X, - u_int16_t Y_bytes, ord *Y, - u_int16_t P_bytes, ord *P, - ord *Z ); -/*Compute a modulo squaring*/ -int Mul_Squr( u_int16_t X_bytes, ord *X, - u_int16_t P_bytes, ord *P, - ord *Z ); -int Square( u_int16_t X_bytes, - ord *X, - u_int16_t P_bytes, - ord *P, - ord *Z ); - -/*Compare two array*/ -int Comp_Mont ( ord *X, ord *P, u_int16_t P_longs ); -/*Compute invers element*/ -ord Inv_Mont ( ord x ); -/*Modulo by the Mongomery*/ -void PartReduct_Mont( ord *X, u_int16_t P_bytes, ord *P, ord inv ); -/*Computes squaring by the Mongomery modulo*/ -int Mul_Squr_Mont(ord *X, u_int16_t P_bytes, - ord *P, ord *Z, - ord inv ); -/*Computes multiply by the montgomery modulo*/ -int Mul_Mont( ord *X, ord *Y, - u_int16_t P_bytes, ord *P, - ord *Z, ord inv ); - -/* Compute a modulo exponent */ - int Expo( u_int16_t X_bytes, ord *X, - u_int16_t Y_bytes, ord *Y, - u_int16_t P_bytes, ord *P, - ord *Z ); - /*Compute double exponent */ - int DoubleExpo( u_int16_t X1_bytes,ord *X1, - u_int16_t Y1_bytes,ord *Y1, - u_int16_t X2_bytes,ord *X2, - u_int16_t Y2_bytes,ord *Y2, - u_int16_t P_bytes,ord *P, - ord *Z); -/* Compute a modulo inverse element */ - int Inverse( u_int16_t X_bytes, ord *X, - u_int16_t P_bytes, ord *P, - ord *Z ); - -/* Verify Pseudo Prime number */ - int VerPrime( u_int16_t P_bytes, ord *P, - u_int16_t k, ord *RVAL, - YIELD_context *yield_cont ); /*TKL00601*/ - -/* Generate Random Pseudo Prime number */ - int GenPrime( u_int16_t P_bytes, ord *P, - u_int16_t k, ord *RVAL, - YIELD_context *yield_cont ); /*TKL00601*/ - -/* Transfer bytes to u_int32_t */ - void ByteLong( uchar *X, - u_int16_t X_bytes, - u_int32_t *Y ); - -/* Transfer u_int32_t to bytes */ - void LongByte( u_int32_t *X, - u_int16_t X_bytes, - uchar *Y ); - -/* Transfer bytes to ord */ - void ByteOrd( uchar *X, - u_int16_t X_bytes, - ord *Y ); - -/* Transfer ord to bytes */ - void OrdByte( ord *X, - u_int16_t X_bytes, - uchar *Y ); - -/* Find the left most non zero bit */ - int LeftMostBit ( ord X ); - -/* Find the left most element */ - int LeftMostEl( ord *X, - u_int16_t len_X ); - -/* Shift array to rigth by n_bit */ - void RShiftL( ord *X, - u_int16_t len_X, - u_int16_t n_bit ); - -/* Shifts array to left by n_bit */ - void LShiftL( ord *X, - u_int16_t len_X, - u_int16_t n_bit ); - -/* Find the value of bit */ - int BitValue( ord *X, - u_int16_t n_bits ); - -/* Perform byte reversal on an array of ordinar type (longword or shortword) */ - void ByteSwap( uchar *X, - u_int16_t X_len ); - -/* Perform byte reversal on an array from LSB to MSB */ - void BigSwap( uchar *X, - u_int16_t X_len ); - -/* Perform byte reversal on an array of longword */ - void ByteSwap32( uchar *X, - u_int16_t X_len ); - -/* Perform short reversal on an array of longword */ - void WordSwap( uchar *X, - u_int16_t X_len ); - -/* Perform SHS transformation */ - void shaTransform( u_int32_t *state, - const uchar *block ); - -/* Compute modulo addition - int Add( ord *X, - ord *Y, - u_int16_t P_len, - ord *P, - ord *Z ); - */ - int Add( ord *X, - ord *Y, - u_int16_t P_len, - ord *P ); -/* Initialize Secure Hash Function for generate - random number for DSS */ - void SHAInitK( SHA_context *hash_context ); - -/* Set parity bits */ - void SetKeyParity( uchar *key ); - -/* Find a least significant non zero bit - and sfift array to right */ - int RShiftMostBit( ord *a, u_int16_t len ); - -/*Compute great common divisor */ - int SteinGCD( ord *m, ord *b, u_int16_t len ); - -/* Compute a modulo and divisor */ - int DivRem( u_int16_t X_bytes, ord *X, - u_int16_t P_bytes, ord *P, - ord *Z, ord *D ); - -/* Generate random number */ -int MyGenRand( u_int16_t A_bytes, ord *A, - ord *RVAL); - -/* Compute a Secure Hash Function */ -int MySHA( uchar *message, - u_int16_t message_bytes, - uchar *hash_result ); - -/* Finalize Secure Hash Function */ - int MySHAFinal( SHA_context *hash_context, - uchar *hash_result ); - - void shaTransform_new( u_int32_t *state, - uchar *block ); - - -#ifdef __cplusplus -} -#endif - - -#endif /* CENCRINT_H */ - diff --git a/usr/src/lib/libresolv2/common/cylink/ctk_endian.h b/usr/src/lib/libresolv2/common/cylink/ctk_endian.h deleted file mode 100644 index 1e5a27682f..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/ctk_endian.h +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (c) 2001 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/**********************************************************************\ -* FILENAME: ctk_endian.h PRODUCT NAME: -* -* DESCRIPTION: header file of defines -* -* USAGE: Platform-dependend compilation modes header -* -* -* Copyright (c) Cylink Corporation 1994. All rights reserved. -* -* REVISION HISTORY: -* -\**********************************************************************/ - -#ifndef CTK_ENDIAN_H /* Prevent multiple inclusions of same header file */ -#define CTK_ENDIAN_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <sys/types.h> -#include <ctype.h> -#include <arpa/nameser_compat.h> -#include "lbn.h" - -#if (defined(BIG_ENDIAN) || defined(_BIG_ENDIAN)) && !(defined(LITTLE_ENDIAN) || defined(_LITTLE_ENDIAN)) -# undef BIG_ENDIAN -# undef _BIG_ENDIAN -# define BIG_ENDIAN 4321 -# define LITTLE_ENDIAN 1234 -# define BYTE_ORDER BIG_ENDIAN - -#elif !(defined(BIG_ENDIAN) || defined(_BIG_ENDIAN)) && (defined(LITTLE_ENDIAN) || defined(_LITTLE_ENDIAN)) -# undef LITTLE_ENDIAN -# undef _LITTLE_ENDIAN -# define BIG_ENDIAN 4321 -# define LITTLE_ENDIAN 1234 -# define BYTE_ORDER LITTLE_ENDIAN -#endif - -#if !defined(BYTE_ORDER) || \ - (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN) - /* you must determine what the correct bit order is for - * your compiler - the next line is an intentional error - * which will force your compiles to bomb until you fix - * the above macros. - */ -# if !defined(CTK_LITTLE_ENDIAN) && !defined(CTK_BIG_ENDIAN) -# error "Undefined or invalid BYTE_ORDER"; -# endif -#endif - -#if !defined(CTK_BIG_ENDIAN) && !defined(CTK_LITTLE_ENDIAN) -# ifdef BYTE_ORDER -# if (BYTE_ORDER == LITTLE_ENDIAN) -# define CTK_LITTLE_ENDIAN -# elif (BYTE_ORDER == BIG_ENDIAN) -# define CTK_BIG_ENDIAN -# else -# error CAN NOT determine ENDIAN with BYTE_ORDER -# endif -# elif defined(_LITTLE_ENDIAN) -# define CTK_LITTLE_ENDIAN -# elif defined(_BIG_ENDIAN) -# define CTK_BIG_ENDIAN -# else -# error CAN NOT determine ENDIAN -# endif -#endif - -#if !defined(CTK_BIG_ENDIAN) && !defined(CTK_LITTLE_ENDIAN) -# error NO CTK_???_ENDIAN defined -#endif - -#if defined( CTK_LITTLE_ENDIAN ) && defined( CTK_BIG_ENDIAN ) -# error Use only one define CPU type CTK_LITTLE or BIG ENDIAN. -#endif - -#if !defined( ORD_32 ) && !defined( ORD_16 ) -# ifdef BNSIZE64 -# error BNSIZE64 do not know how to do this -# elif defined(BNSIZE32) -# define ORD_32 -# elif defined(BNSIZE16) -# define ORD_16 -# elif !defined( UINT_MAX) /* No <limits.h> */ -# define ORD_16 /* default */ -# else -# if ULONG_MAX == 0xffffffff -# define ORD_16 -# else -# define ORD_32 -# endif -# endif -#endif - -#if !defined( ORD_32 ) && !defined( ORD_16 ) -#error Not defined basic word type ORD_32 or ORD_16. -#endif - -#if defined( ORD_32 ) && defined( ORD_16 ) -#error Use only one define basic word type ORD_32 or ORD_16. -#endif - - -#ifdef ORD_16 -/* typedef unsigned short ord; deleted by ogud@tis.com 1998/9/14 */ -typedef u_int16_t ord; -#define BITS_COUNT 16 -#define MAXDIGIT (ord)(0xFFFF) -#endif - -#ifdef ORD_32 -/* typedef unsigned long ord; deleted by ogud@tis.com 1998/9/14 */ -typedef u_int32_t ord; -#define BITS_COUNT 32 -#define MAXDIGIT (ord)(0xFFFFFFFF) -#endif /* ORD_32 */ - - - -#define CALLOC(var,type,len) \ - var=(type *)calloc(len,1); \ - if (var==NULL) \ - status=ERR_ALLOC -#ifdef CTK_BIG_ENDIAN -#define ALIGN_CALLOC(i,o,l) \ - CALLOC(o,ord,l) -#define ALIGN_CALLOC_COPY(i,o,l) \ - CALLOC(o,ord,l); \ - if (o) ByteOrd(i,l,o) -#define ALIGN_CALLOC_MOVE(i,o,l) \ - CALLOC(o,ord,l); \ - if (o) memcpy(o,i,l) -#define ALIGN_FREE(o) \ - free ( o ) -#define ALIGN_COPY_FREE(o,i,l) \ - if ((o) && (status==SUCCESS)) \ - OrdByte(o,l,i); \ - free (o) -#define ALIGN_MOVE_FREE(o,i,l) \ - if ((o) && (status==SUCCESS)) \ - memcpy(i,o,l); \ - memset(o,0,l); \ - free (o) -#else -#define ALIGN_CALLOC(i,o,l) o=(ord *)i -#define ALIGN_CALLOC_COPY(i,o,l) o=(ord *)i -#define ALIGN_CALLOC_MOVE(i,o,l) o=(ord *)i -#define ALIGN_FREE(o) ; -#define ALIGN_COPY_FREE(o,i,l) ; -#define ALIGN_MOVE_FREE(o,i,l) ; -#endif -#define DSS_P_ALIGN_CALLOC_COPY(i,o,l) \ - if (i) \ - { ALIGN_CALLOC_COPY(i,o,l);} \ - else \ - o = &DSS_P_NUMBERS[DSS_NUM_INDEX[(l-DSS_LENGTH_MIN)/LENGTH_STEP]] - -#define DSS_G_ALIGN_CALLOC_COPY(i,o,l) \ - if (i) \ - { ALIGN_CALLOC_COPY(i,o,l);} \ - else \ - o = &DSS_G_NUMBERS[DSS_NUM_INDEX[(l-DSS_LENGTH_MIN)/LENGTH_STEP]] - -#define DSS_Q_ALIGN_CALLOC_COPY(i,o,l) \ - if (i) \ - { ALIGN_CALLOC_COPY(i,o,l);} \ - else \ - o = DSS_Q_NUMBER - -#define DSS_ALIGN_FREE(o,i) \ - if (i) \ - { ALIGN_FREE(o);} -#endif /* CTK_ENDIAN_H */ diff --git a/usr/src/lib/libresolv2/common/cylink/ctk_prime.c b/usr/src/lib/libresolv2/common/cylink/ctk_prime.c deleted file mode 100644 index 45b576eb3f..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/ctk_prime.c +++ /dev/null @@ -1,442 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/**************************************************************************** -* FILENAME: prime.c PRODUCT NAME: CRYPTOGRAPHIC TOOLKIT -* -* FILE STATUS: -* -* DESCRIPTION: Cryptographic Toolkit Internal Functions File -* Prime Number functions -* PRIVATE FUNCTIONS: -* -* int VerPrime( u_int16_t P_bytes, ord *P, -* u_int16_t k, ord *RVAL, -* YIELD_context *yield_cont ) -* int GenPrime( u_int16_t P_bytes, ord *P, -* u_int16_t k, ord *RVAL, -* YIELD_context *yield_cont ) -* Copyright (c) Cylink Corporation 1996. All rights reserved. -* -* REVISION HISTORY: -* -* -****************************************************************************/ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/**************************************************************************** -* INCLUDE FILES -****************************************************************************/ - -#include "port_before.h" -#include <sys/types.h> -#include "cylink.h" -#include "ctk_endian.h" - -/* system files */ -#ifdef VXD -#include <vtoolsc.h> -#else -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#endif - -/* program files */ -#include "cylink.h" -#include "ctk_endian.h" -#include "toolkit.h" -#include "cencrint.h" -#include "port_after.h" - -/**************************************************************************** -* PRIVATE FUNCTIONS DEFINITIONS -****************************************************************************/ -/**************************************************************************** -* NAME: int VerPrime( u_int16_t P_bytes, -* ord *P, -* u_int16_t k, -* ord *RVAL, -* YIELD_context *yield_cont ) -* -* DESCRIPTION: Verify Pseudo Prime number -* -* INPUTS: -* PARAMETERS: -* u_int16_t P_bytes Number of bytes in array -* u_int16_t k Number of testing -* ord *RVAL Pointer to random number generator value -* YIELD_context *yield_cont Pointer to yield_cont structure (NULL if not used) -* OUTPUT: -* PARAMETERS: -* ord *P Pointer to prime number -* ord *RVAL Pointer to updated value -* -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data(zero bytes) -* ERR_PRIME Number is not prime -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* 08 Dec 94 GKL Added YIELD_context -* -****************************************************************************/ - - int VerPrime( u_int16_t P_bytes, - ord *P, - u_int16_t k, - ord *RVAL, - YIELD_context *yield_cont ) /*TKL00601*/ - -{ - int status = SUCCESS; /*function return status*/ - ord *b, *n, *c, *pp; /*pointers to working buffers */ - ord *m, *buf, *P_buf; - u_int16_t max_bytes; /*number of maximum bytes*/ - u_int16_t P_longs; /*number of longs in Y*/ - u_int16_t i, j, s, k_b; /*counters*/ - u_int16_t exit ; /*flag for exit*/ -/* product of prime numbers from 3 to 379 (512-bit number) */ -#ifdef ORD_32 - ord b1[DSS_LENGTH_MIN/sizeof(ord)]={ - 0x2e30c48fL, 0x0decece9L, 0xbada8f98L, 0x9f7ecb29L, - 0xa4a11de4L, 0x6ef04659L, 0xcbc38405L, 0x233db117L, - 0x03e81187L, 0xc1b631a2L, 0x238bfb99L, 0x077ec3baL, - 0xc5d5f09fL, 0xb0813c28L, 0x7646fa6eL, 0x106aa9fbL }; -#else - ord b1[DSS_LENGTH_MIN/sizeof(ord)]={ - 0xc48f, 0x2e30, 0xece9, 0x0dec, 0x8f98, 0xbada, 0xcb29, 0x9f7e, - 0x1de4, 0xa4a1, 0x4659, 0x6ef0, 0x8405, 0xcbc3, 0xb117, 0x233d, - 0x1187, 0x03e8, 0x31a2, 0xc1b6, 0xfb99, 0x238b, 0xc3ba, 0x077e, - 0xf09f, 0xc5d5, 0x3c28, 0xb081, 0xfa6e, 0x7646, 0xa9fb, 0x106a }; -#endif - if ( P_bytes % sizeof(ord) != 0 ) /* not multiple 4 (32 bit) */ - { - status = ERR_INPUT_LEN; /* invalid length for input data */ - return status; - } - if ( P_bytes <= DSS_LENGTH_MIN ) - { - max_bytes = DSS_LENGTH_MIN; - } - else - { - max_bytes = P_bytes; - } - buf = (ord *)calloc( max_bytes / sizeof(ord), sizeof(ord) ); - P_buf = (ord *)calloc( max_bytes / sizeof(ord), sizeof(ord)); - if( !buf || !P_buf ) - { - if ( buf ) - free( buf ); - if( P_buf ) - free( P_buf ); - return ERR_ALLOC; - } - memcpy( buf, b1, DSS_LENGTH_MIN ); - memcpy( P_buf, P, P_bytes ); - - if ( (P_buf[0] & 0x1) == 0 ) - { -#ifdef DEBUG1 - printf ("\n P is not pseudoprime"); -#endif - status = ERR_PRIME; - free ( buf ); - free( P_buf ); - return status; - } - P_longs = (u_int16_t) (P_bytes / sizeof(ord)); - b = (ord *)calloc( P_longs, sizeof(ord) ); - m = (ord *)malloc( P_longs * sizeof(ord) ); - n = (ord *)calloc( P_longs, sizeof(ord) ); - c = (ord *)calloc( P_longs, sizeof(ord) ); - pp = (ord *)malloc( P_longs * sizeof(ord) ); - if( !b || !m || !n || !c || !pp ) - { - if( b ) - free( b ); - if( m ) - free( m ); - if( n ) - free( n ); - if( c ) - free( c ); - if( pp ) - free ( pp ); - } - memcpy( m, P, P_bytes ); - memcpy( pp, P, P_bytes ); - /* Compute great common divisor(gcd) */ - if ( SteinGCD( P_buf, buf, (u_int16_t)(max_bytes / sizeof(ord)) ) == 0 ) - { - pp[0] = pp[0] - 1; /* Initialized work buffer */ - m[0] = m[0] - 1; - s = (u_int16_t) RShiftMostBit( m, (u_int16_t)(P_bytes / sizeof(ord)) ); /* Right shift by number of*/ - exit = 0; /* zero bits at rigth */ - k_b = 0; - while( k_b != k ) - { - MyGenRand( 4, b, RVAL ); /* generate random number */ - if ( SteinGCD( P_buf, b , (u_int16_t)(P_bytes / sizeof(ord)) ) ) /* check gcd */ - { -#ifdef DEBUG1 - printf ("\n P is not pseudoprime"); -#endif - status = ERR_PRIME; - break; - } - k_b++; /* increment counter */ - if ( ( status = Expo ( 4, b, P_bytes, m, - P_bytes, P, c ) ) != SUCCESS ) /* c=b^m mod(P) */ /*TKL00601*/ - { - free( b ); - free( m ); - free( n ); - free( c ); - free( pp ); - free (buf ); - free( P_buf ); - return status; - } - if ( c[0] == 1 ) /* if c==1 number is pseudo prime */ - { - for ( i = 1; i < P_bytes / sizeof(ord); i++ ) - { - if ( c[i] != 0 ) - { - break; - } - } - if ( i == P_bytes / sizeof(ord) ) - { - if (yield_cont) /*TKL00601*/ -#ifdef VXD - if ( VXD_Yield (yield_cont->yield_proc) ) -#else - if ( yield_cont->yield_proc(0xFFFF) ) -#endif - - { - status = ERR_CANCEL; - free( b ); - free( m ); - free( n ); - free( c ); - free( pp ); - free( P_buf ); - free (buf ); - return status; - } -#ifdef DEBUG1 - printf ("\n P is a pseudoprime %d",k_b); -#endif - if ( k_b == k ) - { - break; - } - } - } - else - { - for ( j = 1; j <= s; j++ ) - { - for ( i = 0; i < P_bytes / sizeof(ord); i++ ) /* if c==pp number is pseudo prime */ - { - if ( c[i] != pp[i] ) - { - break; - } - } - if ( i == P_bytes / sizeof(ord) ) - { - if (yield_cont) /*TKL00601*/ -#ifdef VXD - if ( VXD_Yield (yield_cont->yield_proc) ) -#else - if ( yield_cont->yield_proc(0xFFFF) ) -#endif - - { - status = ERR_CANCEL; - free( b ); - free( m ); - free( n ); - free( c ); - free( pp ); - free( P_buf ); - free (buf ); - return status; - } -#ifdef DEBUG1 - printf ("\n P is a pseudoprime %d",k_b); -#endif - break; - } - if ( j == s ) - { -#ifdef DEBUG1 - printf ("\n P is not pseudoprime"); -#endif - status = ERR_PRIME; - exit = 1; - break; - } - else - { - if ( (status = Square(P_bytes, c, /*P_bytes, - c,*/ P_bytes, P, c) ) - != SUCCESS ) /* c=c^2mod(p) */ - { - free( b ); - free( m ); - free( n ); - free( c ); - free( pp ); - free( P_buf ); - free (buf ); - return status; - } - } - } - } - if ( exit == 1 ) /* Exit */ - { - break; - } - } - } - else - { - if (yield_cont) /*TKL00601*/ -#ifdef VXD - if ( VXD_Yield (yield_cont->yield_proc) ) -#else - if ( yield_cont->yield_proc(0xFFFF) ) -#endif - - { - status = ERR_CANCEL; - free( b ); - free( m ); - free( n ); - free( c ); - free( pp ); - free( P_buf ); - free (buf ); - return status; - } -#ifdef DEBUG1 - printf ("\n P is not pseudoprime"); -#endif - status = ERR_PRIME; - } - free( b ); - free( m ); - free( n ); - free( c ); - free( pp ); - free( P_buf ); - free (buf ); - return status; -} - -/**************************************************************************** -* NAME: int GenPrime( u_int16_t P_bytes, -* ord *P, -* u_int16_t k, -* ord *RVAL, -* YIELD_context *yield_cont ) -* -* DESCRIPTION: Generate Random Pseudo Prime number -* -* INPUTS: -* PARAMETERS: -* u_int16_t P_bytes Number of bytes in array -* u_int16_t k Number of testing -* ord *RVAL Pointer to random number generator value -* YIELD_context *yield_cont Pointer to yield_cont structure (NULL if not used) -* OUTPUT: -* PARAMETERS: -* ord *P Pointer to prime number -* ord *RVAL Pointer to updated value -* -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data(zero bytes) -* ERR_PRIME Number is not prime -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* 08 Dec 94 GKL Added YIELD_context -* -****************************************************************************/ - - int GenPrime( u_int16_t P_bytes, - ord *P, - u_int16_t k, - ord *RVAL, - YIELD_context *yield_cont ) /*TKL00601*/ -{ - int status = SUCCESS; /* function return status */ - if ( P_bytes % sizeof(ord) != 0 ) /* not multiple 4 (32 bit) */ - { - status = ERR_INPUT_LEN; /* invalid length for input data */ - return status; - } - do - { - MyGenRand( P_bytes, P, RVAL ); /* generate random number */ - P[0] |= 1; - P[(P_bytes/sizeof(ord))-1] |= ((ord)1 << (BITS_COUNT-1)); - status = VerPrime( P_bytes, P, k, RVAL, yield_cont); /*TKL00601*/ - } while ((status != SUCCESS) && (status != ERR_CANCEL)); /*TKL00601*/ - return status; -} - diff --git a/usr/src/lib/libresolv2/common/cylink/cylink.h b/usr/src/lib/libresolv2/common/cylink/cylink.h deleted file mode 100644 index 1ebbfbbd92..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/cylink.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/**********************************************************************\ -* FILENAME: cylink.h PRODUCT NAME: -* -* DESCRIPTION: Company standard include file -* -* USAGE: File should be #included -* -* -* Copyright (c) Cylink Corporation 1994. All rights reserved. -* -* REVISION HISTORY: -* -\**********************************************************************/ - -#ifndef CYLINK_H /* Prevent multiple inclusions of same header file */ -#define CYLINK_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <sys/param.h> -#if (!defined(BSD)) || (BSD < 199306) -# include <sys/bitypes.h> -#else -# include <sys/types.h> -#endif - -#if ! ( defined(__alpha) && defined(__osf__) ) /* in sys/types.h */ -#if !defined(_H_INTTYPES) && !defined (_H_TYPES) /* AIX puts this in inttypes.h */ -typedef unsigned char uchar; -#endif /* _H_INTTYPES */ -#endif - -typedef u_int16_t USHORT; -typedef u_int32_t ULONG; - -#define FALSE 0 -#define TRUE 1 - -/*-- ANSI-recommended NULL Pointer definition --*/ -#ifndef NULL -#define NULL (void *) 0 -#endif - -#endif /* CYLINK_H */ diff --git a/usr/src/lib/libresolv2/common/cylink/dss.c b/usr/src/lib/libresolv2/common/cylink/dss.c deleted file mode 100644 index fe907a6f21..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/dss.c +++ /dev/null @@ -1,1209 +0,0 @@ -/* - * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/**************************************************************************** -* FILENAME: dss.c PRODUCT NAME: CRYPTOGRAPHIC TOOLKIT -* -* FILE STATUS: -* -* DESCRIPTION: Cryptographic Toolkit Functions File -* Digital Signature Algorithms -* PUBLIC FUNCTIONS: -* uchar *RVAL ) -* int GenDSSKey( u_int16_t dss_p_bytes, uchar *dss_p, -* uchar *dss_q, uchar *dss_g, -* uchar *dss_x, uchar *dss_y, -* uchar *XKEY ) -* -* int GenDSSNumber( uchar *dss_k, uchar dss_q, -* uchar *KKEY ) -* int GenDSSParameters( u_int16_t dss_p_bytes, uchar *dss_p, -* uchar *dss_q, uchar *dss_g, -* uchar *RVAL ); -* -* Copyright (c) Cylink Corporation 1996. All rights reserved. -* -* REVISION HISTORY: -* -* -****************************************************************************/ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/**************************************************************************** -* INCLUDE FILES -****************************************************************************/ - -#include "port_before.h" -#include <sys/types.h> -#include "cylink.h" -#include "ctk_endian.h" - -/* system files */ -#ifdef VXD -#include <vtoolsc.h> -#else -#include <stdlib.h> -#include <string.h> -#endif - -/* program files */ -#ifdef VXD -#include "tkvxd.h" -#endif -#include "toolkit.h" -#include "cencrint.h" -#define INITIALIZ_PQG /*TKL01101*/ -#include "dssnum.h" /*TKL01101*/ -#include "sha.h" -#include "port_after.h" - -#define BEGIN_PROCESSING do { -#define END_PROCESSING } while (0); -#define ERROR_BREAK break -#define CONTINUE continue - -#define BEGIN_LOOP do { -#define END_LOOP } while (1); -#define BREAK break - - -extern u_int16_t DataOrder; - -/**************************************************************************** -* NAME: int GenDSSSignature( u_int16_t dss_p_bytes, -* uchar *dss_p, -* uchar *dss_q, -* uchar *dss_g, -* uchar *dss_x, -* uchar *dss_k, -* uchar *r, -* uchar *s, -* uchar *hash_result) -* -* DESCRIPTION: Compute a DSS Signature -* -* INPUTS: -* PARAMETERS: -* u_int16_t dss_p_bytes Length of dss_p -* uchar *dss_p Pointer to p prime -* uchar *dss_q Pointer to q prime -* uchar *dss_g Pointer to g -* uchar *dss_x Pointer to secret number -* uchar *dss_k Pointer to random secret number -* uchar *hash_result Pointer to message hashing result -* -* -* OUTPUT: -* PARAMETERS: -* uchar *r Pointer to r part of signature -* uchar *s Pointer to s part of signature -* -* RETURN: -* E_SUCCESS No errors -* E_DSS_LEN Invalid length for dss_p -* ERR_ALLOC Insufficient memory -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* 26 Oct 94 GKL (alignment for big endian support & ERR_ALLOC) -* 08 Dec 94 GKL Changed Expo call -* -****************************************************************************/ - -int GenDSSSignature( u_int16_t dss_p_bytes, - uchar *dss_p, - uchar *dss_q, - uchar *dss_g, - uchar *dss_x, - uchar *dss_k, - uchar *r, - uchar *s, - uchar *hash_result) - -{ - int status = SUCCESS; /* function return status */ - ord r_temp[DSS_LENGTH_MAX]; /* r intermidiate value */ - ord k_inverse[SHA_LENGTH+1]; - ord temp[SHA_LENGTH+1]; /* intermidiate values */ - ord *dss_p_a; - ord *dss_g_a; - ord *dss_q_a; - ord *dss_x_a; - ord *dss_k_a; - ord *hash_result_a; - ord *r_a; - ord *s_a; - - if ( (dss_p_bytes < DSS_LENGTH_MIN) || /* less than minimal */ - (dss_p_bytes > DSS_LENGTH_MAX) ) /* more than maximal */ - { - status = ERR_DSS_LEN; /* invalid length for dss_p */ - return status; - } - if ( dss_p_bytes & 0x07 ) /* not multiple 8 (64 bit)*/ - { - status = ERR_DSS_LEN; /* invalid length for dss_p */ - return status; - } - - if (DataOrder) - { - if (dss_p) - BigSwap(dss_p, dss_p_bytes); - if (dss_q) - BigSwap(dss_q, SHA_LENGTH); - if (dss_g) - BigSwap(dss_g, dss_p_bytes); - BigSwap(dss_x, SHA_LENGTH); - BigSwap(dss_k, SHA_LENGTH); - BigSwap(hash_result, SHA_LENGTH); - } - - DSS_G_ALIGN_CALLOC_COPY(dss_g, dss_g_a, dss_p_bytes); /*TKL01101*/ - DSS_P_ALIGN_CALLOC_COPY(dss_p, dss_p_a, dss_p_bytes); /*TKL01101*/ - DSS_Q_ALIGN_CALLOC_COPY(dss_q, dss_q_a, SHA_LENGTH); /*TKL01101*/ - - ALIGN_CALLOC_COPY(dss_x, dss_x_a, SHA_LENGTH); - ALIGN_CALLOC_COPY(dss_k, dss_k_a, SHA_LENGTH); - ALIGN_CALLOC_COPY(hash_result, hash_result_a, SHA_LENGTH); - ALIGN_CALLOC(r, r_a, SHA_LENGTH); - ALIGN_CALLOC(s, s_a, SHA_LENGTH); - if ( status != SUCCESS ) - { - if( dss_p_a ) - DSS_ALIGN_FREE(dss_p_a,dss_p); - if( dss_g_a ) - DSS_ALIGN_FREE(dss_g_a,dss_g); - if( dss_q_a ) - DSS_ALIGN_FREE(dss_q_a,dss_q); - if( dss_x_a ) - { - memset ( dss_x_a , 0 , SHA_LENGTH ); - ALIGN_FREE(dss_x_a); - } - if( dss_k_a ) - { - ALIGN_FREE(dss_k_a); - } - if( hash_result_a ) - { - ALIGN_FREE(hash_result_a); - } - if( r_a ) - { - ALIGN_COPY_FREE(r_a,r,SHA_LENGTH); - } - if( s_a ) - { - ALIGN_COPY_FREE(s_a,s,SHA_LENGTH); - } - if (DataOrder) - { - if (dss_p) - BigSwap(dss_p, dss_p_bytes); - if (dss_q) - BigSwap(dss_q, SHA_LENGTH); - if (dss_g) - BigSwap(dss_g, dss_p_bytes); - BigSwap(dss_x, SHA_LENGTH); - BigSwap(dss_k, SHA_LENGTH); - BigSwap(hash_result, SHA_LENGTH); - } - return status; /* ERR_ALLOC insufficient memory */ - } - -/* Compute DSS r value */ - BEGIN_PROCESSING - if (( status = Expo ( dss_p_bytes, - dss_g_a, - SHA_LENGTH, /* r_temp=(dss_g^dss_k)mod(dss_p)*/ - dss_k_a, - dss_p_bytes, - dss_p_a, - r_temp )) != SUCCESS ) - { - ERROR_BREAK; - } - if (( status = PartReduct ( dss_p_bytes, - r_temp, - SHA_LENGTH, /* r=(r_temp)mod(dss_q) */ - dss_q_a, - r_a )) != SUCCESS ) - { - ERROR_BREAK; - } -/* Compute k modulo inverse value */ - if (( status = Inverse( SHA_LENGTH, /* k_inverse=dss_k^(-1)mod(dss_q)*/ - dss_k_a, - SHA_LENGTH, - dss_q_a, - k_inverse )) != SUCCESS ) - { - ERROR_BREAK; - } -/* Compute DSS s value */ - if (( status = Mul ( SHA_LENGTH, /* temp=(dss_x*r)mod(dss_q) */ - dss_x_a, - SHA_LENGTH, - r_a, - SHA_LENGTH, - dss_q_a, - temp )) != SUCCESS ) - { - ERROR_BREAK; - } - - /* Add( temp, hash_result_a, - SHA_LENGTH, dss_q_a, temp ); temp=(temp+hash_result)mod(dss_q)*/ - - Add( temp, hash_result_a, - SHA_LENGTH, dss_q_a ); - if (( status = Mul ( SHA_LENGTH, /* s=(temp*k_inverse)mod(dss_q) */ - temp, - SHA_LENGTH, - k_inverse, - SHA_LENGTH, - dss_q_a, - s_a )) != SUCCESS ) - { - ERROR_BREAK; - } - END_PROCESSING - - DSS_ALIGN_FREE(dss_p_a,dss_p); /*TKL01101*/ - DSS_ALIGN_FREE(dss_g_a,dss_g); /*TKL01101*/ - DSS_ALIGN_FREE(dss_q_a,dss_q); /*TKL01101*/ - ALIGN_FREE(dss_x_a); - ALIGN_FREE(dss_k_a); - ALIGN_FREE(hash_result_a); - ALIGN_COPY_FREE(r_a,r,SHA_LENGTH); - ALIGN_COPY_FREE(s_a,s,SHA_LENGTH); - - if (DataOrder) - { - if (dss_p) - BigSwap(dss_p, dss_p_bytes); - if (dss_q) - BigSwap(dss_q, SHA_LENGTH); - if (dss_g) - BigSwap(dss_g, dss_p_bytes); - BigSwap(dss_x, SHA_LENGTH); - BigSwap(dss_k, SHA_LENGTH); - BigSwap(hash_result, SHA_LENGTH); - BigSwap(r, SHA_LENGTH); - BigSwap(s, SHA_LENGTH); - } - - return status; -} - -/**************************************************************************** -* NAME: int VerDSSSignature( u_int16_t dss_p_bytes, -* uchar *dss_p, -* uchar *dss_q, -* uchar *dss_g, -* uchar *dss_y, -* uchar *r, -* uchar *s, -* uchar *hash_result) -* -* DESCRIPTION: Verify a DSS Signature -* -* INPUTS: -* PARAMETERS: -* u_int16_t dss_p_bytes Length of dss_p -* uchar *dss_p Pointer to p prime -* uchar *dss_q Pointer to q prime -* uchar *dss_g Pointer to g -* uchar *dss_y Pointer to public number -* uchar *hash_result Pointer to message hashing result -* OUTPUT: -* PARAMETERS: -* -* RETURN: -* SUCCESS No errors -* ERR_SIGNATURE Signature is not valid -* ERR_DSS_LEN Invalid length for dss_p -* ERR_ALLOC Insufficient memory -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* 26 Oct 94 GKL (alignment for big endian support & ERR_ALLOC) -* 08 Dec 94 GKL Changed Expo call -* 21 Aug 96 AAB DoubleExpo call -****************************************************************************/ - -int VerDSSSignature( u_int16_t dss_p_bytes, - uchar *dss_p, - uchar *dss_q, - uchar *dss_g, - uchar *dss_y, - uchar *r, - uchar *s, - uchar *hash_result) -{ - int status = SUCCESS; /* function return status */ - ord w[(SHA_LENGTH / sizeof(ord)) + 1]; - ord u1[SHA_LENGTH / sizeof(ord)]; - ord u2[SHA_LENGTH / sizeof(ord)]; - ord *v; - ord *dss_p_a; - ord *dss_g_a; - ord *dss_q_a; - ord *dss_y_a; - ord *hash_result_a; - ord *r_a; - ord *s_a; - if ( (dss_p_bytes < DSS_LENGTH_MIN) || /* less than minimal */ - (dss_p_bytes > DSS_LENGTH_MAX) ) /* more than maximal */ - { - status = ERR_DSS_LEN; /* invalid length for dss_p */ - return status; - } - if ( dss_p_bytes & 0x07 ) /* not multiple 8 (64 bit)*/ - { - status = ERR_DSS_LEN; /* invalid length for dss_p */ - return status; - } - - if (DataOrder) - { - if (dss_p) - BigSwap(dss_p, dss_p_bytes); - if (dss_q) - BigSwap(dss_q, SHA_LENGTH); - if (dss_g) - BigSwap(dss_g, dss_p_bytes); - BigSwap(dss_y, dss_p_bytes); - BigSwap(hash_result, SHA_LENGTH); - BigSwap(r, SHA_LENGTH); - BigSwap(s, SHA_LENGTH); - } - - DSS_P_ALIGN_CALLOC_COPY(dss_p, dss_p_a, dss_p_bytes); /*TKL01101*/ - DSS_Q_ALIGN_CALLOC_COPY(dss_q, dss_q_a, SHA_LENGTH); /*TKL01101*/ - DSS_G_ALIGN_CALLOC_COPY(dss_g, dss_g_a, dss_p_bytes); /*TKL01101*/ - - ALIGN_CALLOC_COPY(dss_y, dss_y_a, dss_p_bytes); - ALIGN_CALLOC_COPY(hash_result, hash_result_a, SHA_LENGTH); - ALIGN_CALLOC_COPY(r, r_a, SHA_LENGTH); - ALIGN_CALLOC_COPY(s, s_a, SHA_LENGTH); - CALLOC(v,ord,dss_p_bytes); - - if ( status != SUCCESS ) - { - if( dss_p_a ) - { - DSS_ALIGN_FREE(dss_p_a,dss_p); - } - if( dss_g_a ) - { - DSS_ALIGN_FREE(dss_g_a,dss_g); - } - if ( dss_q_a ) - { - DSS_ALIGN_FREE(dss_q_a,dss_q); - } - if( dss_y_a ) - { - ALIGN_FREE(dss_y_a); - } - if( hash_result_a ) - { - ALIGN_FREE(hash_result_a); - } - if( r_a ) - { - ALIGN_FREE(r_a); - } - if( s_a ) - { - ALIGN_FREE(s_a); - } - if( v ) - { - free ( v ); - } - if (DataOrder) - { - if (dss_p) - BigSwap(dss_p, dss_p_bytes); - if (dss_q) - BigSwap(dss_q, SHA_LENGTH); - if (dss_g) - BigSwap(dss_g, dss_p_bytes); - BigSwap(dss_y, dss_p_bytes); - BigSwap(hash_result, SHA_LENGTH); - BigSwap(r, SHA_LENGTH); - BigSwap(s, SHA_LENGTH); - } - - return status; /* ERR_ALLOC insufficient memory */ - } - - BEGIN_PROCESSING - if (( status = Inverse( SHA_LENGTH, /* w=dss_k^(-1)mod(dss_q)*/ - s_a, - SHA_LENGTH, - dss_q_a, - w )) !=SUCCESS ) - { - ERROR_BREAK; - } - if (( status = Mul ( SHA_LENGTH, /* u1=(hash_result_*w)mod(dss_q) */ - hash_result_a, - SHA_LENGTH, - w, - SHA_LENGTH, - dss_q_a, - u1 )) != SUCCESS ) - { - ERROR_BREAK; - } - if (( status = Mul ( SHA_LENGTH, /* u2=(r*w)mod(dss_q) */ - r_a, - SHA_LENGTH, - w, - SHA_LENGTH, - dss_q_a, - u2 )) != SUCCESS ) - { - ERROR_BREAK; - } - /* v = dss_g_a^u1*dss_y_a^u2 moddss_p_a */ - if((status = DoubleExpo( dss_p_bytes, dss_g_a, - SHA_LENGTH, u1, - dss_p_bytes, dss_y_a, - SHA_LENGTH, u2, - dss_p_bytes, dss_p_a, v)) != SUCCESS ) - { - - ERROR_BREAK; - } - if (( status = PartReduct ( dss_p_bytes, /*v = v mod(dss_q)*/ - v, - SHA_LENGTH, - dss_q_a, - v )) != SUCCESS ) - { - ERROR_BREAK; - } - - if (( status = memcmp( r_a, v, SHA_LENGTH)) != 0) /*if v=r sign valid */ - { - status = ERR_SIGNATURE; /* signature is not valid */ - ERROR_BREAK; - } - END_PROCESSING - free ( v ); - DSS_ALIGN_FREE(dss_p_a,dss_p); /*TKL01101*/ - DSS_ALIGN_FREE(dss_g_a,dss_g); /*TKL01101*/ - DSS_ALIGN_FREE(dss_q_a,dss_q); /*TKL01101*/ - ALIGN_FREE(dss_y_a); - ALIGN_FREE(hash_result_a); - ALIGN_FREE(r_a); - ALIGN_FREE(s_a); - - if (DataOrder) - { - if (dss_p) - BigSwap(dss_p, dss_p_bytes); - if (dss_q) - BigSwap(dss_q, SHA_LENGTH); - if (dss_g) - BigSwap(dss_g, dss_p_bytes); - BigSwap(dss_y, dss_p_bytes); - BigSwap(hash_result, SHA_LENGTH); - BigSwap(r, SHA_LENGTH); - BigSwap(s, SHA_LENGTH); - } - - return status; -} - - -/**************************************************************************** -* NAME: int GenDSSKey( u_int16_t dss_p_bytes, -* uchar *dss_p, -* uchar *dss_q, -* uchar *dss_g, -* uchar *dss_x, -* uchar *dss_y, -* uchar *XKEY ) -* -* -* DESCRIPTION: Compute DSS public/secret number pair. -* -* INPUTS: -* PARAMETERS: -* u_int16_t dss_p_bytes Length of modulo -* uchar *dss_p Pointer to modulo -* uchar *dss_q Pointer to modulo -* uchar *dss_g Pointer to public key -* uchar *XKEY Pointer to user supplied random number -* -* -* OUTPUT: -* PARAMETERS: -* uchar *dss_x Pointer to secret key -* uchar *dss_y Pointer to public key -* uchar *XKEY Pointer to updated number -* -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data -* ERR_DATA Generic data error -* ERR_ALLOC Insufficient memory -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* 26 Oct 94 GKL (alignment for big endian support & ERR_ALLOC) -* 08 Dec 94 GKL Changed Expo call -* -****************************************************************************/ - -int GenDSSKey( u_int16_t dss_p_bytes, - uchar *dss_p, - uchar *dss_q, - uchar *dss_g, - uchar *dss_x, - uchar *dss_y, - uchar *XKEY ) -{ - - int status = SUCCESS; /* function return status */ - SHA_context hash_context; /* SHA context structure */ - uchar M[DSS_LENGTH_MIN]; /* message block */ - ord *dss_p_a; - ord *dss_q_a; - ord *dss_g_a; - ord *dss_x_a; - ord *dss_y_a; - ord *XKEY_a; - if ( (dss_p_bytes < DSS_LENGTH_MIN) || /* less than minimal */ - (dss_p_bytes > DSS_LENGTH_MAX) ) /* more than maximal */ - { - status = ERR_DSS_LEN; /* invalid length for dss_p */ - return status; - } - if ( dss_p_bytes & 0x07 ) /* not multiple 8 (64 bit)*/ - { - status = ERR_DSS_LEN; /* invalid length for dss_p */ - return status; - } - if (DataOrder) - { - if (dss_p) - BigSwap(dss_p, dss_p_bytes); - if (dss_q) - BigSwap(dss_q, SHA_LENGTH); - if (dss_g) - BigSwap(dss_g, dss_p_bytes); - } - - DSS_P_ALIGN_CALLOC_COPY(dss_p, dss_p_a, dss_p_bytes); /*TKL01101*/ - DSS_G_ALIGN_CALLOC_COPY(dss_g, dss_g_a, dss_p_bytes); /*TKL01101*/ - DSS_Q_ALIGN_CALLOC_COPY(dss_q, dss_q_a, SHA_LENGTH); /*TKL01101*/ - ALIGN_CALLOC(dss_x, dss_x_a, SHA_LENGTH); - ALIGN_CALLOC(dss_y, dss_y_a, dss_p_bytes); - if ( status != SUCCESS ) - { - if( dss_p_a ) - DSS_ALIGN_FREE(dss_p_a,dss_p); - if( dss_g_a ) - DSS_ALIGN_FREE(dss_g_a,dss_g); - if( dss_q_a ) - DSS_ALIGN_FREE(dss_q_a,dss_q); - if( dss_x_a ) - { - memset(dss_x_a, 0, SHA_LENGTH ); - ALIGN_COPY_FREE(dss_x_a,dss_x,SHA_LENGTH); - } - if( dss_y_a ) - { - ALIGN_COPY_FREE(dss_y_a,dss_y,dss_p_bytes); - } - - if (DataOrder) - { - if (dss_p) - BigSwap(dss_p, dss_p_bytes); - if (dss_q) - BigSwap(dss_q, SHA_LENGTH); - if (dss_g) - BigSwap(dss_g, dss_p_bytes); - } - return status; /* ERR_ALLOC insufficient memory */ - } - - BEGIN_PROCESSING - SHAInit ( &hash_context ); - memcpy( M, XKEY, SHA_LENGTH); - memset( M + SHA_LENGTH, 0, DSS_LENGTH_MIN - SHA_LENGTH ); - if ( (status = SHAUpdate( &hash_context, M, DSS_LENGTH_MIN )) - != SUCCESS ) - { - ERROR_BREAK; - } - if ( (status = MySHAFinal (&hash_context, (uchar *)dss_x_a)) != SUCCESS ) - { - ERROR_BREAK; - } - if (( status = PartReduct ( SHA_LENGTH, /* dss_x = dss_x mod(dss_q)*/ - dss_x_a, - SHA_LENGTH, - dss_q_a, - dss_x_a )) != SUCCESS ) - { - ERROR_BREAK; - } - - BigSwap(XKEY, SHA_LENGTH); - ALIGN_CALLOC_COPY(XKEY, XKEY_a, SHA_LENGTH); - if ( status != SUCCESS ) - { - if( XKEY_a ) - { - ALIGN_COPY_FREE(XKEY_a,XKEY,SHA_LENGTH); - BigSwap(XKEY, SHA_LENGTH); - return status; /* ERR_ALLOC insufficient memory */ - } - } - - Sum_Q((ord*)XKEY_a, 1, SHA_LENGTH / sizeof (ord) ); - - Sum_big( XKEY_a, dss_x_a, /* XKEY=XKEY+dss_x */ - XKEY_a, SHA_LENGTH / sizeof(ord) ); - - ALIGN_COPY_FREE(XKEY_a,XKEY,SHA_LENGTH); - BigSwap(XKEY, SHA_LENGTH); - - if (( status = Expo ( dss_p_bytes, /*dss_y = g^dss_x mod(dss_p)*/ - dss_g_a, - SHA_LENGTH, - dss_x_a, - dss_p_bytes, - dss_p_a, - dss_y_a)) != SUCCESS ) /*TKL00601*/ - { - ERROR_BREAK; - } - END_PROCESSING - - DSS_ALIGN_FREE(dss_p_a,dss_p); /*TKL01101*/ - DSS_ALIGN_FREE(dss_g_a,dss_g); /*TKL01101*/ - DSS_ALIGN_FREE(dss_q_a,dss_q); /*TKL01101*/ - ALIGN_COPY_FREE(dss_x_a,dss_x,SHA_LENGTH); - ALIGN_COPY_FREE(dss_y_a,dss_y,dss_p_bytes); - if (DataOrder) - { - if (dss_p) - BigSwap(dss_p, dss_p_bytes); - if (dss_q) - BigSwap(dss_q, SHA_LENGTH); - if (dss_g) - BigSwap(dss_g, dss_p_bytes); - BigSwap(dss_x, SHA_LENGTH); - BigSwap(dss_y, dss_p_bytes); - } - - return status; -} - - - -/**************************************************************************** -* NAME: int GenDSSNumber( uchar *dss_k, -* uchar *dss_q, -* uchar *KKEY ) -* -* DESCRIPTION: Generate secret number -* -* INPUTS: -* PARAMETERS: -* uchar *KKEY Pointer to input random number -* uchar *dss_q Pointer to modulo -* -* -* OUTPUT: -* PARAMETERS: -* uchar *dss_x Pointer to secret number -* uchar *KKEY Pointer to updated KKEY -* -* RETURN: -* SUCCESS No errors -* ERR_DATA Generic data error -* ERR_ALLOC Insufficient memory -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* 26 Oct 94 GKL (alignment for big endian support & ERR_ALLOC) -* -****************************************************************************/ - -int GenDSSNumber( uchar *dss_k, - uchar *dss_q, - uchar *KKEY ) -{ - - int status = SUCCESS; /* function return status */ - ord *dss_k_a; - ord *dss_q_a; - ord *KKEY_a; - SHA_context hash_context; /* SHA context structure*/ - uchar M[DSS_LENGTH_MIN]; /* message block */ - - if (DataOrder) - { - if (dss_q) - BigSwap(dss_q, SHA_LENGTH); - } - - DSS_Q_ALIGN_CALLOC_COPY(dss_q, dss_q_a, SHA_LENGTH); /*TKL01101*/ - ALIGN_CALLOC(dss_k, dss_k_a, SHA_LENGTH); - if ( status != SUCCESS ) - { - if( dss_q_a ) - DSS_ALIGN_FREE(dss_q_a,dss_q); - if( dss_k_a ) - { - ALIGN_COPY_FREE(dss_k_a,dss_k,SHA_LENGTH); - } - if (DataOrder) - { - if (dss_q) - BigSwap(dss_q, SHA_LENGTH); - } - return status; /* ERR_ALLOC insufficient memory */ - } - - BEGIN_PROCESSING - SHAInitK ( &hash_context ); - memcpy( M, KKEY, SHA_LENGTH); - memset( M + SHA_LENGTH, 0, DSS_LENGTH_MIN - SHA_LENGTH ); - if ( (status = SHAUpdate( &hash_context, M, DSS_LENGTH_MIN )) - != SUCCESS ) - { - ERROR_BREAK; - } - if ( (status = MySHAFinal (&hash_context, (uchar *)dss_k_a)) != SUCCESS ) - { - ERROR_BREAK; - } - if (( status = PartReduct ( SHA_LENGTH, /* dss_k = dss_k mod(dss_q)*/ - dss_k_a, - SHA_LENGTH, - dss_q_a, - dss_k_a )) != SUCCESS ) - { - ERROR_BREAK; - } - BigSwap(KKEY, SHA_LENGTH); - ALIGN_CALLOC_COPY(KKEY, KKEY_a, SHA_LENGTH ); - if ( status != SUCCESS ) - { - if ( KKEY_a ) - { - ALIGN_COPY_FREE(KKEY_a,KKEY,SHA_LENGTH); - BigSwap(KKEY, SHA_LENGTH); - } - return status; /* ERR_ALLOC insufficient memory */ - } - - Sum_Q( KKEY_a, 1, SHA_LENGTH / sizeof(ord)); - - Sum_big( KKEY_a, dss_k_a, /* KKEY=KKEY+dss_k*/ - KKEY_a, SHA_LENGTH / sizeof(ord) ); - - ALIGN_COPY_FREE(KKEY_a,KKEY,SHA_LENGTH); - BigSwap(KKEY, SHA_LENGTH); - - END_PROCESSING - - DSS_ALIGN_FREE(dss_q_a,dss_q); /*TKL01101*/ - - ALIGN_COPY_FREE(dss_k_a,dss_k,SHA_LENGTH); - if (DataOrder) - { - if (dss_q) - BigSwap(dss_q, SHA_LENGTH); - BigSwap(dss_k, SHA_LENGTH); - } - - return status; -} - - -/**************************************************************************** -* NAME: int GenDSSParameters( u_int16_t dss_p_bytes, -* uchar *dss_p, -* uchar *dss_q, -* uchar *dss_g, -* uchar *RVAL, -* YIELD_context *yield_cont ) -* -* DESCRIPTION: Generate DSS Common Parameters -* -* INPUTS: -* PARAMETERS: -* u_int16_t dss_p_bytes Number of bytes in dss_p -* uchar *RVAL Pointer to user supplied random number -* YIELD_context *yield_cont Pointer to yield_cont structure (NULL if not used) -* OUTPUT: -* PARAMETERS: -* uchar *dss_p Pointer to N-byte prime number -* uchar *dss_q Pointer to SHA_LENGTH prime number -* uchar *dss_g Pointer to N-byte number -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data(zero bytes) -* ERR_DSS_LEN; Invalid length for dss_p -* ERR_ALLOC Insufficient memory -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* 26 Oct 94 GKL (alignment for big endian support & ERR_ALLOC) -* 08 Dec 94 GKL Added YIELD_context -* -****************************************************************************/ - - int GenDSSParameters( u_int16_t dss_p_bytes, - uchar *dss_p, - uchar *dss_q, - uchar *dss_g, - uchar *RVAL, - YIELD_context *yield_cont ) /*TKL00701*/ -{ - int status = SUCCESS; /* function return status */ - ord seed[SHA_LENGTH / sizeof (ord)]; - ord u[SHA_LENGTH / sizeof (ord)]; /* work buffers */ - ord u1[SHA_LENGTH / sizeof (ord)]; - ord *dss_p_a; - ord *dss_q_a; - ord *dss_g_a; - ord *RVAL_a; - ord ofone[SHA_LENGTH / sizeof(ord)]; - ord dss_q2[SHA_LENGTH / sizeof(ord) + 1]; /* dss_q2 = 2 * q */ - ord v[SHA_LENGTH / sizeof(ord)]; - ord *w, *c, *c1, *one, *e; /* Pointers to work buffers */ - u_int16_t i, n, count, offset, k; /* counters */ - u_int16_t dss_p_longs; /* number of longs */ - if ( dss_p_bytes == 0 ) /* invalid length for input data (zero bytes) */ - { - status = ERR_INPUT_LEN; - return status; - } - if ( (dss_p_bytes < DSS_LENGTH_MIN) || /* less than minimal */ - (dss_p_bytes > DSS_LENGTH_MAX) ) /* more than maximal */ - { - status = ERR_DSS_LEN; /* invalid length for dss_p */ - return status; - } - if ( dss_p_bytes & 0x07 ) /* not multiple 4 (64 bit)*/ - { - status = ERR_DSS_LEN; /* invalid length for dss_p */ - return status; - } - - n = (u_int16_t) (dss_p_bytes / SHA_LENGTH); /* SHA passes count */ - dss_p_longs = (u_int16_t) (dss_p_bytes / sizeof(ord)); /* number of long in dss_p */ - CALLOC(w, ord, (n + 1) * SHA_LENGTH); - CALLOC(c, ord, dss_p_bytes); - CALLOC(c1, ord, dss_p_bytes); - CALLOC(one, ord, dss_p_bytes); - CALLOC(e,ord, dss_p_bytes - SHA_LENGTH + sizeof(ord)); - ALIGN_CALLOC_MOVE(RVAL, RVAL_a, SHA_LENGTH); - ALIGN_CALLOC(dss_p, dss_p_a, dss_p_bytes); - ALIGN_CALLOC(dss_q, dss_q_a, SHA_LENGTH); - ALIGN_CALLOC(dss_g, dss_g_a, dss_p_bytes); - if ( status != SUCCESS ) - { - if( e ) - free ( e ); - if( one ) - free ( one ); - if( c ) - free ( c ); - if( w ) - free ( w ); - if( c1 ) - free ( c1 ); - if( dss_p_a ) - { - ALIGN_COPY_FREE(dss_p_a, dss_p, dss_p_bytes); - } - if( dss_q_a ) - { - ALIGN_COPY_FREE(dss_q_a, dss_q, SHA_LENGTH); - } - if( dss_g_a ) - { - ALIGN_COPY_FREE(dss_g_a, dss_g, dss_p_bytes); - } - if( RVAL_a ) - { - ALIGN_MOVE_FREE(RVAL_a, RVAL, SHA_LENGTH); - } - return status; /* ERR_ALLOC insufficient memory */ - } - one[0] = 1; - BEGIN_PROCESSING /* Generate DSS Common Parameters */ - - BEGIN_LOOP /* Generate prime & dss_p */ /*TKL00501*/ - /* generate prime number of length 160-bit */ - do - { - MyGenRand( SHA_LENGTH, seed, RVAL_a); /* generate random number */ - /* compute message digest from seed */ - if ( (status = MySHA((uchar *)seed, SHA_LENGTH, (uchar *)u)) != SUCCESS ) - { - break; /* error */ - } - memcpy(ofone, seed,SHA_LENGTH); - Sum_Q( ofone, 1, SHA_LENGTH / sizeof(ord) ); - /* compute message digest from seed */ - if ( (status = MySHA( (uchar *)ofone, SHA_LENGTH,(uchar *)dss_q_a)) != SUCCESS ) - { - break; /* error */ - } - - for ( i = 0; i < (SHA_LENGTH / sizeof(ord)); i++ ) /* dss_q = dss_q ^ u */ - { - dss_q_a[i] = dss_q_a[i] ^ u[i]; - } - /* set least and most significant bits */ - dss_q_a[SHA_LENGTH / sizeof(ord) - 1] |= ((ord)1 << (BITS_COUNT-1)); - dss_q_a[0] |= 0x01; - } while ( VerPrime( SHA_LENGTH, dss_q_a, TEST_COUNT, RVAL_a, yield_cont) /*TKL00701*/ - != SUCCESS ); /* perform a robust primality test */ - if (status != SUCCESS ) - { - ERROR_BREAK; - } - /* dss_q2 = 2 * dss_q */ - memcpy( dss_q2, dss_q_a, SHA_LENGTH ); - dss_q2[SHA_LENGTH / sizeof(ord)] = 0; - LShiftL_big( dss_q2, SHA_LENGTH / sizeof(ord) +1, 1 ); - count = 0; - offset = 2; - memset( ofone, 0, SHA_LENGTH ); - do /* find dss_p */ - { - /* generate random number by dss_p bytes */ - for ( k = 0; k <= n; k++ ) - { - ofone[0] = offset + k; - /* v = ofone + seed */ - Sum_big( seed, ofone, v, SHA_LENGTH / sizeof(ord) ); - if ( (status = MySHA ( (uchar *)v, SHA_LENGTH, - (uchar *)( w + (SHA_LENGTH / sizeof(ord)) * k ))) - != SUCCESS ) /* compute message digest */ - { - break; /* error */ - } - } - if (status != SUCCESS ) - { - break; /* error */ - } - /* set most significant bit */ - w[dss_p_longs - 1] |= ((ord)1 << (BITS_COUNT-1)); - memcpy( c, w, dss_p_bytes); - /* c1 = c mod(dss_q2) */ - if( (status = PartReduct( dss_p_bytes, c, - SHA_LENGTH + sizeof(ord), - dss_q2, c1)) != SUCCESS ) - { - break; /* error */ - } - /* c1 = c1 - 1*/ - Sub_big( c1, one, c1, dss_p_longs ); - /* dss_p = w - c1 */ - Sub_big( w, c1, dss_p_a, dss_p_longs ); - if ( dss_p_a[dss_p_bytes / sizeof(ord) - 1] >= (ord)((ord)1 << (BITS_COUNT-1)) ) - { - if ( VerPrime ( dss_p_bytes, dss_p_a, TEST_COUNT, RVAL_a, yield_cont) /*TKL00701*/ - == SUCCESS ) /* perform a robust primality test */ - { - break; - } - } - count++; - offset = (u_int16_t) (offset + n + 1); - } while ( count < 4096); - if (status != SUCCESS ) - { - ERROR_BREAK; - } - if (count != 4096) /*TKL00501*/ - { - BREAK; /*TKL00501*/ - } - END_LOOP /* Generate dss_p */ /*TKL00501*/ - - if (status != SUCCESS ) - { - ERROR_BREAK; - } - dss_p_a[0] -= 1; /* dss_p = dss_p - 1 */ - if ( (status= DivRem (dss_p_bytes, dss_p_a, SHA_LENGTH, dss_q_a, u1, - e )) != SUCCESS ) /* e = dss_p / dss_q */ - { - ERROR_BREAK; - } - dss_p_a[0] += 1; /* dss_p = dss_p + 1 */ - - BEGIN_LOOP /* Generate dss_g */ /*TKL00501*/ - MyGenRand( SHA_LENGTH, u, RVAL_a ); /*generate random number*/ - u[SHA_LENGTH / sizeof(ord) - 1] &= ~((ord)1 << (BITS_COUNT-1)); /* u < dss_q */ - if ( (status = Expo( SHA_LENGTH, u, (u_int16_t)(dss_p_bytes - SHA_LENGTH + - sizeof(ord)), e, dss_p_bytes, dss_p_a, dss_g_a )) - != SUCCESS ) /* dss_g = e ^ u mod(dss_p) */ - { - ERROR_BREAK; - } - if ( dss_g_a[0] == 1 ) /* check dss_g == 1 */ - { - for ( i = 1; i < (dss_p_bytes / sizeof(ord)); i++ ) - { - if ( dss_g_a[i] != 0 ) - { - break; - } - } - if ( i == (dss_p_bytes / sizeof(ord)) ) - { - CONTINUE; - } - } - BREAK; /*TKL00501*/ - END_LOOP /* Generate dss_g */ /*TKL00501*/ - END_PROCESSING /* Generate DSS Common Parameters */ - free ( e ); - free ( one ); - free ( c ); - free ( w ); - free ( c1 ); - ALIGN_COPY_FREE(dss_p_a, dss_p, dss_p_bytes); - ALIGN_COPY_FREE(dss_q_a, dss_q, SHA_LENGTH); - ALIGN_COPY_FREE(dss_g_a, dss_g, dss_p_bytes); - ALIGN_MOVE_FREE(RVAL_a, RVAL, SHA_LENGTH); - if (DataOrder) - { - BigSwap(dss_p, dss_p_bytes); - BigSwap(dss_q, SHA_LENGTH); - BigSwap(dss_g, dss_p_bytes); - } - return status; -} - - -/**************************************************************************** -* NAME: int GetDSSPQG(u_int16_t dss_p_bytes, -* uchar *dss_p, -* uchar *dss_q, -* uchar *dss_g) -* -* DESCRIPTION: Copy Cylink DSS P,Q,G numbers to *dss_p,*dss_q,*dss_g -* -* INPUTS: -* PARAMETERS: -* u_int16_t dss_p_bytes Number of bytes in dss_p -* uchar *dss_p Pointer to N-byte buffer -* uchar *dss_q Pointer to SHA_LENGTH-byte buffer -* uchar *dss_g Pointer to N-byte buffer -* OUTPUT: -* RETURN: -* SUCCESS No errors -* ERR_DSS_LEN; Invalid length for dss_p -* REVISION HISTORY: -* -* 22 Apr 95 GKL Initial release LOG TKL01201 -* -****************************************************************************/ -int GetDSSPQG(u_int16_t dss_p_bytes, - uchar *dss_p, - uchar *dss_q, - uchar *dss_g) -{ - int status = SUCCESS; /* function return status */ - ord *dss_p_a; - ord *dss_g_a; - - if ( (dss_p_bytes < DSS_LENGTH_MIN) || /* less than minimal */ - (dss_p_bytes > DSS_LENGTH_MAX) ) /* more than maximal */ - { - status = ERR_DSS_LEN; /* invalid length for dss_p */ - return status; - } - if ( dss_p_bytes & 0x07 ) /* not multiple 8 (64 bit)*/ - { - status = ERR_DSS_LEN; /* invalid length for dss_p */ - return status; - } - dss_p_a = &DSS_P_NUMBERS[DSS_NUM_INDEX[(dss_p_bytes-DSS_LENGTH_MIN)/LENGTH_STEP]]; - dss_g_a = &DSS_G_NUMBERS[DSS_NUM_INDEX[(dss_p_bytes-DSS_LENGTH_MIN)/LENGTH_STEP]]; - OrdByte(dss_p_a,dss_p_bytes,dss_p); - OrdByte(dss_g_a,dss_p_bytes,dss_g); - OrdByte(DSS_Q_NUMBER,SHA_LENGTH,dss_q); - if (DataOrder) - { - BigSwap(dss_p, dss_p_bytes); - BigSwap(dss_q, SHA_LENGTH); - BigSwap(dss_g, dss_p_bytes); - } - - return status; -} - - diff --git a/usr/src/lib/libresolv2/common/cylink/dssnum.h b/usr/src/lib/libresolv2/common/cylink/dssnum.h deleted file mode 100644 index f46f08fe61..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/dssnum.h +++ /dev/null @@ -1,731 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/**********************************************************************\ -* FILENAME: DSSNum.h PRODUCT NAME: CRYPTOGRAPHIC TOOLKIT -* -* DESCRIPTION: Standard Cylink DSS numbers (P Q G) support. -* -* USAGE: File should be included to get access to -* Cylink DSS numbers -* -* -* Copyright (c) Cylink Corporation 1995. All rights reserved. -* -* REVISION HISTORY: -* 10 APR 95 GKL Initial release -* -\**********************************************************************/ -#ifndef DSSNUMBER_H /* Prevent multiple inclusions */ -#define DSSNUMBER_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "ctk_endian.h" - -#define LENGTH_MULT_TO_64 - -#define F0 0 -#define F1 (F0 + 1) -#define F2 (F1 + 2) -#define F3 (F2 + 3) -#define F4 (F3 + 4) -#define F5 (F4 + 5) -#define F6 (F5 + 6) -#define F7 (F6 + 7) -#define F8 (F7 + 8) -#define F9 (F8 + 9) -#define F10 (F9 + 10) -#define F11 (F10 + 11) -#define F12 (F11 + 12) -#define F13 (F12 + 13) -#define F14 (F13 + 14) -#define F15 (F14 + 15) - - -#ifdef LENGTH_MULT_TO_64 -#define LENGTH_STEP 8U -#define LAST_F F8 -#endif - -#ifdef LENGTH_MULT_TO_32 -#define LENGTH_STEP 4U -#define LAST_F (F15 + 16) -#endif - - -#define DSS_LENS_NUMBER (int) (1 + ( DSS_LENGTH_MAX - DSS_LENGTH_MIN )/LENGTH_STEP) - -#define DSS_LAST_INDEX (DSS_LENGTH_MIN*DSS_LENS_NUMBER + LENGTH_STEP*LAST_F)/sizeof(ord) - -#ifndef INITIALIZ_PQG - -extern ushort DSS_NUM_INDEX[ DSS_LENS_NUMBER ]; -extern ord DSS_Q_NUMBER[SHA_LENGTH/sizeof(ord)]; -extern ord DSS_P_NUMBERS[DSS_LAST_INDEX]; -extern ord DSS_G_NUMBERS[DSS_LAST_INDEX]; - -#else -ushort DSS_NUM_INDEX[ DSS_LENS_NUMBER ] = -{ - (DSS_LENGTH_MIN*0 + LENGTH_STEP*0 )/sizeof(ord), - (DSS_LENGTH_MIN*1 + LENGTH_STEP*F0 )/sizeof(ord), - (DSS_LENGTH_MIN*2 + LENGTH_STEP*F1 )/sizeof(ord), - (DSS_LENGTH_MIN*3 + LENGTH_STEP*F2 )/sizeof(ord), - (DSS_LENGTH_MIN*4 + LENGTH_STEP*F3 )/sizeof(ord), - (DSS_LENGTH_MIN*5 + LENGTH_STEP*F4 )/sizeof(ord), - (DSS_LENGTH_MIN*6 + LENGTH_STEP*F5 )/sizeof(ord), - (DSS_LENGTH_MIN*7 + LENGTH_STEP*F6 )/sizeof(ord), - (DSS_LENGTH_MIN*8 + LENGTH_STEP*F7 )/sizeof(ord) -#ifdef LENGTH_MULT_TO_32 - , - (DSS_LENGTH_MIN*9 + LENGTH_STEP*F8 )/sizeof(ord), - (DSS_LENGTH_MIN*10 + LENGTH_STEP*F9 )/sizeof(ord), - (DSS_LENGTH_MIN*11 + LENGTH_STEP*F10)/sizeof(ord), - (DSS_LENGTH_MIN*12 + LENGTH_STEP*F11)/sizeof(ord), - (DSS_LENGTH_MIN*13 + LENGTH_STEP*F12)/sizeof(ord), - (DSS_LENGTH_MIN*14 + LENGTH_STEP*F13)/sizeof(ord), - (DSS_LENGTH_MIN*15 + LENGTH_STEP*F14)/sizeof(ord), - (DSS_LENGTH_MIN*16 + LENGTH_STEP*F15)/sizeof(ord) -#endif -}; - -ord DSS_Q_NUMBER[SHA_LENGTH/sizeof(ord)] = -#ifdef ORD_16 - { - 0x8fb7, 0x81f0, 0x6b9e, 0x122a, 0x4dc4, 0x03ca, 0xc896, 0x8d0e, 0xbe3b, 0xed4b - }; -#else - { - 0x81f08fb7L, 0x122a6b9eL, 0x03ca4dc4L, 0x8d0ec896L, 0xed4bbe3bL - }; -#endif - - -ord DSS_P_NUMBERS[DSS_LAST_INDEX] = -#ifdef ORD_16 - { - /* dss_p length = 512*/ - 0x92b7, 0xbd96, 0x9aab, 0x584c, 0xd617, 0xf2f0, 0xda85, 0xd370, - 0xcc82, 0x273e, 0x6b04, 0xc171, 0x5c32, 0xd3ff, 0x352e, 0xf2f8, - 0x4fc2, 0x20bc, 0xbdec, 0xe96e, 0x3503, 0x4d89, 0xe92d, 0xeb7d, - 0x9c1a, 0x7852, 0xfe2a, 0x0a25, 0x4446, 0xce18, 0x7829, 0x95d8, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 544*/ - 0x12db, 0x0d31, 0x9950, 0x16c9, 0x3045, 0x0acb, 0x3c46, 0x3c5c, - 0x6c94, 0x2458, 0x0736, 0x13da, 0xa0af, 0x790f, 0xb177, 0xa6ae, - 0xd111, 0x2bda, 0x697c, 0x49a2, 0xe3e5, 0x6f27, 0x02f5, 0x9bc9, - 0xd4da, 0x7d9b, 0x89c6, 0x63bc, 0x0b6d, 0xfe2d, 0xc7a1, 0x435f, - 0x7fad, 0x9e40, -#endif - /* dss_p length = 576*/ - 0x626b, 0x41b5, 0xd218, 0x25bf, 0x1825, 0x42b3, 0x9eb0, 0xc244, - 0x96ce, 0x22ac, 0x3ac6, 0x713f, 0x321d, 0x398c, 0x3022, 0xbc49, - 0xdd03, 0x52d5, 0x29f8, 0x2a57, 0x8fa1, 0x2173, 0xee7d, 0xb90d, - 0xcc64, 0x5fae, 0xaa81, 0xe3d0, 0x648f, 0xfa6e, 0xdc6c, 0x039f, - 0x2cd6, 0xc552, 0xe2dc, 0xebec, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 608*/ - 0x35f5, 0xb2af, 0x27d0, 0x398b, 0x493d, 0x6f2e, 0xbe27, 0xe5b5, - 0x972c, 0x3470, 0x9638, 0xe90e, 0xf7b7, 0x98ad, 0xd091, 0xb4ca, - 0x3f43, 0x5f58, 0xb6c5, 0xd014, 0x25ee, 0x414d, 0xe2c1, 0x6fd6, - 0xd737, 0x9be6, 0x66ca, 0xe241, 0x1897, 0xf740, 0xe5df, 0xceb0, - 0xdb38, 0xabc8, 0x8af8, 0xc58b, 0xc6a0, 0x9a04, -#endif - /* dss_p length = 640*/ - 0x4095, 0xf6bf, 0x7568, 0x4032, 0x5c0f, 0x64f2, 0x5aae, 0xb099, - 0x346f, 0x0e81, 0x357a, 0x7aeb, 0x0291, 0xfd0a, 0x8d54, 0xce80, - 0x0c05, 0xbea3, 0x889f, 0x8a1b, 0xf1c1, 0x6049, 0x214a, 0x8ec3, - 0xb926, 0xdde1, 0x61b4, 0x384e, 0x404b, 0xb6d7, 0x2e2d, 0x4584, - 0xae6a, 0xcc7a, 0x7bfa, 0x9eb0, 0x3a26, 0x3904, 0x8cac, 0xc036, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 672*/ - 0x0abb, 0xaea3, 0xc749, 0x757c, 0x3035, 0x29d0, 0x46bd, 0xd56c, - 0xf49d, 0xa355, 0x1297, 0x8dcb, 0x9802, 0xc58c, 0xf1ec, 0x8aac, - 0x55dd, 0xb107, 0x0140, 0x26d1, 0x8a5d, 0x8a90, 0xf33e, 0xde0b, - 0xb844, 0xb429, 0x4db2, 0x9806, 0xf629, 0x4c3b, 0xcd76, 0x2f23, - 0x6c68, 0x7bf4, 0x2a7e, 0xd982, 0xc89f, 0x16a2, 0xfe84, 0x953c, - 0x3e4a, 0x8de8, -#endif - /* dss_p length = 704*/ - 0x0113, 0x1535, 0xca0b, 0x8faf, 0xa327, 0x989c, 0x12c8, 0xe512, - 0x796f, 0x1229, 0x12bf, 0x62c8, 0xa50a, 0x2b99, 0xc93b, 0x450c, - 0x71ad, 0x0826, 0xf4c6, 0x3913, 0x9b6e, 0x96da, 0xa08d, 0xbc5e, - 0xd4d3, 0x7b26, 0xf9fd, 0xdd76, 0x4e82, 0x2f06, 0x1f96, 0xbf47, - 0xcadf, 0x3610, 0x917b, 0x4e94, 0xe2e8, 0x0eaf, 0x1cb9, 0x6b90, - 0xb917, 0x6d6f, 0x92b9, 0xb329, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 736*/ - 0x6dad, 0xd878, 0xc913, 0xe61e, 0x87d9, 0xe275, 0xad24, 0xf090, - 0xe12b, 0xfdfe, 0x39a3, 0xc9a1, 0x8330, 0x138a, 0x4bed, 0xc319, - 0x8094, 0x88ba, 0x4b80, 0x1325, 0x7852, 0x67e2, 0x715e, 0x7313, - 0x3b4e, 0x7727, 0x9870, 0x5c6e, 0xe0ce, 0xc67a, 0xd057, 0xf3c5, - 0x55ea, 0x98ba, 0x6ea0, 0xaee7, 0x31e8, 0x3cd6, 0x0e28, 0x42d1, - 0x8946, 0xc395, 0x34fc, 0x1b9d, 0x19d1, 0x86f9, -#endif - /* dss_p length = 768*/ - 0xe293, 0xea08, 0xcdd0, 0xf668, 0x8b2a, 0x06db, 0x7c71, 0xadb2, - 0x943d, 0x6721, 0x54f5, 0xbc44, 0xf7ca, 0x3345, 0x1bf6, 0x0b90, - 0xb475, 0xd3c4, 0xbdb6, 0x7caa, 0xa45f, 0xe9b4, 0x6e0e, 0x0c1a, - 0xb5c3, 0x9760, 0x851a, 0x53af, 0x96b7, 0x4979, 0xf162, 0xe951, - 0x6a54, 0xd020, 0x9ded, 0xdecb, 0xfc81, 0x7d74, 0x5e92, 0x2aee, - 0x0946, 0x0eb5, 0x3700, 0x9bce, 0x845a, 0xa7a3, 0x157a, 0x8618, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 800*/ - 0xb0a1, 0xac27, 0xec4e, 0xf623, 0x55e2, 0x2cb6, 0x288b, 0x4b28, - 0xd74e, 0xbbe6, 0xfdf7, 0xaecd, 0x5758, 0xe251, 0x9074, 0x1aee, - 0xe6ed, 0x4d5e, 0x01d9, 0x529e, 0xf736, 0x0091, 0x0212, 0xc725, - 0x60ce, 0x966f, 0x851d, 0x5c4b, 0x80de, 0x34df, 0x1c88, 0x0636, - 0xbb71, 0x32ce, 0x45cb, 0x86da, 0x4d0e, 0x13e0, 0x7d7d, 0x544b, - 0x1272, 0x747f, 0xd6a7, 0xfa3b, 0xcb86, 0x6b43, 0x66f5, 0xd012, - 0xfe7a, 0xa0cb, -#endif - /* dss_p length = 832*/ - 0xed2d, 0x84dd, 0xf274, 0xdd8f, 0xcd5f, 0x7928, 0xbfc6, 0xa522, - 0xe4e4, 0x50f0, 0xcddf, 0x5842, 0xbb29, 0x7c4d, 0xeef4, 0x6946, - 0x87f6, 0xe486, 0x61b5, 0xc1b6, 0xadef, 0x575a, 0x360f, 0x724f, - 0xcb29, 0x591b, 0x9a4c, 0xf7bc, 0x309e, 0xa348, 0x0ff5, 0x94f3, - 0x932f, 0x9dc6, 0x992c, 0xc6d7, 0x12f6, 0xc2d7, 0x38aa, 0x8c01, - 0x5dca, 0x74f4, 0xfcfd, 0x4cf4, 0x588a, 0x7837, 0x097e, 0xd2e2, - 0x6eac, 0x8869, 0xe92f, 0xec62, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 864*/ - 0x7c21, 0x931e, 0x553d, 0x00f2, 0xa860, 0x940f, 0x411e, 0x7d20, - 0xb168, 0x52a3, 0x69ee, 0x166e, 0xb9e6, 0x1b23, 0xd5e0, 0xef64, - 0x2850, 0x724c, 0xc1fe, 0xea73, 0xda8c, 0xe342, 0x1d7b, 0xd256, - 0x359b, 0x180f, 0xd7f5, 0xca77, 0x06ac, 0x2162, 0xa977, 0x78bb, - 0x5018, 0x5de2, 0x6061, 0xe217, 0x4d42, 0xfed1, 0x3929, 0xd50f, - 0xc946, 0x2433, 0x15f8, 0x361b, 0xbf51, 0x3ff0, 0x3efa, 0x3157, - 0x7350, 0x53a0, 0xd1a4, 0x261b, 0xde5b, 0x9236, -#endif - /* dss_p length = 896*/ - 0x8e21, 0x0364, 0x86d2, 0xe58c, 0x2274, 0x780a, 0x9ffc, 0x4951, - 0x3f99, 0xbc96, 0x9e60, 0x5a7e, 0x010a, 0x23d4, 0x54d1, 0x48e9, - 0xfd6b, 0x979c, 0x5202, 0x8af3, 0x5d87, 0xfe8f, 0x3e3c, 0x1e0c, - 0xe294, 0xcc52, 0xa8d6, 0x480e, 0xa898, 0xd4ce, 0x5949, 0xd341, - 0xe325, 0xf41b, 0x72d6, 0x6a90, 0x7a8b, 0x6f14, 0x3e2b, 0x6636, - 0x3748, 0x4eea, 0xa590, 0x03e4, 0x0524, 0x9c32, 0xeb53, 0x02af, - 0xca71, 0x6792, 0xd673, 0xedf8, 0x6448, 0x59c3, 0x7319, 0x883f, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 928*/ - 0xc17d, 0xa4e8, 0xea08, 0x8ff8, 0x2cb0, 0x73f5, 0xd7ba, 0xc027, - 0xb9c8, 0x989d, 0xe5fe, 0xe3a1, 0xf324, 0x39d3, 0xf142, 0x5ba8, - 0xe6cb, 0x3708, 0xa0b7, 0xed9a, 0xb6b3, 0xe314, 0xf80a, 0x6778, - 0x4d27, 0x7107, 0x6ee8, 0xb9c2, 0xc6af, 0xab70, 0x53be, 0xc445, - 0x7926, 0x34bb, 0x5191, 0xe11d, 0x67f1, 0xcc3a, 0x5354, 0xd34d, - 0xa1ac, 0x08ba, 0x32d4, 0x068a, 0x7c3b, 0x415f, 0xbce0, 0xb549, - 0x0ecf, 0x538f, 0xb5d0, 0x22a3, 0x1d47, 0xe837, 0x14c0, 0x69dd, - 0xa02d, 0xce91, -#endif - /* dss_p length = 960*/ - 0x1ff3, 0xf77e, 0xae7a, 0x5a28, 0x43b1, 0xe187, 0x2e04, 0xb3ea, - 0x7394, 0xa3e8, 0x4985, 0xc9bc, 0x7b7d, 0x1e1c, 0xd99c, 0x55f8, - 0x447b, 0x5704, 0xd758, 0xbed1, 0xe698, 0x2a5e, 0x5c19, 0xc206, - 0x6d38, 0x1f88, 0x2ea4, 0x5f15, 0xebfd, 0xd716, 0x8a2a, 0xf960, - 0x83ac, 0xc493, 0xb966, 0x8f13, 0x4778, 0x9682, 0x4712, 0x84cd, - 0xbb4e, 0xe567, 0x644f, 0x0780, 0x133d, 0x0b0a, 0xe42e, 0x06e8, - 0xa4cc, 0x3131, 0x39d9, 0xfaf8, 0x12a3, 0x5550, 0x43b1, 0xb8a9, - 0xb0eb, 0x0fad, 0x986f, 0xd427, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 992*/ - 0xbcfd, 0x363f, 0x050a, 0x18f0, 0x78d8, 0xcac9, 0x423a, 0xf31e, - 0x198f, 0xd0c3, 0xb319, 0x5d1b, 0x917a, 0xc0b0, 0x8d1b, 0x6b91, - 0xea69, 0xa9d1, 0x02ce, 0x5345, 0x2c80, 0x6992, 0x4dad, 0x7a28, - 0xbb75, 0xd46d, 0x0faa, 0x5612, 0x6878, 0x8a0e, 0x63b4, 0x46ab, - 0xaca0, 0x5381, 0xb90a, 0x3e70, 0x19c4, 0xb639, 0xf778, 0xe751, - 0x5974, 0xb726, 0x589f, 0x8679, 0xeb04, 0xc0b5, 0xdffd, 0x2b32, - 0x4b51, 0xc632, 0xd8c6, 0x9501, 0x4f94, 0x2026, 0x253a, 0x0d27, - 0x07bb, 0x0838, 0x2725, 0xa3eb, 0x3c4e, 0x89b6, -#endif - /* dss_p length = 1024*/ - 0xa141, 0xecf7, 0xc6d6, 0x867d, 0xefa3, 0x1cdd, 0x6c9d, 0x6ca5, - 0x2e2f, 0x68af, 0x90e1, 0x1d3e, 0xd75f, 0x0c2a, 0x844b, 0x36c7, - 0x3420, 0xfd1a, 0xb9ee, 0xf6e5, 0x5fde, 0xc8ed, 0x0c90, 0xd353, - 0x6faa, 0x80a4, 0x5bbd, 0xa59d, 0x9e72, 0x3223, 0x8f59, 0xf33d, - 0x10eb, 0xeccd, 0x184e, 0x3e2a, 0x4c07, 0x564b, 0x4c0a, 0x3263, - 0xc535, 0x8aeb, 0xf982, 0x2be2, 0xe475, 0x9b87, 0xcca0, 0x4d08, - 0x3adf, 0x0484, 0xd528, 0x7acd, 0x304d, 0x55a0, 0x70ae, 0x8298, - 0x6a7a, 0x2298, 0x15c0, 0x7a86, 0x7fc5, 0x654a, 0x14ad, 0xd0aa - }; -#else - { -/* dss_p length = 512*/ - 0xbd9692b7L, 0x584c9aabL, 0xf2f0d617L, 0xd370da85L, - 0x273ecc82L, 0xc1716b04L, 0xd3ff5c32L, 0xf2f8352eL, - 0x20bc4fc2L, 0xe96ebdecL, 0x4d893503L, 0xeb7de92dL, - 0x78529c1aL, 0x0a25fe2aL, 0xce184446L, 0x95d87829L, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 544*/ - 0x0d3112dbL, 0x16c99950L, 0x0acb3045L, 0x3c5c3c46L, - 0x24586c94L, 0x13da0736L, 0x790fa0afL, 0xa6aeb177L, - 0x2bdad111L, 0x49a2697cL, 0x6f27e3e5L, 0x9bc902f5L, - 0x7d9bd4daL, 0x63bc89c6L, 0xfe2d0b6dL, 0x435fc7a1L, - 0x9e407fadL, -#endif - /* dss_p length = 576*/ - 0x41b5626bL, 0x25bfd218L, 0x42b31825L, 0xc2449eb0L, - 0x22ac96ceL, 0x713f3ac6L, 0x398c321dL, 0xbc493022L, - 0x52d5dd03L, 0x2a5729f8L, 0x21738fa1L, 0xb90dee7dL, - 0x5faecc64L, 0xe3d0aa81L, 0xfa6e648fL, 0x039fdc6cL, - 0xc5522cd6L, 0xebece2dcL, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 608*/ - 0xb2af35f5L, 0x398b27d0L, 0x6f2e493dL, 0xe5b5be27L, - 0x3470972cL, 0xe90e9638L, 0x98adf7b7L, 0xb4cad091L, - 0x5f583f43L, 0xd014b6c5L, 0x414d25eeL, 0x6fd6e2c1L, - 0x9be6d737L, 0xe24166caL, 0xf7401897L, 0xceb0e5dfL, - 0xabc8db38L, 0xc58b8af8L, 0x9a04c6a0L, -#endif - /* dss_p length = 640*/ - 0xf6bf4095L, 0x40327568L, 0x64f25c0fL, 0xb0995aaeL, - 0x0e81346fL, 0x7aeb357aL, 0xfd0a0291L, 0xce808d54L, - 0xbea30c05L, 0x8a1b889fL, 0x6049f1c1L, 0x8ec3214aL, - 0xdde1b926L, 0x384e61b4L, 0xb6d7404bL, 0x45842e2dL, - 0xcc7aae6aL, 0x9eb07bfaL, 0x39043a26L, 0xc0368cacL, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 672*/ - 0xaea30abbL, 0x757cc749L, 0x29d03035L, 0xd56c46bdL, - 0xa355f49dL, 0x8dcb1297L, 0xc58c9802L, 0x8aacf1ecL, - 0xb10755ddL, 0x26d10140L, 0x8a908a5dL, 0xde0bf33eL, - 0xb429b844L, 0x98064db2L, 0x4c3bf629L, 0x2f23cd76L, - 0x7bf46c68L, 0xd9822a7eL, 0x16a2c89fL, 0x953cfe84L, - 0x8de83e4aL, -#endif - /* dss_p length = 704*/ - 0x15350113L, 0x8fafca0bL, 0x989ca327L, 0xe51212c8L, - 0x1229796fL, 0x62c812bfL, 0x2b99a50aL, 0x450cc93bL, - 0x082671adL, 0x3913f4c6L, 0x96da9b6eL, 0xbc5ea08dL, - 0x7b26d4d3L, 0xdd76f9fdL, 0x2f064e82L, 0xbf471f96L, - 0x3610cadfL, 0x4e94917bL, 0x0eafe2e8L, 0x6b901cb9L, - 0x6d6fb917L, 0xb32992b9L, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 736*/ - 0xd8786dadL, 0xe61ec913L, 0xe27587d9L, 0xf090ad24L, - 0xfdfee12bL, 0xc9a139a3L, 0x138a8330L, 0xc3194bedL, - 0x88ba8094L, 0x13254b80L, 0x67e27852L, 0x7313715eL, - 0x77273b4eL, 0x5c6e9870L, 0xc67ae0ceL, 0xf3c5d057L, - 0x98ba55eaL, 0xaee76ea0L, 0x3cd631e8L, 0x42d10e28L, - 0xc3958946L, 0x1b9d34fcL, 0x86f919d1L, -#endif - /* dss_p length = 768*/ - 0xea08e293L, 0xf668cdd0L, 0x06db8b2aL, 0xadb27c71L, - 0x6721943dL, 0xbc4454f5L, 0x3345f7caL, 0x0b901bf6L, - 0xd3c4b475L, 0x7caabdb6L, 0xe9b4a45fL, 0x0c1a6e0eL, - 0x9760b5c3L, 0x53af851aL, 0x497996b7L, 0xe951f162L, - 0xd0206a54L, 0xdecb9dedL, 0x7d74fc81L, 0x2aee5e92L, - 0x0eb50946L, 0x9bce3700L, 0xa7a3845aL, 0x8618157aL, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 800*/ - 0xac27b0a1L, 0xf623ec4eL, 0x2cb655e2L, 0x4b28288bL, - 0xbbe6d74eL, 0xaecdfdf7L, 0xe2515758L, 0x1aee9074L, - 0x4d5ee6edL, 0x529e01d9L, 0x0091f736L, 0xc7250212L, - 0x966f60ceL, 0x5c4b851dL, 0x34df80deL, 0x06361c88L, - 0x32cebb71L, 0x86da45cbL, 0x13e04d0eL, 0x544b7d7dL, - 0x747f1272L, 0xfa3bd6a7L, 0x6b43cb86L, 0xd01266f5L, - 0xa0cbfe7aL, -#endif - /* dss_p length = 832*/ - 0x84dded2dL, 0xdd8ff274L, 0x7928cd5fL, 0xa522bfc6L, - 0x50f0e4e4L, 0x5842cddfL, 0x7c4dbb29L, 0x6946eef4L, - 0xe48687f6L, 0xc1b661b5L, 0x575aadefL, 0x724f360fL, - 0x591bcb29L, 0xf7bc9a4cL, 0xa348309eL, 0x94f30ff5L, - 0x9dc6932fL, 0xc6d7992cL, 0xc2d712f6L, 0x8c0138aaL, - 0x74f45dcaL, 0x4cf4fcfdL, 0x7837588aL, 0xd2e2097eL, - 0x88696eacL, 0xec62e92fL, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 864*/ - 0x931e7c21L, 0x00f2553dL, 0x940fa860L, 0x7d20411eL, - 0x52a3b168L, 0x166e69eeL, 0x1b23b9e6L, 0xef64d5e0L, - 0x724c2850L, 0xea73c1feL, 0xe342da8cL, 0xd2561d7bL, - 0x180f359bL, 0xca77d7f5L, 0x216206acL, 0x78bba977L, - 0x5de25018L, 0xe2176061L, 0xfed14d42L, 0xd50f3929L, - 0x2433c946L, 0x361b15f8L, 0x3ff0bf51L, 0x31573efaL, - 0x53a07350L, 0x261bd1a4L, 0x9236de5bL, -#endif - /* dss_p length = 896*/ - 0x03648e21L, 0xe58c86d2L, 0x780a2274L, 0x49519ffcL, - 0xbc963f99L, 0x5a7e9e60L, 0x23d4010aL, 0x48e954d1L, - 0x979cfd6bL, 0x8af35202L, 0xfe8f5d87L, 0x1e0c3e3cL, - 0xcc52e294L, 0x480ea8d6L, 0xd4cea898L, 0xd3415949L, - 0xf41be325L, 0x6a9072d6L, 0x6f147a8bL, 0x66363e2bL, - 0x4eea3748L, 0x03e4a590L, 0x9c320524L, 0x02afeb53L, - 0x6792ca71L, 0xedf8d673L, 0x59c36448L, 0x883f7319L, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 928*/ - 0xa4e8c17dL, 0x8ff8ea08L, 0x73f52cb0L, 0xc027d7baL, - 0x989db9c8L, 0xe3a1e5feL, 0x39d3f324L, 0x5ba8f142L, - 0x3708e6cbL, 0xed9aa0b7L, 0xe314b6b3L, 0x6778f80aL, - 0x71074d27L, 0xb9c26ee8L, 0xab70c6afL, 0xc44553beL, - 0x34bb7926L, 0xe11d5191L, 0xcc3a67f1L, 0xd34d5354L, - 0x08baa1acL, 0x068a32d4L, 0x415f7c3bL, 0xb549bce0L, - 0x538f0ecfL, 0x22a3b5d0L, 0xe8371d47L, 0x69dd14c0L, - 0xce91a02dL, -#endif - /* dss_p length = 960*/ - 0xf77e1ff3L, 0x5a28ae7aL, 0xe18743b1L, 0xb3ea2e04L, - 0xa3e87394L, 0xc9bc4985L, 0x1e1c7b7dL, 0x55f8d99cL, - 0x5704447bL, 0xbed1d758L, 0x2a5ee698L, 0xc2065c19L, - 0x1f886d38L, 0x5f152ea4L, 0xd716ebfdL, 0xf9608a2aL, - 0xc49383acL, 0x8f13b966L, 0x96824778L, 0x84cd4712L, - 0xe567bb4eL, 0x0780644fL, 0x0b0a133dL, 0x06e8e42eL, - 0x3131a4ccL, 0xfaf839d9L, 0x555012a3L, 0xb8a943b1L, - 0x0fadb0ebL, 0xd427986fL, -#ifdef LENGTH_MULT_TO_32 - /* dss_p length = 992*/ - 0x363fbcfdL, 0x18f0050aL, 0xcac978d8L, 0xf31e423aL, - 0xd0c3198fL, 0x5d1bb319L, 0xc0b0917aL, 0x6b918d1bL, - 0xa9d1ea69L, 0x534502ceL, 0x69922c80L, 0x7a284dadL, - 0xd46dbb75L, 0x56120faaL, 0x8a0e6878L, 0x46ab63b4L, - 0x5381aca0L, 0x3e70b90aL, 0xb63919c4L, 0xe751f778L, - 0xb7265974L, 0x8679589fL, 0xc0b5eb04L, 0x2b32dffdL, - 0xc6324b51L, 0x9501d8c6L, 0x20264f94L, 0x0d27253aL, - 0x083807bbL, 0xa3eb2725L, 0x89b63c4eL, -#endif - /* dss_p length = 1024*/ - 0xecf7a141L, 0x867dc6d6L, 0x1cddefa3L, 0x6ca56c9dL, - 0x68af2e2fL, 0x1d3e90e1L, 0x0c2ad75fL, 0x36c7844bL, - 0xfd1a3420L, 0xf6e5b9eeL, 0xc8ed5fdeL, 0xd3530c90L, - 0x80a46faaL, 0xa59d5bbdL, 0x32239e72L, 0xf33d8f59L, - 0xeccd10ebL, 0x3e2a184eL, 0x564b4c07L, 0x32634c0aL, - 0x8aebc535L, 0x2be2f982L, 0x9b87e475L, 0x4d08cca0L, - 0x04843adfL, 0x7acdd528L, 0x55a0304dL, 0x829870aeL, - 0x22986a7aL, 0x7a8615c0L, 0x654a7fc5L, 0xd0aa14adL - }; -#endif - -ord DSS_G_NUMBERS[DSS_LAST_INDEX] = -#ifdef ORD_16 - { - /* dss_g length = 512*/ - 0x8b1a, 0xedfe, 0xef16, 0xdb26, 0xeae0, 0x1f1d, 0xaf3a, 0x3e30, - 0x2bd6, 0x25ec, 0xa451, 0x6255, 0xbc75, 0x499c, 0x4071, 0x5da2, - 0x1149, 0xc7fc, 0x1402, 0x9b69, 0xc168, 0xb0ea, 0xaf92, 0x6a33, - 0xf45f, 0xd93a, 0x75a6, 0x263c, 0xb820, 0x7eb1, 0x5f5b, 0x4bd7, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 544*/ - 0x2772, 0xe0e6, 0xce97, 0x605b, 0x4aa8, 0x2586, 0x095a, 0xb83f, - 0x8b01, 0xfe53, 0x9250, 0x74ef, 0x74d4, 0xd9fa, 0xb78b, 0xa714, - 0x106f, 0x03a6, 0xb406, 0xc549, 0xc44d, 0xd559, 0x8100, 0xfef4, - 0x34a4, 0x1f4c, 0x3c6b, 0x4ae0, 0xe770, 0x158b, 0x3f8d, 0xf73d, - 0x0cc5, 0x61b7, -#endif - /* dss_g length = 576*/ - 0x3dde, 0x64fd, 0x2b69, 0x03c3, 0xad1d, 0x1751, 0x11dc, 0xfe67, - 0x6379, 0x76de, 0xe333, 0x3b8f, 0x242f, 0x27d8, 0x5f33, 0x3597, - 0xb98c, 0x11dc, 0x718c, 0xe3b5, 0xa3d4, 0x58f2, 0x71fa, 0x2675, - 0x49f9, 0xf2c7, 0x510e, 0xa4e1, 0xeca4, 0x7c64, 0x243b, 0x78fc, - 0x2ce2, 0x7017, 0x0095, 0x23b6, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 608*/ - 0xdad8, 0x1e27, 0x41f5, 0xd536, 0x528f, 0x7047, 0x028a, 0x56f5, - 0xe55f, 0xe20d, 0x612c, 0x520f, 0xebfd, 0x8c86, 0x0924, 0x562a, - 0x2185, 0xe5ac, 0xa113, 0x4b8c, 0x87da, 0xfa4c, 0x8788, 0x9d8d, - 0x41c0, 0x9d25, 0x9c77, 0xff33, 0x6861, 0xd10a, 0xc734, 0x8454, - 0xf803, 0x55ce, 0xfeac, 0x6580, 0x6cd2, 0x482b, -#endif - /* dss_g length = 640*/ - 0x4ff7, 0x2829, 0x8ab0, 0xa0bd, 0x7b1c, 0xf544, 0xe633, 0x6e7b, - 0x9824, 0x494a, 0xfb7f, 0xc8ad, 0x45b6, 0x956e, 0x0574, 0x5b0d, - 0xd40c, 0xf807, 0x7372, 0x56fd, 0xdd12, 0x8960, 0x255c, 0x019e, - 0xfc39, 0x06b3, 0x9f8e, 0x4cd9, 0xe714, 0x77f6, 0x76f7, 0xb573, - 0x010e, 0x9b52, 0x04d2, 0xe269, 0xd4bb, 0xbdec, 0x089d, 0x7f88, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 672*/ - 0x3d36, 0xb22d, 0x2144, 0xfda0, 0x1d4a, 0xc144, 0xef8f, 0x70e8, - 0xfd0f, 0xcbf9, 0x7433, 0xbf29, 0x1657, 0x757b, 0x011d, 0x5c7e, - 0xa0d3, 0xec5a, 0xd45d, 0xacd6, 0x136a, 0x9454, 0x61fd, 0xc3f6, - 0x3758, 0x5c89, 0xe4df, 0xd3c9, 0x6f99, 0xa113, 0x0992, 0x16b2, - 0xf92f, 0xfb67, 0x3f34, 0x57e6, 0xb224, 0xdfd1, 0x43c4, 0x639a, - 0xccf5, 0x86c4, -#endif - /* dss_g length = 704*/ - 0x1621, 0x8313, 0x216e, 0xcb3b, 0xde00, 0xa11b, 0xf27f, 0xd5d4, - 0x6d2e, 0xc870, 0x1c47, 0x2e21, 0x780b, 0x1db6, 0x8adf, 0xe5c6, - 0x837d, 0x7dba, 0x9c8c, 0x28b5, 0xd309, 0xf3fa, 0x6c65, 0xe37f, - 0x6a1e, 0x2601, 0xbb92, 0x56aa, 0x9c0e, 0x9db1, 0xb782, 0x642b, - 0x6cc9, 0xb9fb, 0x6a3c, 0x97b9, 0xf1a8, 0xd8a2, 0xfe6b, 0xcb93, - 0x59ee, 0x32a4, 0x0aa1, 0x58ad, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 736*/ - 0x648c, 0xa15c, 0x27b2, 0x8137, 0xefb3, 0x0e81, 0x258e, 0xabe0, - 0x9f2f, 0x6c67, 0xbed6, 0xd201, 0x3647, 0xbe9a, 0x0091, 0xba9a, - 0x4df1, 0xdc8c, 0x5b15, 0x5a37, 0xb5b1, 0x50f8, 0xdfe6, 0x081b, - 0x48d7, 0xd40b, 0x7c51, 0x0417, 0x97c7, 0x2565, 0xf960, 0x89b2, - 0xa1f0, 0x7aac, 0xed6f, 0x20fe, 0x1d98, 0x0eee, 0x48b8, 0xb062, - 0x70e7, 0xa3f3, 0xbe3f, 0x9183, 0x76ae, 0x6cbc, -#endif - /* dss_g length = 768*/ - 0x6216, 0x4b90, 0xc254, 0x7ab6, 0x7a04, 0xf90f, 0x42dd, 0x58c7, - 0xd015, 0x904d, 0xfbf7, 0x624a, 0x5010, 0x627f, 0x696c, 0x1a32, - 0xe0bc, 0xcdfd, 0xe32f, 0xb081, 0x1377, 0x1913, 0x5f96, 0x86c6, - 0x864a, 0x8429, 0x4bb9, 0xd0c6, 0x3361, 0xbc7d, 0xbd8d, 0xa3b2, - 0x47d5, 0x5086, 0xed0b, 0x3bb6, 0xdba6, 0x6f2c, 0x707a, 0x434b, - 0xd4cc, 0x7b10, 0x8ef0, 0x3466, 0x4737, 0x8f27, 0x3399, 0x3716, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 800*/ - 0x99a7, 0xa90c, 0xdf8e, 0xba50, 0x83b5, 0x7ea0, 0x1d8a, 0xe5bb, - 0x34c9, 0x8c4d, 0xb151, 0x3aba, 0xee2f, 0x76c8, 0xeebf, 0x3db9, - 0xc1e0, 0x2b9a, 0x774f, 0xb476, 0x9b93, 0x53b5, 0xc008, 0xed2c, - 0x0ad4, 0x8af4, 0xc0e6, 0x0e98, 0x2d7b, 0xdb37, 0x7b59, 0x8a31, - 0x0667, 0x1225, 0xb882, 0x0355, 0x58ba, 0xf079, 0x80d7, 0x8033, - 0x54bc, 0xf9cd, 0x461e, 0xc70a, 0x9170, 0x1dba, 0xc447, 0xd3e5, - 0xaf18, 0x04c4, -#endif - /* dss_g length = 832*/ - 0xd1b5, 0x3d20, 0xfbdb, 0xa0b6, 0x0505, 0x4e88, 0xa781, 0x7c65, - 0xd381, 0x5b6e, 0xfd1e, 0xbb71, 0xe085, 0x855d, 0x6d0b, 0x650a, - 0xa248, 0x82d0, 0xd4dd, 0x7ea0, 0x16d1, 0x6937, 0x2cc2, 0x2dec, - 0x5e07, 0x97b4, 0x0c5a, 0xcf21, 0x0299, 0x9b96, 0x4acf, 0xc732, - 0xfbcf, 0xeefb, 0x0032, 0x40bb, 0xc86e, 0xeacb, 0xae2b, 0x8adb, - 0x39aa, 0xbb47, 0xaf3a, 0xfd36, 0xf859, 0x97fc, 0x5535, 0x0d3d, - 0x627a, 0x3f62, 0x1f90, 0x5490, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 864*/ - 0xbf83, 0x8b52, 0xc2b1, 0x0808, 0x4a3e, 0x6ccb, 0x8aa8, 0xcfdd, - 0xb046, 0x4948, 0xcdf4, 0x9881, 0x13d8, 0x85b0, 0xa22a, 0x3786, - 0xe9db, 0xcb8a, 0x89ad, 0x5e27, 0xd925, 0x1fcb, 0x3855, 0x4afd, - 0x7f67, 0x83be, 0xb092, 0xe061, 0x6703, 0xf21f, 0x403e, 0x4c6a, - 0xa8bd, 0x536a, 0x89b6, 0xb25e, 0xe165, 0xd259, 0xb765, 0xd7f3, - 0xc474, 0xd8bc, 0x617d, 0x1a0a, 0xa054, 0x8c28, 0x9fb0, 0x9595, - 0x6f2d, 0x6254, 0xe1c2, 0xb450, 0xef81, 0x277f, -#endif - /* dss_g length = 896*/ - 0x7490, 0x2aea, 0xd005, 0xa3cc, 0x9211, 0x235a, 0x7b6d, 0xacec, - 0xfca5, 0x5407, 0x8515, 0x5bc1, 0x8b2a, 0x9388, 0x8ff9, 0xed56, - 0xf4e9, 0xf31e, 0x7e05, 0x172a, 0x6e2a, 0x8165, 0x7a24, 0x975b, - 0x1f6e, 0xd4d1, 0x8232, 0xd6ff, 0x2363, 0x4072, 0xa1f1, 0xd18b, - 0xe574, 0xb032, 0xc330, 0x81b6, 0x6033, 0x07d5, 0x5107, 0xb7cc, - 0x2c10, 0xbd8e, 0xc6a3, 0xe731, 0xfcd6, 0xe567, 0x3440, 0xbcde, - 0x1976, 0xdbb3, 0xd15a, 0x4e39, 0xc282, 0x4b0b, 0x82b3, 0x286b, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 928*/ - 0x9f66, 0xd0e5, 0xd7d2, 0xe875, 0x0707, 0x2dca, 0xa5a2, 0x266d, - 0x80c2, 0x6d20, 0x69b3, 0x759c, 0x497f, 0x74b4, 0x0f56, 0x4b63, - 0xa294, 0x4995, 0x3eda, 0xf5c4, 0x7951, 0x3a3d, 0x22e9, 0x617f, - 0x1906, 0xd45d, 0x047f, 0x2726, 0x27be, 0x660e, 0xc1d3, 0xa588, - 0xceb2, 0xe300, 0xca06, 0x8620, 0x1110, 0x76ae, 0xf7b8, 0xe368, - 0x89a7, 0x2ded, 0x2756, 0x3ed6, 0x5449, 0x4bd8, 0xb73d, 0xb406, - 0x25ec, 0x32f7, 0x989c, 0x6623, 0x6b1f, 0xf7f0, 0x4807, 0x0954, - 0x51e6, 0x97d0, -#endif - /* dss_g length = 960*/ - 0x4118, 0xe87c, 0x809a, 0x1287, 0x2a0f, 0x51d6, 0x7fc8, 0xdad8, - 0x8dc6, 0xddce, 0xd27c, 0x898a, 0x96a9, 0xaee1, 0xe44c, 0xd322, - 0x9d58, 0x3a34, 0xcebd, 0x322a, 0x5b48, 0x9c21, 0x6d04, 0x2d77, - 0x41f1, 0x5123, 0xaa5f, 0x2192, 0x8175, 0x5cac, 0xf547, 0xdc08, - 0xb0d9, 0x4f11, 0x85c9, 0xb5bf, 0x7147, 0x9fbf, 0x3c20, 0x7f7a, - 0xdd8a, 0xa163, 0x0ae4, 0xfcb2, 0x8251, 0x8162, 0xb96e, 0x84f9, - 0xd652, 0x94ba, 0xbb90, 0x9559, 0xac51, 0x6418, 0xdb54, 0x4739, - 0x3ec0, 0x9b7c, 0xae96, 0x3e14, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 992*/ - 0x4eff, 0x399a, 0x5da9, 0x1e5a, 0x9040, 0x4bad, 0xc85d, 0x5b9a, - 0x825b, 0x5464, 0x7538, 0xe2ea, 0xb957, 0x5def, 0xbfa6, 0x4916, - 0x89be, 0x93fe, 0xe5da, 0x919f, 0x791c, 0xe7a8, 0xef86, 0xc186, - 0xbf63, 0xa881, 0x1e38, 0x9abe, 0x8b58, 0x70b4, 0x9dfd, 0x0719, - 0x85e5, 0xc60a, 0xab36, 0xe07d, 0x0c49, 0xd6fe, 0xfdb4, 0x6619, - 0xe55d, 0x997e, 0x5f38, 0x824f, 0x47ff, 0xf800, 0xb137, 0x839d, - 0x2dae, 0xe0db, 0x2a74, 0x2f58, 0x6fb3, 0x1bab, 0x62ed, 0x0e02, - 0xbef2, 0xd7f1, 0xe566, 0xa9ae, 0xbc35, 0x6357, -#endif - /* dss_g length = 1024*/ - 0x914d, 0x76b2, 0xfee4, 0x9cf7, 0xa136, 0x07a1, 0x3808, 0x1857, - 0x8f96, 0x870c, 0x1f3c, 0x59f2, 0x6f01, 0x4d4d, 0x580e, 0xafc6, - 0x99af, 0xff1b, 0xc019, 0x6c1f, 0xe449, 0x1698, 0x4787, 0x0aa2, - 0x6e68, 0x768d, 0x5ff0, 0x27dc, 0xca9e, 0x630f, 0x01ae, 0x9981, - 0x688d, 0xf278, 0x7f3d, 0x17ad, 0x48aa, 0x65d6, 0x181f, 0x1802, - 0x647c, 0x9ef5, 0x7081, 0x5843, 0x1f0d, 0x9364, 0xebe9, 0x6330, - 0x033a, 0x5d2a, 0xb68a, 0x5639, 0xfa7c, 0xd77e, 0x4bdc, 0x4a62, - 0x5c6d, 0xfed5, 0xa8aa, 0x5eff, 0x1138, 0xae4a, 0xe993, 0x3a73 - }; -#else - { - /* dss_g length = 512*/ - 0xedfe8b1aL, 0xdb26ef16L, 0x1f1deae0L, 0x3e30af3aL, - 0x25ec2bd6L, 0x6255a451L, 0x499cbc75L, 0x5da24071L, - 0xc7fc1149L, 0x9b691402L, 0xb0eac168L, 0x6a33af92L, - 0xd93af45fL, 0x263c75a6L, 0x7eb1b820L, 0x4bd75f5bL, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 544*/ - 0xe0e62772L, 0x605bce97L, 0x25864aa8L, 0xb83f095aL, - 0xfe538b01L, 0x74ef9250L, 0xd9fa74d4L, 0xa714b78bL, - 0x03a6106fL, 0xc549b406L, 0xd559c44dL, 0xfef48100L, - 0x1f4c34a4L, 0x4ae03c6bL, 0x158be770L, 0xf73d3f8dL, - 0x61b70cc5L, -#endif - /* dss_g length = 576*/ - 0x64fd3ddeL, 0x03c32b69L, 0x1751ad1dL, 0xfe6711dcL, - 0x76de6379L, 0x3b8fe333L, 0x27d8242fL, 0x35975f33L, - 0x11dcb98cL, 0xe3b5718cL, 0x58f2a3d4L, 0x267571faL, - 0xf2c749f9L, 0xa4e1510eL, 0x7c64eca4L, 0x78fc243bL, - 0x70172ce2L, 0x23b60095L, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 608*/ - 0x1e27dad8L, 0xd53641f5L, 0x7047528fL, 0x56f5028aL, - 0xe20de55fL, 0x520f612cL, 0x8c86ebfdL, 0x562a0924L, - 0xe5ac2185L, 0x4b8ca113L, 0xfa4c87daL, 0x9d8d8788L, - 0x9d2541c0L, 0xff339c77L, 0xd10a6861L, 0x8454c734L, - 0x55cef803L, 0x6580feacL, 0x482b6cd2L, -#endif - /* dss_g length = 640*/ - 0x28294ff7L, 0xa0bd8ab0L, 0xf5447b1cL, 0x6e7be633L, - 0x494a9824L, 0xc8adfb7fL, 0x956e45b6L, 0x5b0d0574L, - 0xf807d40cL, 0x56fd7372L, 0x8960dd12L, 0x019e255cL, - 0x06b3fc39L, 0x4cd99f8eL, 0x77f6e714L, 0xb57376f7L, - 0x9b52010eL, 0xe26904d2L, 0xbdecd4bbL, 0x7f88089dL, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 672*/ - 0xb22d3d36L, 0xfda02144L, 0xc1441d4aL, 0x70e8ef8fL, - 0xcbf9fd0fL, 0xbf297433L, 0x757b1657L, 0x5c7e011dL, - 0xec5aa0d3L, 0xacd6d45dL, 0x9454136aL, 0xc3f661fdL, - 0x5c893758L, 0xd3c9e4dfL, 0xa1136f99L, 0x16b20992L, - 0xfb67f92fL, 0x57e63f34L, 0xdfd1b224L, 0x639a43c4L, - 0x86c4ccf5L, -#endif - /* dss_g length = 704*/ - 0x83131621L, 0xcb3b216eL, 0xa11bde00L, 0xd5d4f27fL, - 0xc8706d2eL, 0x2e211c47L, 0x1db6780bL, 0xe5c68adfL, - 0x7dba837dL, 0x28b59c8cL, 0xf3fad309L, 0xe37f6c65L, - 0x26016a1eL, 0x56aabb92L, 0x9db19c0eL, 0x642bb782L, - 0xb9fb6cc9L, 0x97b96a3cL, 0xd8a2f1a8L, 0xcb93fe6bL, - 0x32a459eeL, 0x58ad0aa1L, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 736*/ - 0xa15c648cL, 0x813727b2L, 0x0e81efb3L, 0xabe0258eL, - 0x6c679f2fL, 0xd201bed6L, 0xbe9a3647L, 0xba9a0091L, - 0xdc8c4df1L, 0x5a375b15L, 0x50f8b5b1L, 0x081bdfe6L, - 0xd40b48d7L, 0x04177c51L, 0x256597c7L, 0x89b2f960L, - 0x7aaca1f0L, 0x20feed6fL, 0x0eee1d98L, 0xb06248b8L, - 0xa3f370e7L, 0x9183be3fL, 0x6cbc76aeL, -#endif - /* dss_g length = 768*/ - 0x4b906216L, 0x7ab6c254L, 0xf90f7a04L, 0x58c742ddL, - 0x904dd015L, 0x624afbf7L, 0x627f5010L, 0x1a32696cL, - 0xcdfde0bcL, 0xb081e32fL, 0x19131377L, 0x86c65f96L, - 0x8429864aL, 0xd0c64bb9L, 0xbc7d3361L, 0xa3b2bd8dL, - 0x508647d5L, 0x3bb6ed0bL, 0x6f2cdba6L, 0x434b707aL, - 0x7b10d4ccL, 0x34668ef0L, 0x8f274737L, 0x37163399L, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 800*/ - 0xa90c99a7L, 0xba50df8eL, 0x7ea083b5L, 0xe5bb1d8aL, - 0x8c4d34c9L, 0x3abab151L, 0x76c8ee2fL, 0x3db9eebfL, - 0x2b9ac1e0L, 0xb476774fL, 0x53b59b93L, 0xed2cc008L, - 0x8af40ad4L, 0x0e98c0e6L, 0xdb372d7bL, 0x8a317b59L, - 0x12250667L, 0x0355b882L, 0xf07958baL, 0x803380d7L, - 0xf9cd54bcL, 0xc70a461eL, 0x1dba9170L, 0xd3e5c447L, - 0x04c4af18L, -#endif - /* dss_g length = 832*/ - 0x3d20d1b5L, 0xa0b6fbdbL, 0x4e880505L, 0x7c65a781L, - 0x5b6ed381L, 0xbb71fd1eL, 0x855de085L, 0x650a6d0bL, - 0x82d0a248L, 0x7ea0d4ddL, 0x693716d1L, 0x2dec2cc2L, - 0x97b45e07L, 0xcf210c5aL, 0x9b960299L, 0xc7324acfL, - 0xeefbfbcfL, 0x40bb0032L, 0xeacbc86eL, 0x8adbae2bL, - 0xbb4739aaL, 0xfd36af3aL, 0x97fcf859L, 0x0d3d5535L, - 0x3f62627aL, 0x54901f90L, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 864*/ - 0x8b52bf83L, 0x0808c2b1L, 0x6ccb4a3eL, 0xcfdd8aa8L, - 0x4948b046L, 0x9881cdf4L, 0x85b013d8L, 0x3786a22aL, - 0xcb8ae9dbL, 0x5e2789adL, 0x1fcbd925L, 0x4afd3855L, - 0x83be7f67L, 0xe061b092L, 0xf21f6703L, 0x4c6a403eL, - 0x536aa8bdL, 0xb25e89b6L, 0xd259e165L, 0xd7f3b765L, - 0xd8bcc474L, 0x1a0a617dL, 0x8c28a054L, 0x95959fb0L, - 0x62546f2dL, 0xb450e1c2L, 0x277fef81L, -#endif - /* dss_g length = 896*/ - 0x2aea7490L, 0xa3ccd005L, 0x235a9211L, 0xacec7b6dL, - 0x5407fca5L, 0x5bc18515L, 0x93888b2aL, 0xed568ff9L, - 0xf31ef4e9L, 0x172a7e05L, 0x81656e2aL, 0x975b7a24L, - 0xd4d11f6eL, 0xd6ff8232L, 0x40722363L, 0xd18ba1f1L, - 0xb032e574L, 0x81b6c330L, 0x07d56033L, 0xb7cc5107L, - 0xbd8e2c10L, 0xe731c6a3L, 0xe567fcd6L, 0xbcde3440L, - 0xdbb31976L, 0x4e39d15aL, 0x4b0bc282L, 0x286b82b3L, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 928*/ - 0xd0e59f66L, 0xe875d7d2L, 0x2dca0707L, 0x266da5a2L, - 0x6d2080c2L, 0x759c69b3L, 0x74b4497fL, 0x4b630f56L, - 0x4995a294L, 0xf5c43edaL, 0x3a3d7951L, 0x617f22e9L, - 0xd45d1906L, 0x2726047fL, 0x660e27beL, 0xa588c1d3L, - 0xe300ceb2L, 0x8620ca06L, 0x76ae1110L, 0xe368f7b8L, - 0x2ded89a7L, 0x3ed62756L, 0x4bd85449L, 0xb406b73dL, - 0x32f725ecL, 0x6623989cL, 0xf7f06b1fL, 0x09544807L, - 0x97d051e6L, -#endif - /* dss_g length = 960*/ - 0xe87c4118L, 0x1287809aL, 0x51d62a0fL, 0xdad87fc8L, - 0xddce8dc6L, 0x898ad27cL, 0xaee196a9L, 0xd322e44cL, - 0x3a349d58L, 0x322acebdL, 0x9c215b48L, 0x2d776d04L, - 0x512341f1L, 0x2192aa5fL, 0x5cac8175L, 0xdc08f547L, - 0x4f11b0d9L, 0xb5bf85c9L, 0x9fbf7147L, 0x7f7a3c20L, - 0xa163dd8aL, 0xfcb20ae4L, 0x81628251L, 0x84f9b96eL, - 0x94bad652L, 0x9559bb90L, 0x6418ac51L, 0x4739db54L, - 0x9b7c3ec0L, 0x3e14ae96L, -#ifdef LENGTH_MULT_TO_32 - /* dss_g length = 992*/ - 0x399a4effL, 0x1e5a5da9L, 0x4bad9040L, 0x5b9ac85dL, - 0x5464825bL, 0xe2ea7538L, 0x5defb957L, 0x4916bfa6L, - 0x93fe89beL, 0x919fe5daL, 0xe7a8791cL, 0xc186ef86L, - 0xa881bf63L, 0x9abe1e38L, 0x70b48b58L, 0x07199dfdL, - 0xc60a85e5L, 0xe07dab36L, 0xd6fe0c49L, 0x6619fdb4L, - 0x997ee55dL, 0x824f5f38L, 0xf80047ffL, 0x839db137L, - 0xe0db2daeL, 0x2f582a74L, 0x1bab6fb3L, 0x0e0262edL, - 0xd7f1bef2L, 0xa9aee566L, 0x6357bc35L, -#endif - /* dss_g length = 1024*/ - 0x76b2914dL, 0x9cf7fee4L, 0x07a1a136L, 0x18573808L, - 0x870c8f96L, 0x59f21f3cL, 0x4d4d6f01L, 0xafc6580eL, - 0xff1b99afL, 0x6c1fc019L, 0x1698e449L, 0x0aa24787L, - 0x768d6e68L, 0x27dc5ff0L, 0x630fca9eL, 0x998101aeL, - 0xf278688dL, 0x17ad7f3dL, 0x65d648aaL, 0x1802181fL, - 0x9ef5647cL, 0x58437081L, 0x93641f0dL, 0x6330ebe9L, - 0x5d2a033aL, 0x5639b68aL, 0xd77efa7cL, 0x4a624bdcL, - 0xfed55c6dL, 0x5effa8aaL, 0xae4a1138L, 0x3a73e993L - }; -#endif - -#endif /*INITIALIZ_PQG*/ - -#endif /*DSSNUMBER_H*/ diff --git a/usr/src/lib/libresolv2/common/cylink/kludge.h b/usr/src/lib/libresolv2/common/cylink/kludge.h deleted file mode 100644 index 7c85615e89..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/kludge.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#ifndef KLUDGE_H -#define KLUDGE_H - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Kludges for not-quite-ANSI systems. - * This should always be the last file included, because it may - * mess up some system header files. - */ - -/* - * Some compilers complain about #if FOO if FOO isn't defined, - * so do the ANSI-mandated thing explicitly... - */ -#ifndef ASSERT_NEEDS_STDIO -#define ASSERT_NEEDS_STDIO 0 -#endif -#ifndef ASSERT_NEEDS_STDLIB -#define ASSERT_NEEDS_STDLIB 0 -#endif -#ifndef NO_STDLIB_H -#define NO_STDLIB_H 0 -#endif - -/* SunOS 4.1.x <assert.h> needs "stderr" defined, and "exit" declared... */ -#ifdef assert -#if ASSERT_NEEDS_STDIO -#include <stdio.h> -#endif -#if ASSERT_NEEDS_STDLIB -#if !NO_STDLIB_H -#include <stdlib.h> -#endif -#endif -#endif - -#ifndef NO_MEMMOVE -#define NO_MEMMOVE 0 -#endif -#if NO_MEMMOVE /* memove() not in libraries */ -#define memmove(dest,src,len) bcopy(src,dest,len) -#endif - -#ifndef NO_MEMCPY -#define NO_MEMCPY 0 -#endif -#if NO_MEMCPY /* memcpy() not in libraries */ -#define memcpy(dest,src,len) bcopy(src,dest,len) -#endif - -#ifndef MEM_PROTOS_BROKEN -#define MEM_PROTOS_BROKEN 0 -#endif -#if MEM_PROTOS_BROKEN -#define memcpy(d,s,l) memcpy((void *)(d), (void const *)(s), l) -#define memmove(d,s,l) memmove((void *)(d), (void const *)(s), l) -#define memcmp(d,s,l) memcmp((void const *)(d), (void const *)(s), l) -#define memset(d,v,l) memset((void *)(d), v, l) -#endif - -/* - * If there are no prototypes for the stdio functions, use these to - * reduce compiler warnings. Uses EOF as a giveaway to indicate - * that <stdio.h> was #included. - */ -#ifndef NO_STDIO_PROTOS -#define NO_STDIO_PROTOS 0 -#endif -#if NO_STDIO_PROTOS /* Missing prototypes for "simple" functions */ -#ifdef EOF -#ifdef __cplusplus -extern "C" { -#endif -int (puts)(char const *); -int (fputs)(char const *, FILE *); -int (fflush)(FILE *); -int (printf)(char const *, ...); -int (fprintf)(FILE *, char const *, ...); -/* If we have a sufficiently old-fashioned stdio, it probably uses these... */ -int (_flsbuf)(int, FILE *); -int (_filbuf)(FILE *); -#ifdef __cplusplus -} -#endif -#endif /* EOF */ -#endif /* NO_STDIO_PROTOS */ - -/* - * Borland C seems to think that it's a bad idea to decleare a - * structure tag and not declare the contents. I happen to think - * it's a *good* idea to use such "opaque" structures wherever - * possible. So shut up. - */ -#ifdef __BORLANDC__ -#pragma warn -stu -#ifndef MSDOS -#define MSDOS 1 -#endif -#endif - -/* Turn off warning about negation of unsigned values */ -#ifdef _MSC_VER -#pragma warning(disable:4146) -#endif - -/* Cope with people forgetting to define the OS, if possible... */ - -#ifndef MSDOS -#ifdef __MSDOS -#define MSDOS 1 -#endif -#endif -#ifndef MSDOS -#ifdef __MSDOS__ -#define MSDOS 1 -#endif -#endif - -#endif /* KLUDGE_H */ diff --git a/usr/src/lib/libresolv2/common/cylink/lbn.h b/usr/src/lib/libresolv2/common/cylink/lbn.h deleted file mode 100644 index c0385c60cc..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbn.h +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * lbn.h - Low-level bignum header. - * Defines various word sizes and useful macros. - * - * Copyright (c) 1995 Colin Plumb. All rights reserved. - * For licensing and other legal details, see the file legal.c. - */ -#ifndef LBN_H -#define LBN_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifndef HAVE_CONFIG_H -#define HAVE_CONFIG_H 0 -#endif -#if HAVE_CONFIG_H -#include "config.h" -#endif - -/* - * Some compilers complain about #if FOO if FOO isn't defined, - * so do the ANSI-mandated thing explicitly... - */ -#ifndef NO_LIMITS_H -#define NO_LIMITS_H 0 -#endif - -/* Make sure we have 8-bit bytes */ -#if !NO_LIMITS_H -#include <limits.h> -#if UCHAR_MAX != 0xff || CHAR_BIT != 8 -#error The bignum library requires 8-bit unsigned characters. -#endif -#endif /* !NO_LIMITS_H */ - -#ifdef BNINCLUDE /* If this is defined as, say, foo.h */ -#define STR(x) #x /* STR(BNINCLUDE) -> "BNINCLUDE" */ -#define XSTR(x) STR(x) /* XSTR(BNINCLUDE) -> STR(foo.h) -> "foo.h" */ -#include XSTR(BNINCLUDE) /* #include "foo.h" */ -#undef XSTR -#undef STR -#endif - -/* Figure out the endianness */ -/* Error if more than one is defined */ -#if BN_BIG_ENDIAN && BN_LITTLE_ENDIAN -#error Only one of BN_BIG_ENDIAN or BN_LITTLE_ENDIAN may be defined -#endif - -/* - * If no preference is stated, little-endian C code is slightly more - * efficient, so prefer that. (The endianness here does NOT have to - * match the machine's native byte sex; the library's C code will work - * either way. The flexibility is allowed for assembly routines - * that do care. - */ -#if !defined(BN_BIG_ENDIAN) && !defined(BN_LITTLE_ENDIAN) -#define BN_LITTLE_ENDIAN 1 -#endif /* !BN_BIG_ENDIAN && !BN_LITTLE_ENDIAN */ - -/* Macros to choose between big and little endian */ -#if BN_BIG_ENDIAN -#define BIG(b) b -#define LITTLE(l) /*nothing*/ -#define BIGLITTLE(b,l) b -#elif BN_LITTLE_ENDIAN -#define BIG(b) /*nothing*/ -#define LITTLE(l) l -#define BIGLITTLE(b,l) l -#else -#error One of BN_BIG_ENDIAN or BN_LITTLE_ENDIAN must be defined as 1 -#endif - - -/* - * Find a 16-bit unsigned type. - * Unsigned short is preferred over unsigned int to make the type chosen - * by this file more stable on platforms (such as many 68000 compilers) - * which support both 16- and 32-bit ints. - */ -#ifndef BNWORD16 -#ifndef USHRT_MAX /* No <limits.h> available - guess */ -typedef unsigned short bnword16; -#define BNWORD16 bnword16 -#elif USHRT_MAX == 0xffff -typedef unsigned short bnword16; -#define BNWORD16 bnword16 -#elif UINT_MAX == 0xffff -typedef unsigned bnword16; -#define BNWORD16 bnword16 -#endif -#endif /* BNWORD16 */ - -/* - * Find a 32-bit unsigned type. - * Unsigned long is preferred over unsigned int to make the type chosen - * by this file more stable on platforms (such as many 68000 compilers) - * which support both 16- and 32-bit ints. - */ -#ifndef BNWORD32 -#ifndef ULONG_MAX /* No <limits.h> available - guess */ -typedef unsigned long bnword32; -#define BNWORD32 bnword32 -#elif ULONG_MAX == 0xfffffffful -typedef unsigned long bnword32; -#define BNWORD32 bnword32 -#elif UINT_MAX == 0xffffffff -typedef unsigned bnword32; -#define BNWORD32 bnword32 -#elif USHRT_MAX == 0xffffffff -typedef unsigned short bnword32; -#define BNWORD32 bnword32 -#endif -#endif /* BNWORD16 */ - -/* - * Find a 64-bit unsigned type. - * The conditions here are more complicated to avoid using numbers that - * will choke lesser preprocessors (like 0xffffffffffffffff) unless - * we're reasonably certain that they'll be acceptable. - */ -#if !defined(BNWORD64) && ULONG_MAX > 0xfffffffful -#if ULONG_MAX == 0xffffffffffffffff -typedef unsigned long bnword64; -#define BNWORD64 bnword64 -#endif -#endif - -#if 0 -/* - * I would test the value of unsigned long long, but some *preprocessors* - * don't constants that long even if the compiler can accept them, so it - * doesn't work reliably. So cross our fingers and hope that it's a 64-bit - * type. - * - * GCC uses ULONG_LONG_MAX. Solaris uses ULLONG_MAX. IRIX uses ULONGLONG_MAX. - * Are there any other names for this? - */ -#if !defined(BNWORD64) && \ - (defined(ULONG_LONG_MAX) || defined (ULLONG_MAX) || defined(ULONGLONG_MAX)) -typedef unsigned long long bnword64; -#define BNWORD64 bnword64 -#endif -#endif - -/* We don't even try to find a 128-bit type at the moment */ - -#endif /* !LBN_H */ diff --git a/usr/src/lib/libresolv2/common/cylink/lbn00.c b/usr/src/lib/libresolv2/common/cylink/lbn00.c deleted file mode 100644 index f6686d7b00..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbn00.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2001 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * lbn00.c - auto-size-detecting lbn??.c file. - * - * Written in 1995 by Colin Plumb. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "port_before.h" -#include "bnsize00.h" - - -#if BNSIZE64 - -/* Include all of the C source file by reference */ -#include "lbn64.c" - -#elif BNSIZE32 - -/* Include all of the C source file by reference */ -#include "lbn32.c" - -#else /* BNSIZE16 */ - -/* Include all of the C source file by reference */ -#include "lbn16.c" - -#endif diff --git a/usr/src/lib/libresolv2/common/cylink/lbn16.c b/usr/src/lib/libresolv2/common/cylink/lbn16.c deleted file mode 100644 index 938651d1d4..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbn16.c +++ /dev/null @@ -1,3651 +0,0 @@ -/* - * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * lbn16.c - Low-level bignum routines, 16-bit version. - * - * Copyright (c) 1995 Colin Plumb. All rights reserved. - * For licensing and other legal details, see the file legal.c. - * - * NOTE: the magic constants "16" and "32" appear in many places in this - * file, including inside identifiers. Because it is not possible to - * ask "#ifdef" of a macro expansion, it is not possible to use the - * preprocessor to conditionalize these properly. Thus, this file is - * intended to be edited with textual search and replace to produce - * alternate word size versions. Any reference to the number of bits - * in a word must be the string "16", and that string must not appear - * otherwise. Any reference to twice this number must appear as "32", - * which likewise must not appear otherwise. Is that clear? - * - * Remember, when doubling the bit size replace the larger number (32) - * first, then the smaller (16). When halving the bit size, do the - * opposite. Otherwise, things will get wierd. Also, be sure to replace - * every instance that appears. (:%s/foo/bar/g in vi) - * - * These routines work with a pointer to the least-significant end of - * an array of WORD16s. The BIG(x), LITTLE(y) and BIGLTTLE(x,y) macros - * defined in lbn.h (which expand to x on a big-edian machine and y on a - * little-endian machine) are used to conditionalize the code to work - * either way. If you have no assembly primitives, it doesn't matter. - * Note that on a big-endian machine, the least-significant-end pointer - * is ONE PAST THE END. The bytes are ptr[-1] through ptr[-len]. - * On little-endian, they are ptr[0] through ptr[len-1]. This makes - * perfect sense if you consider pointers to point *between* bytes rather - * than at them. - * - * Because the array index values are unsigned integers, ptr[-i] - * may not work properly, since the index -i is evaluated as an unsigned, - * and if pointers are wider, zero-extension will produce a positive - * number rahter than the needed negative. The expression used in this - * code, *(ptr-i) will, however, work. (The array syntax is equivalent - * to *(ptr+-i), which is a pretty subtle difference.) - * - * Many of these routines will get very unhappy if fed zero-length inputs. - * They use assert() to enforce this. An higher layer of code must make - * sure that these aren't called with zero-length inputs. - * - * Any of these routines can be replaced with more efficient versions - * elsewhere, by just #defining their names. If one of the names - * is #defined, the C code is not compiled in and no declaration is - * made. Use the BNINCLUDE file to do that. Typically, you compile - * asm subroutines with the same name and just, e.g. - * #define lbnMulAdd1_16 lbnMulAdd1_16 - * - * If you want to write asm routines, start with lbnMulAdd1_16(). - * This is the workhorse of modular exponentiation. lbnMulN1_16() is - * also used a fair bit, although not as much and it's defined in terms - * of lbnMulAdd1_16 if that has a custom version. lbnMulSub1_16 and - * lbnDiv21_16 are used in the usual division and remainder finding. - * (Not the Montgomery reduction used in modular exponentiation, though.) - * Once you have lbnMulAdd1_16 defined, writing the other two should - * be pretty easy. (Just make sure you get the sign of the subtraction - * in lbnMulSub1_16 right - it's dest = dest - source * k.) - * - * The only definitions that absolutely need a double-word (BNWORD32) - * type are lbnMulAdd1_16 and lbnMulSub1_16; if those are provided, - * the rest follows. lbnDiv21_16, however, is a lot slower unless you - * have them, and lbnModQ_16 takes after it. That one is used quite a - * bit for prime sieving. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifndef HAVE_CONFIG_H -#define HAVE_CONFIG_H 0 -#endif -#if HAVE_CONFIG_H -#include "config.h" -#endif - -/* - * Some compilers complain about #if FOO if FOO isn't defined, - * so do the ANSI-mandated thing explicitly... - */ -#ifndef NO_ASSERT_H -#define NO_ASSERT_H 0 -#endif -#ifndef NO_STRING_H -#define NO_STRING_H 0 -#endif -#ifndef HAVE_STRINGS_H -#define HAVE_STRINGS_H 0 -#endif -#ifndef NEED_MEMORY_H -#define NEED_MEMORY_H 0 -#endif - -#if !NO_ASSERT_H -#include <assert.h> -#else -#define assert(x) (void)0 -#endif - -#if !NO_STRING_H -#include <string.h> /* For memcpy */ -#elif HAVE_STRINGS_H -#include <strings.h> -#endif -#if NEED_MEMORY_H -#include <memory.h> -#endif - -#include "lbn.h" -#include "lbn16.h" -#include "lbnmem.h" -#include "legal.h" - -#include "kludge.h" -#include <port_after.h> - -#ifndef BNWORD16 -#error 16-bit bignum library requires a 16-bit data type -#endif - -/* Make sure the copyright notice gets included */ -volatile const char * volatile const lbnCopyright_16 = bnCopyright; - -/* - * Most of the multiply (and Montgomery reduce) routines use an outer - * loop that iterates over one of the operands - a so-called operand - * scanning approach. One big advantage of this is that the assembly - * support routines are simpler. The loops can be rearranged to have - * an outer loop that iterates over the product, a so-called product - * scanning approach. This has the advantage of writing less data - * and doing fewer adds to memory, so is supposedly faster. Some - * code has been written using a product-scanning approach, but - * it appears to be slower, so it is turned off by default. Some - * experimentation would be appreciated. - * - * (The code is also annoying to get right and not very well commented, - * one of my pet peeves about math libraries. I'm sorry.) - */ -#ifndef PRODUCT_SCAN -#define PRODUCT_SCAN 0 -#endif - -/* - * Copy an array of words. <Marvin mode on> Thrilling, isn't it? </Marvin> - * This is a good example of how the byte offsets and BIGLITTLE() macros work. - * Another alternative would have been - * memcpy(dest BIG(-len), src BIG(-len), len*sizeof(BNWORD16)), but I find that - * putting operators into conditional macros is confusing. - */ -#ifndef lbnCopy_16 -void -lbnCopy_16(BNWORD16 *dest, BNWORD16 const *src, unsigned len) -{ - memcpy(BIGLITTLE(dest-len,dest), BIGLITTLE(src-len,src), - len * sizeof(*src)); -} -#endif /* !lbnCopy_16 */ - -/* - * Fill n words with zero. This does it manually rather than calling - * memset because it can assume alignment to make things faster while - * memset can't. Note how big-endian numbers are naturally addressed - * using predecrement, while little-endian is postincrement. - */ -#ifndef lbnZero_16 -void -lbnZero_16(BNWORD16 *num, unsigned len) -{ - while (len--) - BIGLITTLE(*--num,*num++) = 0; -} -#endif /* !lbnZero_16 */ - -/* - * Negate an array of words. - * Negation is subtraction from zero. Negating low-order words - * entails doing nothing until a non-zero word is hit. Once that - * is negated, a borrow is generated and never dies until the end - * of the number is hit. Negation with borrow, -x-1, is the same as ~x. - * Repeat that until the end of the number. - * - * Doesn't return borrow out because that's pretty useless - it's - * always set unless the input is 0, which is easy to notice in - * normalized form. - */ -#ifndef lbnNeg_16 -void -lbnNeg_16(BNWORD16 *num, unsigned len) -{ - assert(len); - - /* Skip low-order zero words */ - while (BIGLITTLE(*--num,*num) == 0) { - if (!--len) - return; - LITTLE(num++;) - } - /* Negate the lowest-order non-zero word */ - *num = -*num; - /* Complement all the higher-order words */ - while (--len) { - BIGLITTLE(--num,++num); - *num = ~*num; - } -} -#endif /* !lbnNeg_16 */ - - -/* - * lbnAdd1_16: add the single-word "carry" to the given number. - * Used for minor increments and propagating the carry after - * adding in a shorter bignum. - * - * Technique: If we have a double-width word, presumably the compiler - * can add using its carry in inline code, so we just use a larger - * accumulator to compute the carry from the first addition. - * If not, it's more complex. After adding the first carry, which may - * be > 1, compare the sum and the carry. If the sum wraps (causing a - * carry out from the addition), the result will be less than each of the - * inputs, since the wrap subtracts a number (2^16) which is larger than - * the other input can possibly be. If the sum is >= the carry input, - * return success immediately. - * In either case, if there is a carry, enter a loop incrementing words - * until one does not wrap. Since we are adding 1 each time, the wrap - * will be to 0 and we can test for equality. - */ -#ifndef lbnAdd1_16 /* If defined, it's provided as an asm subroutine */ -#ifdef BNWORD32 -BNWORD16 -lbnAdd1_16(BNWORD16 *num, unsigned len, BNWORD16 carry) -{ - BNWORD32 t; - assert(len > 0); /* Alternative: if (!len) return carry */ - - t = (BNWORD32)BIGLITTLE(*--num,*num) + carry; - BIGLITTLE(*num,*num++) = (BNWORD16)t; - if ((t >> 16) == 0) - return 0; - while (--len) { - if (++BIGLITTLE(*--num,*num++) != 0) - return 0; - } - return 1; -} -#else /* no BNWORD32 */ -BNWORD16 -lbnAdd1_16(BNWORD16 *num, unsigned len, BNWORD16 carry) -{ - assert(len > 0); /* Alternative: if (!len) return carry */ - - if ((BIGLITTLE(*--num,*num++) += carry) >= carry) - return 0; - while (--len) { - if (++BIGLITTLE(*--num,*num++) != 0) - return 0; - } - return 1; -} -#endif -#endif/* !lbnAdd1_16 */ - -/* - * lbnSub1_16: subtract the single-word "borrow" from the given number. - * Used for minor decrements and propagating the borrow after - * subtracting a shorter bignum. - * - * Technique: Similar to the add, above. If there is a double-length type, - * use that to generate the first borrow. - * If not, after subtracting the first borrow, which may be > 1, compare - * the difference and the *negative* of the carry. If the subtract wraps - * (causing a borrow out from the subtraction), the result will be at least - * as large as -borrow. If the result < -borrow, then no borrow out has - * appeared and we may return immediately, except when borrow == 0. To - * deal with that case, use the identity that -x = ~x+1, and instead of - * comparing < -borrow, compare for <= ~borrow. - * Either way, if there is a borrow out, enter a loop decrementing words - * until a non-zero word is reached. - * - * Note the cast of ~borrow to (BNWORD16). If the size of an int is larger - * than BNWORD16, C rules say the number is expanded for the arithmetic, so - * the inversion will be done on an int and the value won't be quite what - * is expected. - */ -#ifndef lbnSub1_16 /* If defined, it's provided as an asm subroutine */ -#ifdef BNWORD32 -BNWORD16 -lbnSub1_16(BNWORD16 *num, unsigned len, BNWORD16 borrow) -{ - BNWORD32 t; - assert(len > 0); /* Alternative: if (!len) return borrow */ - - t = (BNWORD32)BIGLITTLE(*--num,*num) - borrow; - BIGLITTLE(*num,*num++) = (BNWORD16)t; - if ((t >> 16) == 0) - return 0; - while (--len) { - if ((BIGLITTLE(*--num,*num++))-- != 0) - return 0; - } - return 1; -} -#else /* no BNWORD32 */ -BNWORD16 -lbnSub1_16(BNWORD16 *num, unsigned len, BNWORD16 borrow) -{ - assert(len > 0); /* Alternative: if (!len) return borrow */ - - if ((BIGLITTLE(*--num,*num++) -= borrow) <= (BNWORD16)~borrow) - return 0; - while (--len) { - if ((BIGLITTLE(*--num,*num++))-- != 0) - return 0; - } - return 1; -} -#endif -#endif /* !lbnSub1_16 */ - -/* - * lbnAddN_16: add two bignums of the same length, returning the carry (0 or 1). - * One of the building blocks, along with lbnAdd1, of adding two bignums of - * differing lengths. - * - * Technique: Maintain a word of carry. If there is no double-width type, - * use the same technique as in lbnAdd1, above, to maintain the carry by - * comparing the inputs. Adding the carry sources is used as an OR operator; - * at most one of the two comparisons can possibly be true. The first can - * only be true if carry == 1 and x, the result, is 0. In that case the - * second can't possibly be true. - */ -#ifndef lbnAddN_16 -#ifdef BNWORD32 -BNWORD16 -lbnAddN_16(BNWORD16 *num1, BNWORD16 const *num2, unsigned len) -{ - BNWORD32 t; - - assert(len > 0); - - t = (BNWORD32)BIGLITTLE(*--num1,*num1) + BIGLITTLE(*--num2,*num2++); - BIGLITTLE(*num1,*num1++) = (BNWORD16)t; - while (--len) { - t = (BNWORD32)BIGLITTLE(*--num1,*num1) + - (BNWORD32)BIGLITTLE(*--num2,*num2++) + (t >> 16); - BIGLITTLE(*num1,*num1++) = (BNWORD16)t; - } - - return (BNWORD16)(t>>16); -} -#else /* no BNWORD32 */ -BNWORD16 -lbnAddN_16(BNWORD16 *num1, BNWORD16 const *num2, unsigned len) -{ - BNWORD16 x, carry = 0; - - assert(len > 0); /* Alternative: change loop to test at start */ - - do { - x = BIGLITTLE(*--num2,*num2++); - carry = (x += carry) < carry; - carry += (BIGLITTLE(*--num1,*num1++) += x) < x; - } while (--len); - - return carry; -} -#endif -#endif /* !lbnAddN_16 */ - -/* - * lbnSubN_16: add two bignums of the same length, returning the carry (0 or 1). - * One of the building blocks, along with subn1, of subtracting two bignums of - * differing lengths. - * - * Technique: If no double-width type is availble, maintain a word of borrow. - * First, add the borrow to the subtrahend (did you have to learn all those - * awful words in elementary school, too?), and if it overflows, set the - * borrow again. Then subtract the modified subtrahend from the next word - * of input, using the same technique as in subn1, above. - * Adding the borrows is used as an OR operator; at most one of the two - * comparisons can possibly be true. The first can only be true if - * borrow == 1 and x, the result, is 0. In that case the second can't - * possibly be true. - * - * In the double-word case, (BNWORD16)-(t>>16) is subtracted, rather than - * adding t>>16, because the shift would need to sign-extend and that's - * not guaranteed to happen in ANSI C, even with signed types. - */ -#ifndef lbnSubN_16 -#ifdef BNWORD32 -BNWORD16 -lbnSubN_16(BNWORD16 *num1, BNWORD16 const *num2, unsigned len) -{ - BNWORD32 t; - - assert(len > 0); - - t = (BNWORD32)BIGLITTLE(*--num1,*num1) - BIGLITTLE(*--num2,*num2++); - BIGLITTLE(*num1,*num1++) = (BNWORD16)t; - - while (--len) { - t = (BNWORD32)BIGLITTLE(*--num1,*num1) - - (BNWORD32)BIGLITTLE(*--num2,*num2++) - (BNWORD16)-(t >> 16); - BIGLITTLE(*num1,*num1++) = (BNWORD16)t; - } - - return -(BNWORD16)(t>>16); -} -#else -BNWORD16 -lbnSubN_16(BNWORD16 *num1, BNWORD16 const *num2, unsigned len) -{ - BNWORD16 x, borrow = 0; - - assert(len > 0); /* Alternative: change loop to test at start */ - - do { - x = BIGLITTLE(*--num2,*num2++); - borrow = (x += borrow) < borrow; - borrow += (BIGLITTLE(*--num1,*num1++) -= x) > (BNWORD16)~x; - } while (--len); - - return borrow; -} -#endif -#endif /* !lbnSubN_16 */ - -#ifndef lbnCmp_16 -/* - * lbnCmp_16: compare two bignums of equal length, returning the sign of - * num1 - num2. (-1, 0 or +1). - * - * Technique: Change the little-endian pointers to big-endian pointers - * and compare from the most-significant end until a difference if found. - * When it is, figure out the sign of the difference and return it. - */ -int -lbnCmp_16(BNWORD16 const *num1, BNWORD16 const *num2, unsigned len) -{ - BIGLITTLE(num1 -= len, num1 += len); - BIGLITTLE(num2 -= len, num2 += len); - - while (len--) { - if (BIGLITTLE(*num1++ != *num2++, *--num1 != *--num2)) { - if (BIGLITTLE(num1[-1] < num2[-1], *num1 < *num2)) - return -1; - else - return 1; - } - } - return 0; -} -#endif /* !lbnCmp_16 */ - -/* - * mul16_ppmmaa(ph,pl,x,y,a,b) is an optional routine that - * computes (ph,pl) = x * y + a + b. mul16_ppmma and mul16_ppmm - * are simpler versions. If you want to be lazy, all of these - * can be defined in terms of the others, so here we create any - * that have not been defined in terms of the ones that have been. - */ - -/* Define ones with fewer a's in terms of ones with more a's */ -#if !defined(mul16_ppmma) && defined(mul16_ppmmaa) -#define mul16_ppmma(ph,pl,x,y,a) mul16_ppmmaa(ph,pl,x,y,a,0) -#endif - -#if !defined(mul16_ppmm) && defined(mul16_ppmma) -#define mul16_ppmm(ph,pl,x,y) mul16_ppmma(ph,pl,x,y,0) -#endif - -/* - * Use this definition to test the mul16_ppmm-based operations on machines - * that do not provide mul16_ppmm. Change the final "0" to a "1" to - * enable it. - */ -#if !defined(mul16_ppmm) && defined(BNWORD32) && 0 /* Debugging */ -#define mul16_ppmm(ph,pl,x,y) \ - ({BNWORD32 _ = (BNWORD32)(x)*(y); (pl) = _; (ph) = _>>16;}) -#endif - -#if defined(mul16_ppmm) && !defined(mul16_ppmma) -#define mul16_ppmma(ph,pl,x,y,a) \ - (mul16_ppmm(ph,pl,x,y), (ph) += ((pl) += (a)) < (a)) -#endif - -#if defined(mul16_ppmma) && !defined(mul16_ppmmaa) -#define mul16_ppmmaa(ph,pl,x,y,a,b) \ - (mul16_ppmma(ph,pl,x,y,a), (ph) += ((pl) += (b)) < (b)) -#endif - -/* - * lbnMulN1_16: Multiply an n-word input by a 1-word input and store the - * n+1-word product. This uses either the mul16_ppmm and mul16_ppmma - * macros, or C multiplication with the BNWORD32 type. This uses mul16_ppmma - * if available, assuming you won't bother defining it unless you can do - * better than the normal multiplication. - */ -#ifndef lbnMulN1_16 -#ifdef lbnMulAdd1_16 /* If we have this asm primitive, use it. */ -void -lbnMulN1_16(BNWORD16 *out, BNWORD16 const *in, unsigned len, BNWORD16 k) -{ - lbnZero_16(out, len); - BIGLITTLE(*(out-len),*(out+len)) = lbnMulAdd1_16(out, in, len, k); -} -#elif defined(mul16_ppmm) -void -lbnMulN1_16(BNWORD16 *out, BNWORD16 const *in, unsigned len, BNWORD16 k) -{ - BNWORD16 prod, carry, carryin; - - assert(len > 0); - - BIG(--out;--in;); - mul16_ppmm(carry, *out, *in, k); - LITTLE(out++;in++;) - - while (--len) { - BIG(--out;--in;) - carryin = carry; - mul16_ppmma(carry, *out, *in, k, carryin); - LITTLE(out++;in++;) - } - BIGLITTLE(*--out,*out) = carry; -} -#elif defined(BNWORD32) -void -lbnMulN1_16(BNWORD16 *out, BNWORD16 const *in, unsigned len, BNWORD16 k) -{ - BNWORD32 p; - - assert(len > 0); - - p = (BNWORD32)BIGLITTLE(*--in,*in++) * k; - BIGLITTLE(*--out,*out++) = (BNWORD16)p; - - while (--len) { - p = (BNWORD32)BIGLITTLE(*--in,*in++) * k + (BNWORD16)(p >> 16); - BIGLITTLE(*--out,*out++) = (BNWORD16)p; - } - BIGLITTLE(*--out,*out) = (BNWORD16)(p >> 16); -} -#else -#error No 16x16 -> 32 multiply available for 16-bit bignum package -#endif -#endif /* lbnMulN1_16 */ - -/* - * lbnMulAdd1_16: Multiply an n-word input by a 1-word input and add the - * low n words of the product to the destination. *Returns the n+1st word - * of the product.* (That turns out to be more convenient than adding - * it into the destination and dealing with a possible unit carry out - * of *that*.) This uses either the mul16_ppmma and mul16_ppmmaa macros, - * or C multiplication with the BNWORD32 type. - * - * If you're going to write assembly primitives, this is the one to - * start with. It is by far the most commonly called function. - */ -#ifndef lbnMulAdd1_16 -#if defined(mul16_ppmm) -BNWORD16 -lbnMulAdd1_16(BNWORD16 *out, BNWORD16 const *in, unsigned len, BNWORD16 k) -{ - BNWORD16 prod, carry, carryin; - - assert(len > 0); - - BIG(--out;--in;); - carryin = *out; - mul16_ppmma(carry, *out, *in, k, carryin); - LITTLE(out++;in++;) - - while (--len) { - BIG(--out;--in;); - carryin = carry; - mul16_ppmmaa(carry, prod, *in, k, carryin, *out); - *out = prod; - LITTLE(out++;in++;) - } - - return carry; -} -#elif defined(BNWORD32) -BNWORD16 -lbnMulAdd1_16(BNWORD16 *out, BNWORD16 const *in, unsigned len, BNWORD16 k) -{ - BNWORD32 p; - - assert(len > 0); - - p = (BNWORD32)BIGLITTLE(*--in,*in++) * k + BIGLITTLE(*--out,*out); - BIGLITTLE(*out,*out++) = (BNWORD16)p; - - while (--len) { - p = (BNWORD32)BIGLITTLE(*--in,*in++) * k + - (BNWORD16)(p >> 16) + BIGLITTLE(*--out,*out); - BIGLITTLE(*out,*out++) = (BNWORD16)p; - } - - return (BNWORD16)(p >> 16); -} -#else -#error No 16x16 -> 32 multiply available for 16-bit bignum package -#endif -#endif /* lbnMulAdd1_16 */ - -/* - * lbnMulSub1_16: Multiply an n-word input by a 1-word input and subtract the - * n-word product from the destination. Returns the n+1st word of the product. - * This uses either the mul16_ppmm and mul16_ppmma macros, or - * C multiplication with the BNWORD32 type. - * - * This is rather uglier than adding, but fortunately it's only used in - * division which is not used too heavily. - */ -#ifndef lbnMulN1_16 -#if defined(mul16_ppmm) -BNWORD16 -lbnMulSub1_16(BNWORD16 *out, BNWORD16 const *in, unsigned len, BNWORD16 k) -{ - BNWORD16 prod, carry, carryin; - - assert(len > 0); - - BIG(--in;) - mul16_ppmm(carry, prod, *in, k); - LITTLE(in++;) - carry += (BIGLITTLE(*--out,*out++) -= prod) > (BNWORD16)~prod; - - while (--len) { - BIG(--in;); - carryin = carry; - mul16_ppmma(carry, prod, *in, k, carryin); - LITTLE(in++;) - carry += (BIGLITTLE(*--out,*out++) -= prod) > (BNWORD16)~prod; - } - - return carry; -} -#elif defined(BNWORD32) -BNWORD16 -lbnMulSub1_16(BNWORD16 *out, BNWORD16 const *in, unsigned len, BNWORD16 k) -{ - BNWORD32 p; - BNWORD16 carry, t; - - assert(len > 0); - - p = (BNWORD32)BIGLITTLE(*--in,*in++) * k; - t = BIGLITTLE(*--out,*out); - carry = (BNWORD16)(p>>16) + ((BIGLITTLE(*out,*out++)=t-(BNWORD16)p) > t); - - while (--len) { - p = (BNWORD32)BIGLITTLE(*--in,*in++) * k + carry; - t = BIGLITTLE(*--out,*out); - carry = (BNWORD16)(p>>16) + - ( (BIGLITTLE(*out,*out++)=t-(BNWORD16)p) > t ); - } - - return carry; -} -#else -#error No 16x16 -> 32 multiply available for 16-bit bignum package -#endif -#endif /* !lbnMulSub1_16 */ - -/* - * Shift n words left "shift" bits. 0 < shift < 16. Returns the - * carry, any bits shifted off the left-hand side (0 <= carry < 2^shift). - */ -#ifndef lbnLshift_16 -BNWORD16 -lbnLshift_16(BNWORD16 *num, unsigned len, unsigned shift) -{ - BNWORD16 x, carry; - - assert(shift > 0); - assert(shift < 16); - - carry = 0; - while (len--) { - BIG(--num;) - x = *num; - *num = (x<<shift) | carry; - LITTLE(num++;) - carry = x >> (16-shift); - } - return carry; -} -#endif /* !lbnLshift_16 */ - -/* - * An optimized version of the above, for shifts of 1. - * Some machines can use add-with-carry tricks for this. - */ -#ifndef lbnDouble_16 -BNWORD16 -lbnDouble_16(BNWORD16 *num, unsigned len) -{ - BNWORD16 x, carry; - - carry = 0; - while (len--) { - BIG(--num;) - x = *num; - *num = (x<<1) | carry; - LITTLE(num++;) - carry = x >> (16-1); - } - return carry; -} -#endif /* !lbnDouble_16 */ - -/* - * Shift n words right "shift" bits. 0 < shift < 16. Returns the - * carry, any bits shifted off the right-hand side (0 <= carry < 2^shift). - */ -#ifndef lbnRshift_16 -BNWORD16 -lbnRshift_16(BNWORD16 *num, unsigned len, unsigned shift) -{ - BNWORD16 x, carry = 0; - - assert(shift > 0); - assert(shift < 16); - - BIGLITTLE(num -= len, num += len); - - while (len--) { - LITTLE(--num;) - x = *num; - *num = (x>>shift) | carry; - BIG(num++;) - carry = x << (16-shift); - } - return carry >> (16-shift); -} -#endif /* !lbnRshift_16 */ - -/* - * Multiply two numbers of the given lengths. prod and num2 may overlap, - * provided that the low len1 bits of prod are free. (This corresponds - * nicely to the place the result is returned from lbnMontReduce_16.) - * - * TODO: Use Karatsuba multiply. The overlap constraints may have - * to get rewhacked. - */ -#ifndef lbnMul_16 -void -lbnMul_16(BNWORD16 *prod, BNWORD16 const *num1, unsigned len1, - BNWORD16 const *num2, unsigned len2) -{ - /* Special case of zero */ - if (!len1 || !len2) { - lbnZero_16(prod, len1+len2); - return; - } - - /* Multiply first word */ - lbnMulN1_16(prod, num1, len1, BIGLITTLE(*--num2,*num2++)); - - /* - * Add in subsequent words, storing the most significant word, - * which is new each time. - */ - while (--len2) { - BIGLITTLE(--prod,prod++); - BIGLITTLE(*(prod-len1-1),*(prod+len1)) = - lbnMulAdd1_16(prod, num1, len1, BIGLITTLE(*--num2,*num2++)); - } -} -#endif /* !lbnMul_16 */ - -/* - * lbnMulX_16 is a square multiply - both inputs are the same length. - * It's normally just a macro wrapper around the general multiply, - * but might be implementable in assembly more efficiently (such as - * when product scanning). - */ -#ifndef lbnMulX_16 -#if defined(BNWORD32) && PRODUCT_SCAN -/* - * Test code to see whether product scanning is any faster. It seems - * to make the C code slower, so PRODUCT_SCAN is not defined. - */ -static void -lbnMulX_16(BNWORD16 *prod, BNWORD16 const *num1, BNWORD16 const *num2, - unsigned len) -{ - BNWORD32 x, y; - BNWORD16 const *p1, *p2; - unsigned carry; - unsigned i, j; - - /* Special case of zero */ - if (!len) - return; - - x = (BNWORD32)BIGLITTLE(num1[-1] * num2[-1], num1[0] * num2[0]); - BIGLITTLE(*--prod, *prod++) = (BNWORD16)x; - x >>= 16; - - for (i = 1; i < len; i++) { - carry = 0; - p1 = num1; - p2 = BIGLITTLE(num2-i-1,num2+i+1); - for (j = 0; j <= i; j++) { - BIG(y = (BNWORD32)*--p1 * *p2++;) - LITTLE(y = (BNWORD32)*p1++ * *--p2;) - x += y; - carry += (x < y); - } - BIGLITTLE(*--prod,*prod++) = (BNWORD16)x; - x = (x >> 16) | (BNWORD32)carry << 16; - } - for (i = 1; i < len; i++) { - carry = 0; - p1 = BIGLITTLE(num1-i,num1+i); - p2 = BIGLITTLE(num2-len,num2+len); - for (j = i; j < len; j++) { - BIG(y = (BNWORD32)*--p1 * *p2++;) - LITTLE(y = (BNWORD32)*p1++ * *--p2;) - x += y; - carry += (x < y); - } - BIGLITTLE(*--prod,*prod++) = (BNWORD16)x; - x = (x >> 16) | (BNWORD32)carry << 16; - } - - BIGLITTLE(*--prod,*prod) = (BNWORD16)x; -} -#else /* !defined(BNWORD32) || !PRODUCT_SCAN */ -/* Default trivial macro definition */ -#define lbnMulX_16(prod, num1, num2, len) lbnMul_16(prod, num1, len, num2, len) -#endif /* !defined(BNWORD32) || !PRODUCT_SCAN */ -#endif /* !lbmMulX_16 */ - -#if !defined(lbnMontMul_16) && defined(BNWORD32) && PRODUCT_SCAN -/* - * Test code for product-scanning multiply. This seems to slow the C - * code down rather than speed it up. - * This does a multiply and Montgomery reduction together, using the - * same loops. The outer loop scans across the product, twice. - * The first pass computes the low half of the product and the - * Montgomery multipliers. These are stored in the product array, - * which contains no data as of yet. x and carry add up the columns - * and propagate carries forward. - * - * The second half multiplies the upper half, adding in the modulus - * times the Montgomery multipliers. The results of this multiply - * are stored. - */ -static void -lbnMontMul_16(BNWORD16 *prod, BNWORD16 const *num1, BNWORD16 const *num2, - BNWORD16 const *mod, unsigned len, BNWORD16 inv) -{ - BNWORD32 x, y; - BNWORD16 const *p1, *p2, *pm; - BNWORD16 *pp; - BNWORD16 t; - unsigned carry; - unsigned i, j; - - /* Special case of zero */ - if (!len) - return; - - /* - * This computes directly into the high half of prod, so just - * shift the pointer and consider prod only "len" elements long - * for the rest of the code. - */ - BIGLITTLE(prod -= len, prod += len); - - /* Pass 1 - compute Montgomery multipliers */ - /* First iteration can have certain simplifications. */ - x = (BNWORD32)BIGLITTLE(num1[-1] * num2[-1], num1[0] * num2[0]); - BIGLITTLE(prod[-1], prod[0]) = t = inv * (BNWORD16)x; - y = (BNWORD32)t * BIGLITTLE(mod[-1],mod[0]); - x += y; - /* Note: GCC 2.6.3 has a bug if you try to eliminate "carry" */ - carry = (x < y); - assert((BNWORD16)x == 0); - x = x >> 16 | (BNWORD32)carry << 16; - - for (i = 1; i < len; i++) { - carry = 0; - p1 = num1; - p2 = BIGLITTLE(num2-i-1,num2+i+1); - pp = prod; - pm = BIGLITTLE(mod-i-1,mod+i+1); - for (j = 0; j < i; j++) { - y = (BNWORD32)BIGLITTLE(*--p1 * *p2++, *p1++ * *--p2); - x += y; - carry += (x < y); - y = (BNWORD32)BIGLITTLE(*--pp * *pm++, *pp++ * *--pm); - x += y; - carry += (x < y); - } - y = (BNWORD32)BIGLITTLE(p1[-1] * p2[0], p1[0] * p2[-1]); - x += y; - carry += (x < y); - assert(BIGLITTLE(pp == prod-i, pp == prod+i)); - BIGLITTLE(pp[-1], pp[0]) = t = inv * (BNWORD16)x; - assert(BIGLITTLE(pm == mod-1, pm == mod+1)); - y = (BNWORD32)t * BIGLITTLE(pm[0],pm[-1]); - x += y; - carry += (x < y); - assert((BNWORD16)x == 0); - x = x >> 16 | (BNWORD32)carry << 16; - } - - /* Pass 2 - compute reduced product and store */ - for (i = 1; i < len; i++) { - carry = 0; - p1 = BIGLITTLE(num1-i,num1+i); - p2 = BIGLITTLE(num2-len,num2+len); - pm = BIGLITTLE(mod-i,mod+i); - pp = BIGLITTLE(prod-len,prod+len); - for (j = i; j < len; j++) { - y = (BNWORD32)BIGLITTLE(*--p1 * *p2++, *p1++ * *--p2); - x += y; - carry += (x < y); - y = (BNWORD32)BIGLITTLE(*--pm * *pp++, *pm++ * *--pp); - x += y; - carry += (x < y); - } - assert(BIGLITTLE(pm == mod-len, pm == mod+len)); - assert(BIGLITTLE(pp == prod-i, pp == prod+i)); - BIGLITTLE(pp[0],pp[-1]) = (BNWORD16)x; - x = (x >> 16) | (BNWORD32)carry << 16; - } - - /* Last round of second half, simplified. */ - BIGLITTLE(*(prod-len),*(prod+len-1)) = (BNWORD16)x; - carry = (x >> 16); - - while (carry) - carry -= lbnSubN_16(prod, mod, len); - while (lbnCmp_16(prod, mod, len) >= 0) - (void)lbnSubN_16(prod, mod, len); -} -/* Suppress later definition */ -#define lbnMontMul_16 lbnMontMul_16 -#endif - -#if !defined(lbnSquare_16) && defined(BNWORD32) && PRODUCT_SCAN -/* - * Trial code for product-scanning squaring. This seems to slow the C - * code down rather than speed it up. - */ -void -lbnSquare_16(BNWORD16 *prod, BNWORD16 const *num, unsigned len) -{ - BNWORD32 x, y, z; - BNWORD16 const *p1, *p2; - unsigned carry; - unsigned i, j; - - /* Special case of zero */ - if (!len) - return; - - /* Word 0 of product */ - x = (BNWORD32)BIGLITTLE(num[-1] * num[-1], num[0] * num[0]); - BIGLITTLE(*--prod, *prod++) = (BNWORD16)x; - x >>= 16; - - /* Words 1 through len-1 */ - for (i = 1; i < len; i++) { - carry = 0; - y = 0; - p1 = num; - p2 = BIGLITTLE(num-i-1,num+i+1); - for (j = 0; j < (i+1)/2; j++) { - BIG(z = (BNWORD32)*--p1 * *p2++;) - LITTLE(z = (BNWORD32)*p1++ * *--p2;) - y += z; - carry += (y < z); - } - y += z = y; - carry += carry + (y < z); - if ((i & 1) == 0) { - assert(BIGLITTLE(--p1 == p2, p1 == --p2)); - BIG(z = (BNWORD32)*p2 * *p2;) - LITTLE(z = (BNWORD32)*p1 * *p1;) - y += z; - carry += (y < z); - } - x += y; - carry += (x < y); - BIGLITTLE(*--prod,*prod++) = (BNWORD16)x; - x = (x >> 16) | (BNWORD32)carry << 16; - } - /* Words len through 2*len-2 */ - for (i = 1; i < len; i++) { - carry = 0; - y = 0; - p1 = BIGLITTLE(num-i,num+i); - p2 = BIGLITTLE(num-len,num+len); - for (j = 0; j < (len-i)/2; j++) { - BIG(z = (BNWORD32)*--p1 * *p2++;) - LITTLE(z = (BNWORD32)*p1++ * *--p2;) - y += z; - carry += (y < z); - } - y += z = y; - carry += carry + (y < z); - if ((len-i) & 1) { - assert(BIGLITTLE(--p1 == p2, p1 == --p2)); - BIG(z = (BNWORD32)*p2 * *p2;) - LITTLE(z = (BNWORD32)*p1 * *p1;) - y += z; - carry += (y < z); - } - x += y; - carry += (x < y); - BIGLITTLE(*--prod,*prod++) = (BNWORD16)x; - x = (x >> 16) | (BNWORD32)carry << 16; - } - - /* Word 2*len-1 */ - BIGLITTLE(*--prod,*prod) = (BNWORD16)x; -} -/* Suppress later definition */ -#define lbnSquare_16 lbnSquare_16 -#endif - -/* - * Square a number, using optimized squaring to reduce the number of - * primitive multiples that are executed. There may not be any - * overlap of the input and output. - * - * Technique: Consider the partial products in the multiplication - * of "abcde" by itself: - * - * a b c d e - * * a b c d e - * ================== - * ae be ce de ee - * ad bd cd dd de - * ac bc cc cd ce - * ab bb bc bd be - * aa ab ac ad ae - * - * Note that everything above the main diagonal: - * ae be ce de = (abcd) * e - * ad bd cd = (abc) * d - * ac bc = (ab) * c - * ab = (a) * b - * - * is a copy of everything below the main diagonal: - * de - * cd ce - * bc bd be - * ab ac ad ae - * - * Thus, the sum is 2 * (off the diagonal) + diagonal. - * - * This is accumulated beginning with the diagonal (which - * consist of the squares of the digits of the input), which is then - * divided by two, the off-diagonal added, and multiplied by two - * again. The low bit is simply a copy of the low bit of the - * input, so it doesn't need special care. - * - * TODO: Merge the shift by 1 with the squaring loop. - * TODO: Use Karatsuba. (a*W+b)^2 = a^2 * (W^2+W) + b^2 * (W+1) - (a-b)^2 * W. - */ -#ifndef lbnSquare_16 -void -lbnSquare_16(BNWORD16 *prod, BNWORD16 const *num, unsigned len) -{ - BNWORD16 t; - BNWORD16 *prodx = prod; /* Working copy of the argument */ - BNWORD16 const *numx = num; /* Working copy of the argument */ - unsigned lenx = len; /* Working copy of the argument */ - - if (!len) - return; - - /* First, store all the squares */ - while (lenx--) { -#ifdef mul16_ppmm - BNWORD16 ph, pl; - t = BIGLITTLE(*--numx,*numx++); - mul16_ppmm(ph,pl,t,t); - BIGLITTLE(*--prodx,*prodx++) = pl; - BIGLITTLE(*--prodx,*prodx++) = ph; -#elif defined(BNWORD32) /* use BNWORD32 */ - BNWORD32 p; - t = BIGLITTLE(*--numx,*numx++); - p = (BNWORD32)t * t; - BIGLITTLE(*--prodx,*prodx++) = (BNWORD16)p; - BIGLITTLE(*--prodx,*prodx++) = (BNWORD16)(p>>16); -#else /* Use lbnMulN1_16 */ - t = BIGLITTLE(numx[-1],*numx); - lbnMulN1_16(prodx, numx, 1, t); - BIGLITTLE(--numx,numx++); - BIGLITTLE(prodx -= 2, prodx += 2); -#endif - } - /* Then, shift right 1 bit */ - (void)lbnRshift_16(prod, 2*len, 1); - - /* Then, add in the off-diagonal sums */ - lenx = len; - numx = num; - prodx = prod; - while (--lenx) { - t = BIGLITTLE(*--numx,*numx++); - BIGLITTLE(--prodx,prodx++); - t = lbnMulAdd1_16(prodx, numx, lenx, t); - lbnAdd1_16(BIGLITTLE(prodx-lenx,prodx+lenx), lenx+1, t); - BIGLITTLE(--prodx,prodx++); - } - - /* Shift it back up */ - lbnDouble_16(prod, 2*len); - - /* And set the low bit appropriately */ - BIGLITTLE(prod[-1],prod[0]) |= BIGLITTLE(num[-1],num[0]) & 1; -} -#endif /* !lbnSquare_16 */ - -/* - * lbnNorm_16 - given a number, return a modified length such that the - * most significant digit is non-zero. Zero-length input is okay. - */ -#ifndef lbnNorm_16 -unsigned -lbnNorm_16(BNWORD16 const *num, unsigned len) -{ - BIGLITTLE(num -= len,num += len); - while (len && BIGLITTLE(*num++,*--num) == 0) - --len; - return len; -} -#endif /* lbnNorm_16 */ - -/* - * lbnBits_16 - return the number of significant bits in the array. - * It starts by normalizing the array. Zero-length input is okay. - * Then assuming there's anything to it, it fetches the high word, - * generates a bit length by multiplying the word length by 16, and - * subtracts off 16/2, 16/4, 16/8, ... bits if the high bits are clear. - */ -#ifndef lbnBits_16 -unsigned -lbnBits_16(BNWORD16 const *num, unsigned len) -{ - BNWORD16 t; - unsigned i; - - len = lbnNorm_16(num, len); - if (len) { - t = BIGLITTLE(*(num-len),*(num+(len-1))); - assert(t); - len *= 16; - i = 16/2; - do { - if (t >> i) - t >>= i; - else - len -= i; - } while ((i /= 2) != 0); - } - return len; -} -#endif /* lbnBits_16 */ - -/* - * If defined, use hand-rolled divide rather than compiler's native. - * If the machine doesn't do it in line, the manual code is probably - * faster, since it can assume normalization and the fact that the - * quotient will fit into 16 bits, which a general 32-bit divide - * in a compiler's run-time library can't do. - */ -#ifndef BN_SLOW_DIVIDE_32 -/* Assume that divisors of more than thirty-two bits are slow */ -#define BN_SLOW_DIVIDE_32 (32 > 0x20) -#endif - -/* - * Return (nh<<16|nl) % d, and place the quotient digit into *q. - * It is guaranteed that nh < d, and that d is normalized (with its high - * bit set). If we have a double-width type, it's easy. If not, ooh, - * yuk! - */ -#ifndef lbnDiv21_16 -#if defined(BNWORD32) && !BN_SLOW_DIVIDE_32 -BNWORD16 -lbnDiv21_16(BNWORD16 *q, BNWORD16 nh, BNWORD16 nl, BNWORD16 d) -{ - BNWORD32 n = (BNWORD32)nh << 16 | nl; - - /* Divisor must be normalized */ - assert(d >> (16-1) == 1); - - *q = (BNWORD16)(n / d); - return (BNWORD16)(n % d); -} -#else -/* - * This is where it gets ugly. - * - * Do the division in two halves, using Algorithm D from section 4.3.1 - * of Knuth. Note Theorem B from that section, that the quotient estimate - * is never more than the true quotient, and is never more than two - * too low. - * - * The mapping onto conventional long division is (everything a half word): - * _____________qh___ql_ - * dh dl ) nh.h nh.l nl.h nl.l - * - (qh * d) - * ----------- - * rrrr rrrr nl.l - * - (ql * d) - * ----------- - * rrrr rrrr - * - * The implicit 3/2-digit d*qh and d*ql subtractors are computed this way: - * First, estimate a q digit so that nh/dh works. Subtracting qh*dh from - * the (nh.h nh.l) list leaves a 1/2-word remainder r. Then compute the - * low part of the subtractor, qh * dl. This also needs to be subtracted - * from (nh.h nh.l nl.h) to get the final remainder. So we take the - * remainder, which is (nh.h nh.l) - qh*dl, shift it and add in nl.h, and - * try to subtract qh * dl from that. Since the remainder is 1/2-word - * long, shifting and adding nl.h results in a single word r. - * It is possible that the remainder we're working with, r, is less than - * the product qh * dl, if we estimated qh too high. The estimation - * technique can produce a qh that is too large (never too small), leading - * to r which is too small. In that case, decrement the digit qh, add - * shifted dh to r (to correct for that error), and subtract dl from the - * product we're comparing r with. That's the "correct" way to do it, but - * just adding dl to r instead of subtracting it from the product is - * equivalent and a lot simpler. You just have to watch out for overflow. - * - * The process is repeated with (rrrr rrrr nl.l) for the low digit of the - * quotient ql. - * - * The various uses of 16/2 for shifts are because of the note about - * automatic editing of this file at the very top of the file. - */ -#define highhalf(x) ( (x) >> 16/2 ) -#define lowhalf(x) ( (x) & (((BNWORD16)1 << 16/2)-1) ) -BNWORD16 -lbnDiv21_16(BNWORD16 *q, BNWORD16 nh, BNWORD16 nl, BNWORD16 d) -{ - BNWORD16 dh = highhalf(d), dl = lowhalf(d); - BNWORD16 qh, ql, prod, r; - - /* Divisor must be normalized */ - assert((d >> (16-1)) == 1); - - /* Do first half-word of division */ - qh = nh / dh; - r = nh % dh; - prod = qh * dl; - - /* - * Add next half-word of numerator to remainder and correct. - * qh may be up to two too large. - */ - r = (r << (16/2)) | highhalf(nl); - if (r < prod) { - --qh; r += d; - if (r >= d && r < prod) { - --qh; r += d; - } - } - r -= prod; - - /* Do second half-word of division */ - ql = r / dh; - r = r % dh; - prod = ql * dl; - - r = (r << (16/2)) | lowhalf(nl); - if (r < prod) { - --ql; r += d; - if (r >= d && r < prod) { - --ql; r += d; - } - } - r -= prod; - - *q = (qh << (16/2)) | ql; - - return r; -} -#endif -#endif /* lbnDiv21_16 */ - - -/* - * In the division functions, the dividend and divisor are referred to - * as "n" and "d", which stand for "numerator" and "denominator". - * - * The quotient is (nlen-dlen+1) digits long. It may be overlapped with - * the high (nlen-dlen) words of the dividend, but one extra word is needed - * on top to hold the top word. - */ - -/* - * Divide an n-word number by a 1-word number, storing the remainder - * and n-1 words of the n-word quotient. The high word is returned. - * It IS legal for rem to point to the same address as n, and for - * q to point one word higher. - * - * TODO: If BN_SLOW_DIVIDE_32, add a divnhalf_16 which uses 16-bit - * dividends if the divisor is half that long. - * TODO: Shift the dividend on the fly to avoid the last division and - * instead have a remainder that needs shifting. - * TODO: Use reciprocals rather than dividing. - */ -#ifndef lbnDiv1_16 -BNWORD16 -lbnDiv1_16(BNWORD16 *q, BNWORD16 *rem, BNWORD16 const *n, unsigned len, - BNWORD16 d) -{ - unsigned shift; - unsigned xlen; - BNWORD16 r; - BNWORD16 qhigh; - - assert(len > 0); - assert(d); - - if (len == 1) { - r = *n; - *rem = r%d; - return r/d; - } - - shift = 0; - r = d; - xlen = 16/2; - do { - if (r >> xlen) - r >>= xlen; - else - shift += xlen; - } while ((xlen /= 2) != 0); - assert((d >> (16-1-shift)) == 1); - d <<= shift; - - BIGLITTLE(q -= len-1,q += len-1); - BIGLITTLE(n -= len,n += len); - - r = BIGLITTLE(*n++,*--n); - if (r < d) { - qhigh = 0; - } else { - qhigh = r/d; - r %= d; - } - - xlen = len; - while (--xlen) - r = lbnDiv21_16(BIGLITTLE(q++,--q), r, BIGLITTLE(*n++,*--n), d); - - /* - * Final correction for shift - shift the quotient up "shift" - * bits, and merge in the extra bits of quotient. Then reduce - * the final remainder mod the real d. - */ - if (shift) { - d >>= shift; - qhigh = (qhigh << shift) | lbnLshift_16(q, len-1, shift); - BIGLITTLE(q[-1],*q) |= r/d; - r %= d; - } - *rem = r; - - return qhigh; -} -#endif - -/* - * This function performs a "quick" modulus of a number with a divisor - * d which is guaranteed to be at most sixteen bits, i.e. less than 65536. - * This applies regardless of the word size the library is compiled with. - * - * This function is important to prime generation, for sieving. - */ -#ifndef lbnModQ_16 -/* If there's a custom lbnMod21_16, no normalization needed */ -#ifdef lbnMod21_16 -unsigned -lbnModQ_16(BNWORD16 const *n, unsigned len, unsigned d) -{ - unsigned i, shift; - BNWORD16 r; - - assert(len > 0); - - BIGLITTLE(n -= len,n += len); - - /* Try using a compare to avoid the first divide */ - r = BIGLITTLE(*n++,*--n); - if (r >= d) - r %= d; - while (--len) - r = lbnMod21_16(r, BIGLITTLE(*n++,*--n), d); - - return r; -} -#elif defined(BNWORD32) && !BN_SLOW_DIVIDE_32 -unsigned -lbnModQ_16(BNWORD16 const *n, unsigned len, unsigned d) -{ - BNWORD16 r; - - if (!--len) - return BIGLITTLE(n[-1],n[0]) % d; - - BIGLITTLE(n -= len,n += len); - r = BIGLITTLE(n[-1],n[0]); - - do { - r = (BNWORD16)((((BNWORD32)r<<16) | BIGLITTLE(*n++,*--n)) % d); - } while (--len); - - return r; -} -#elif 16 >= 0x20 -/* - * If the single word size can hold 65535*65536, then this function - * is avilable. - */ -#ifndef highhalf -#define highhalf(x) ( (x) >> 16/2 ) -#define lowhalf(x) ( (x) & ((1 << 16/2)-1) ) -#endif -unsigned -lbnModQ_16(BNWORD16 const *n, unsigned len, unsigned d) -{ - BNWORD16 r, x; - - BIGLITTLE(n -= len,n += len); - - r = BIGLITTLE(*n++,*--n); - while (--len) { - x = BIGLITTLE(*n++,*--n); - r = (r%d << 16/2) | highhalf(x); - r = (r%d << 16/2) | lowhalf(x); - } - - return r%d; -} -#else -/* Default case - use lbnDiv21_16 */ -unsigned -lbnModQ_16(BNWORD16 const *n, unsigned len, unsigned d) -{ - unsigned i, shift; - BNWORD16 r; - BNWORD16 q; - - assert(len > 0); - - shift = 0; - r = d; - i = 16; - while (i /= 2) { - if (r >> i) - r >>= i; - else - shift += i; - } - assert(d >> (16-1-shift) == 1); - d <<= shift; - - BIGLITTLE(n -= len,n += len); - - r = BIGLITTLE(*n++,*--n); - if (r >= d) - r %= d; - - while (--len) - r = lbnDiv21_16(&q, r, BIGLITTLE(*n++,*--n), d); - - /* - * Final correction for shift - shift the quotient up "shift" - * bits, and merge in the extra bits of quotient. Then reduce - * the final remainder mod the real d. - */ - if (shift) - r %= d >> shift; - - return r; -} -#endif -#endif /* lbnModQ_16 */ - -/* - * Reduce n mod d and return the quotient. That is, find: - * q = n / d; - * n = n % d; - * d is altered during the execution of this subroutine by normalizing it. - * It must already have its most significant word non-zero; it is shifted - * so its most significant bit is non-zero. - * - * The quotient q is nlen-dlen+1 words long. To make it possible to - * overlap the quptient with the input (you can store it in the high dlen - * words), the high word of the quotient is *not* stored, but is returned. - * (If all you want is the remainder, you don't care about it, anyway.) - * - * This uses algorithm D from Knuth (4.3.1), except that we do binary - * (shift) normalization of the divisor. WARNING: This is hairy! - * - * This function is used for some modular reduction, but it is not used in - * the modular exponentiation loops; they use Montgomery form and the - * corresponding, more efficient, Montgomery reduction. This code - * is needed for the conversion to Montgomery form, however, so it - * has to be here and it might as well be reasonably efficient. - * - * The overall operation is as follows ("top" and "up" refer to the - * most significant end of the number; "bottom" and "down", the least): - * - * - Shift the divisor up until the most significant bit is set. - * - Shift the dividend up the same amount. This will produce the - * correct quotient, and the remainder can be recovered by shifting - * it back down the same number of bits. This may produce an overflow - * word, but the word is always strictly less than the most significant - * divisor word. - * - Estimate the first quotient digit qhat: - * - First take the top two words (one of which is the overflow) of the - * dividend and divide by the top word of the divisor: - * qhat = (nh,nm)/dh. This qhat is >= the correct quotient digit - * and, since dh is normalized, it is at most two over. - * - Second, correct by comparing the top three words. If - * (dh,dl) * qhat > (nh,nm,ml), decrease qhat and try again. - * The second iteration can be simpler because there can't be a third. - * The computation can be simplified by subtracting dh*qhat from - * both sides, suitably shifted. This reduces the left side to - * dl*qhat. On the right, (nh,nm)-dh*qhat is simply the - * remainder r from (nh,nm)%dh, so the right is (r,nl). - * This produces qhat that is almost always correct and at - * most (prob ~ 2/2^16) one too high. - * - Subtract qhat times the divisor (suitably shifted) from the dividend. - * If there is a borrow, qhat was wrong, so decrement it - * and add the divisor back in (once). - * - Store the final quotient digit qhat in the quotient array q. - * - * Repeat the quotient digit computation for successive digits of the - * quotient until the whole quotient has been computed. Then shift the - * divisor and the remainder down to correct for the normalization. - * - * TODO: Special case 2-word divisors. - * TODO: Use reciprocals rather than dividing. - */ -#ifndef divn_16 -BNWORD16 -lbnDiv_16(BNWORD16 *q, BNWORD16 *n, unsigned nlen, BNWORD16 *d, unsigned dlen) -{ - BNWORD16 nh,nm,nl; /* Top three words of the dividend */ - BNWORD16 dh,dl; /* Top two words of the divisor */ - BNWORD16 qhat; /* Extimate of quotient word */ - BNWORD16 r; /* Remainder from quotient estimate division */ - BNWORD16 qhigh; /* High word of quotient */ - unsigned i; /* Temp */ - unsigned shift; /* Bits shifted by normalization */ - unsigned qlen = nlen-dlen; /* Size of quotient (less 1) */ -#ifdef mul16_ppmm - BNWORD16 t16; -#elif defined(BNWORD32) - BNWORD32 t32; -#else /* use lbnMulN1_16 */ - BNWORD16 t2[2]; -#define t2high BIGLITTLE(t2[0],t2[1]) -#define t2low BIGLITTLE(t2[1],t2[0]) -#endif - - assert(dlen); - assert(nlen >= dlen); - - /* - * Special cases for short divisors. The general case uses the - * top top 2 digits of the divisor (d) to estimate a quotient digit, - * so it breaks if there are fewer digits available. Thus, we need - * special cases for a divisor of length 1. A divisor of length - * 2 can have a *lot* of administrivia overhead removed removed, - * so it's probably worth special-casing that case, too. - */ - if (dlen == 1) - return lbnDiv1_16(q, BIGLITTLE(n-1,n), n, nlen, - BIGLITTLE(d[-1],d[0])); - -#if 0 - /* - * @@@ This is not yet written... The general loop will do, - * albeit less efficiently - */ - if (dlen == 2) { - /* - * divisor two digits long: - * use the 3/2 technique from Knuth, but we know - * it's exact. - */ - dh = BIGLITTLE(d[-1],d[0]); - dl = BIGLITTLE(d[-2],d[1]); - shift = 0; - if ((sh & ((BNWORD16)1 << 16-1-shift)) == 0) { - do { - shift++; - } while (dh & (BNWORD16)1<<16-1-shift) == 0); - dh = dh << shift | dl >> (16-shift); - dl <<= shift; - - - } - - - for (shift = 0; (dh & (BNWORD16)1 << 16-1-shift)) == 0; shift++) - ; - if (shift) { - } - dh = dh << shift | dl >> (16-shift); - shift = 0; - while (dh - } -#endif - - dh = BIGLITTLE(*(d-dlen),*(d+(dlen-1))); - assert(dh); - - /* Normalize the divisor */ - shift = 0; - r = dh; - i = 16/2; - do { - if (r >> i) - r >>= i; - else - shift += i; - } while ((i /= 2) != 0); - - nh = 0; - if (shift) { - lbnLshift_16(d, dlen, shift); - dh = BIGLITTLE(*(d-dlen),*(d+(dlen-1))); - nh = lbnLshift_16(n, nlen, shift); - } - - /* Assert that dh is now normalized */ - assert(dh >> (16-1)); - - /* Also get the second-most significant word of the divisor */ - dl = BIGLITTLE(*(d-(dlen-1)),*(d+(dlen-2))); - - /* - * Adjust pointers: n to point to least significant end of first - * first subtract, and q to one the most-significant end of the - * quotient array. - */ - BIGLITTLE(n -= qlen,n += qlen); - BIGLITTLE(q -= qlen,q += qlen); - - /* Fetch the most significant stored word of the dividend */ - nm = BIGLITTLE(*(n-dlen),*(n+(dlen-1))); - - /* - * Compute the first digit of the quotient, based on the - * first two words of the dividend (the most significant of which - * is the overflow word h). - */ - if (nh) { - assert(nh < dh); - r = lbnDiv21_16(&qhat, nh, nm, dh); - } else if (nm >= dh) { - qhat = nm/dh; - r = nm % dh; - } else { /* Quotient is zero */ - qhigh = 0; - goto divloop; - } - - /* Now get the third most significant word of the dividend */ - nl = BIGLITTLE(*(n-(dlen-1)),*(n+(dlen-2))); - - /* - * Correct qhat, the estimate of quotient digit. - * qhat can only be high, and at most two words high, - * so the loop can be unrolled and abbreviated. - */ -#ifdef mul16_ppmm - mul16_ppmm(nm, t16, qhat, dl); - if (nm > r || (nm == r && t16 > nl)) { - /* Decrement qhat and adjust comparison parameters */ - qhat--; - if ((r += dh) >= dh) { - nm -= (t16 < dl); - t16 -= dl; - if (nm > r || (nm == r && t16 > nl)) - qhat--; - } - } -#elif defined(BNWORD32) - t32 = (BNWORD32)qhat * dl; - if (t32 > ((BNWORD32)r << 16) + nl) { - /* Decrement qhat and adjust comparison parameters */ - qhat--; - if ((r += dh) > dh) { - t32 -= dl; - if (t32 > ((BNWORD32)r << 16) + nl) - qhat--; - } - } -#else /* Use lbnMulN1_16 */ - lbnMulN1_16(BIGLITTLE(t2+2,t2), &dl, 1, qhat); - if (t2high > r || (t2high == r && t2low > nl)) { - /* Decrement qhat and adjust comparison parameters */ - qhat--; - if ((r += dh) >= dh) { - t2high -= (t2low < dl); - t2low -= dl; - if (t2high > r || (t2high == r && t2low > nl)) - qhat--; - } - } -#endif - - /* Do the multiply and subtract */ - r = lbnMulSub1_16(n, d, dlen, qhat); - /* If there was a borrow, add back once. */ - if (r > nh) { /* Borrow? */ - (void)lbnAddN_16(n, d, dlen); - qhat--; - } - - /* Remember the first quotient digit. */ - qhigh = qhat; - - /* Now, the main division loop: */ -divloop: - while (qlen--) { - - /* Advance n */ - nh = BIGLITTLE(*(n-dlen),*(n+(dlen-1))); - BIGLITTLE(++n,--n); - nm = BIGLITTLE(*(n-dlen),*(n+(dlen-1))); - - if (nh == dh) { - qhat = ~(BNWORD16)0; - /* Optimized computation of r = (nh,nm) - qhat * dh */ - r = nh + nm; - if (r < nh) - goto subtract; - } else { - assert(nh < dh); - r = lbnDiv21_16(&qhat, nh, nm, dh); - } - - nl = BIGLITTLE(*(n-(dlen-1)),*(n+(dlen-2))); -#ifdef mul16_ppmm - mul16_ppmm(nm, t16, qhat, dl); - if (nm > r || (nm == r && t16 > nl)) { - /* Decrement qhat and adjust comparison parameters */ - qhat--; - if ((r += dh) >= dh) { - nm -= (t16 < dl); - t16 -= dl; - if (nm > r || (nm == r && t16 > nl)) - qhat--; - } - } -#elif defined(BNWORD32) - t32 = (BNWORD32)qhat * dl; - if (t32 > ((BNWORD32)r<<16) + nl) { - /* Decrement qhat and adjust comparison parameters */ - qhat--; - if ((r += dh) >= dh) { - t32 -= dl; - if (t32 > ((BNWORD32)r << 16) + nl) - qhat--; - } - } -#else /* Use lbnMulN1_16 */ - lbnMulN1_16(BIGLITTLE(t2+2,t2), &dl, 1, qhat); - if (t2high > r || (t2high == r && t2low > nl)) { - /* Decrement qhat and adjust comparison parameters */ - qhat--; - if ((r += dh) >= dh) { - t2high -= (t2low < dl); - t2low -= dl; - if (t2high > r || (t2high == r && t2low > nl)) - qhat--; - } - } -#endif - - /* - * As a point of interest, note that it is not worth checking - * for qhat of 0 or 1 and installing special-case code. These - * occur with probability 2^-16, so spending 1 cycle to check - * for them is only worth it if we save more than 2^15 cycles, - * and a multiply-and-subtract for numbers in the 1024-bit - * range just doesn't take that long. - */ -subtract: - /* - * n points to the least significant end of the substring - * of n to be subtracted from. qhat is either exact or - * one too large. If the subtract gets a borrow, it was - * one too large and the divisor is added back in. It's - * a dlen+1 word add which is guaranteed to produce a - * carry out, so it can be done very simply. - */ - r = lbnMulSub1_16(n, d, dlen, qhat); - if (r > nh) { /* Borrow? */ - (void)lbnAddN_16(n, d, dlen); - qhat--; - } - /* Store the quotient digit */ - BIGLITTLE(*q++,*--q) = qhat; - } - /* Tah dah! */ - - if (shift) { - lbnRshift_16(d, dlen, shift); - lbnRshift_16(n, dlen, shift); - } - - return qhigh; -} -#endif - -/* - * Find the negative multiplicative inverse of x (x must be odd!) modulo 2^16. - * - * This just performs Newton's iteration until it gets the - * inverse. The initial estimate is always correct to 3 bits, and - * sometimes 4. The number of valid bits doubles each iteration. - * (To prove it, assume x * y == 1 (mod 2^n), and introduce a variable - * for the error mod 2^2n. x * y == 1 + k*2^n (mod 2^2n) and follow - * the iteration through.) - */ -#ifndef lbnMontInv1_16 -BNWORD16 -lbnMontInv1_16(BNWORD16 const x) -{ - BNWORD16 y = x, z; - - assert(x & 1); - - while ((z = x*y) != 1) - y *= 2 - z; - return -y; -} -#endif /* !lbnMontInv1_16 */ - -#if defined(BNWORD32) && PRODUCT_SCAN -/* - * Test code for product-scanning Montgomery reduction. - * This seems to slow the C code down rather than speed it up. - * - * The first loop computes the Montgomery multipliers, storing them over - * the low half of the number n. - * - * The second half multiplies the upper half, adding in the modulus - * times the Montgomery multipliers. The results of this multiply - * are stored. - */ -void -lbnMontReduce_16(BNWORD16 *n, BNWORD16 const *mod, unsigned mlen, BNWORD16 inv) -{ - BNWORD32 x, y; - BNWORD16 const *pm; - BNWORD16 *pn; - BNWORD16 t; - unsigned carry; - unsigned i, j; - - /* Special case of zero */ - if (!mlen) - return; - - /* Pass 1 - compute Montgomery multipliers */ - /* First iteration can have certain simplifications. */ - t = BIGLITTLE(n[-1],n[0]); - x = t; - t *= inv; - BIGLITTLE(n[-1], n[0]) = t; - x += (BNWORD32)t * BIGLITTLE(mod[-1],mod[0]); /* Can't overflow */ - assert((BNWORD16)x == 0); - x = x >> 16; - - for (i = 1; i < mlen; i++) { - carry = 0; - pn = n; - pm = BIGLITTLE(mod-i-1,mod+i+1); - for (j = 0; j < i; j++) { - y = (BNWORD32)BIGLITTLE(*--pn * *pm++, *pn++ * *--pm); - x += y; - carry += (x < y); - } - assert(BIGLITTLE(pn == n-i, pn == n+i)); - y = t = BIGLITTLE(pn[-1], pn[0]); - x += y; - carry += (x < y); - BIGLITTLE(pn[-1], pn[0]) = t = inv * (BNWORD16)x; - assert(BIGLITTLE(pm == mod-1, pm == mod+1)); - y = (BNWORD32)t * BIGLITTLE(pm[0],pm[-1]); - x += y; - carry += (x < y); - assert((BNWORD16)x == 0); - x = x >> 16 | (BNWORD32)carry << 16; - } - - BIGLITTLE(n -= mlen, n += mlen); - - /* Pass 2 - compute upper words and add to n */ - for (i = 1; i < mlen; i++) { - carry = 0; - pm = BIGLITTLE(mod-i,mod+i); - pn = n; - for (j = i; j < mlen; j++) { - y = (BNWORD32)BIGLITTLE(*--pm * *pn++, *pm++ * *--pn); - x += y; - carry += (x < y); - } - assert(BIGLITTLE(pm == mod-mlen, pm == mod+mlen)); - assert(BIGLITTLE(pn == n+mlen-i, pn == n-mlen+i)); - y = t = BIGLITTLE(*(n-i),*(n+i-1)); - x += y; - carry += (x < y); - BIGLITTLE(*(n-i),*(n+i-1)) = (BNWORD16)x; - x = (x >> 16) | (BNWORD32)carry << 16; - } - - /* Last round of second half, simplified. */ - t = BIGLITTLE(*(n-mlen),*(n+mlen-1)); - x += t; - BIGLITTLE(*(n-mlen),*(n+mlen-1)) = (BNWORD16)x; - carry = (unsigned)(x >> 16); - - while (carry) - carry -= lbnSubN_16(n, mod, mlen); - while (lbnCmp_16(n, mod, mlen) >= 0) - (void)lbnSubN_16(n, mod, mlen); -} -#define lbnMontReduce_16 lbnMontReduce_16 -#endif - -/* - * Montgomery reduce n, modulo mod. This reduces modulo mod and divides by - * 2^(16*mlen). Returns the result in the *top* mlen words of the argument n. - * This is ready for another multiplication using lbnMul_16. - * - * Montgomery representation is a very useful way to encode numbers when - * you're doing lots of modular reduction. What you do is pick a multiplier - * R which is relatively prime to the modulus and very easy to divide by. - * Since the modulus is odd, R is closen as a power of 2, so the division - * is a shift. In fact, it's a shift of an integral number of words, - * so the shift can be implicit - just drop the low-order words. - * - * Now, choose R *larger* than the modulus m, 2^(16*mlen). Then convert - * all numbers a, b, etc. to Montgomery form M(a), M(b), etc using the - * relationship M(a) = a*R mod m, M(b) = b*R mod m, etc. Note that: - * - The Montgomery form of a number depends on the modulus m. - * A fixed modulus m is assumed throughout this discussion. - * - Since R is relaitvely prime to m, multiplication by R is invertible; - * no information about the numbers is lost, they're just scrambled. - * - Adding (and subtracting) numbers in this form works just as usual. - * M(a+b) = (a+b)*R mod m = (a*R + b*R) mod m = (M(a) + M(b)) mod m - * - Multiplying numbers in this form produces a*b*R*R. The problem - * is to divide out the excess factor of R, modulo m as well as to - * reduce to the given length mlen. It turns out that this can be - * done *faster* than a normal divide, which is where the speedup - * in Montgomery division comes from. - * - * Normal reduction chooses a most-significant quotient digit q and then - * subtracts q*m from the number to be reduced. Choosing q is tricky - * and involved (just look at lbnDiv_16 to see!) and is usually - * imperfect, requiring a check for correction after the subtraction. - * - * Montgomery reduction *adds* a multiple of m to the *low-order* part - * of the number to be reduced. This multiple is chosen to make the - * low-order part of the number come out to zero. This can be done - * with no trickery or error using a precomputed inverse of the modulus. - * In this code, the "part" is one word, but any width can be used. - * - * Repeating this step sufficiently often results in a value which - * is a multiple of R (a power of two, remember) but is still (since - * the additions were to the low-order part and thus did not increase - * the value of the number being reduced very much) still not much - * larger than m*R. Then implicitly divide by R and subtract off - * m until the result is in the correct range. - * - * Since the low-order part being cancelled is less than R, the - * multiple of m added must have a multiplier which is at most R-1. - * Assuming that the input is at most m*R-1, the final number is - * at most m*(2*R-1)-1 = 2*m*R - m - 1, so subtracting m once from - * the high-order part, equivalent to subtracting m*R from the - * while number, produces a result which is at most m*R - m - 1, - * which divided by R is at most m-1. - * - * To convert *to* Montgomery form, you need a regular remainder - * routine, although you can just compute R*R (mod m) and do the - * conversion using Montgomery multiplication. To convert *from* - * Montgomery form, just Montgomery reduce the number to - * remove the extra factor of R. - * - * TODO: Change to a full inverse and use Karatsuba's multiplication - * rather than this word-at-a-time. - */ -#ifndef lbnMontReduce_16 -void -lbnMontReduce_16(BNWORD16 *n, BNWORD16 const *mod, unsigned const mlen, - BNWORD16 inv) -{ - BNWORD16 t; - BNWORD16 c = 0; - unsigned len = mlen; - - /* inv must be the negative inverse of mod's least significant word */ - assert((BNWORD16)(inv * BIGLITTLE(mod[-1],mod[0])) == (BNWORD16)-1); - - assert(len); - - do { - t = lbnMulAdd1_16(n, mod, mlen, (BNWORD16)(inv * BIGLITTLE(n[-1],n[0]))); - c += lbnAdd1_16(BIGLITTLE(n-mlen,n+mlen), len, t); - BIGLITTLE(--n,++n); - } while (--len); - - /* - * All that adding can cause an overflow past the modulus size, - * but it's unusual, and never by much, so a subtraction loop - * is the right way to deal with it. - * This subtraction happens infrequently - I've only ever seen it - * invoked once per reduction, and then just under 22.5% of the time. - */ - while (c) - c -= lbnSubN_16(n, mod, mlen); - while (lbnCmp_16(n, mod, mlen) >= 0) - (void)lbnSubN_16(n, mod, mlen); -} -#endif /* !lbnMontReduce_16 */ - -/* - * A couple of helpers that you might want to implement atomically - * in asm sometime. - */ -#ifndef lbnMontMul_16 -/* - * Multiply "num1" by "num2", modulo "mod", all of length "len", and - * place the result in the high half of "prod". "inv" is the inverse - * of the least-significant word of the modulus, modulo 2^16. - * This uses numbers in Montgomery form. Reduce using "len" and "inv". - * - * This is implemented as a macro to win on compilers that don't do - * inlining, since it's so trivial. - */ -#define lbnMontMul_16(prod, n1, n2, mod, len, inv) \ - (lbnMulX_16(prod, n1, n2, len), lbnMontReduce_16(prod, mod, len, inv)) -#endif /* !lbnMontMul_16 */ - -#ifndef lbnMontSquare_16 -/* - * Square "num", modulo "mod", both of length "len", and place the result - * in the high half of "prod". "inv" is the inverse of the least-significant - * word of the modulus, modulo 2^16. - * This uses numbers in Montgomery form. Reduce using "len" and "inv". - * - * This is implemented as a macro to win on compilers that don't do - * inlining, since it's so trivial. - */ -#define lbnMontSquare_16(prod, n, mod, len, inv) \ - (lbnSquare_16(prod, n, len), lbnMontReduce_16(prod, mod, len, inv)) - -#endif /* !lbnMontSquare_16 */ - -/* - * Convert a number to Montgomery form - requires mlen + nlen words - * of memory in "n". - */ -void -lbnToMont_16(BNWORD16 *n, unsigned nlen, BNWORD16 *mod, unsigned mlen) -{ - /* Move n up "mlen" words */ - lbnCopy_16(BIGLITTLE(n-mlen,n+mlen), n, nlen); - lbnZero_16(n, mlen); - /* Do the division - dump the quotient in the high-order words */ - (void)lbnDiv_16(BIGLITTLE(n-mlen,n+mlen), n, mlen+nlen, mod, mlen); -} - -/* - * Convert from Montgomery form. Montgomery reduction is all that is - * needed. - */ -void -lbnFromMont_16(BNWORD16 *n, BNWORD16 *mod, unsigned len) -{ - /* Zero the high words of n */ - lbnZero_16(BIGLITTLE(n-len,n+len), len); - lbnMontReduce_16(n, mod, len, lbnMontInv1_16(BIGLITTLE(mod[-1],mod[0]))); - /* Move n down len words */ - lbnCopy_16(n, BIGLITTLE(n-len,n+len), len); -} - -/* - * The windowed exponentiation algorithm, precomputes a table of odd - * powers of n up to 2^k. It takes 2^(k-1)-1 multiplies to compute - * the table, and (e-1)/(k+1) multiplies (on average) to perform the - * exponentiation. To minimize the sum, k must vary with e. - * The optimal window sizes vary with the exponent length. Here are - * some selected values and the boundary cases. - * (An underscore _ has been inserted into some of the numbers to ensure - * that magic strings like 16 do not appear in this table. It should be - * ignored.) - * - * At e = 1 bits, k=1 (0.000000) is best. - * At e = 2 bits, k=1 (0.500000) is best. - * At e = 4 bits, k=1 (1.500000) is best. - * At e = 8 bits, k=2 (3.333333) < k=1 (3.500000) - * At e = 1_6 bits, k=2 (6.000000) is best. - * At e = 26 bits, k=3 (9.250000) < k=2 (9.333333) - * At e = 3_2 bits, k=3 (10.750000) is best. - * At e = 6_4 bits, k=3 (18.750000) is best. - * At e = 82 bits, k=4 (23.200000) < k=3 (23.250000) - * At e = 128 bits, k=4 (3_2.400000) is best. - * At e = 242 bits, k=5 (55.1_66667) < k=4 (55.200000) - * At e = 256 bits, k=5 (57.500000) is best. - * At e = 512 bits, k=5 (100.1_66667) is best. - * At e = 674 bits, k=6 (127.142857) < k=5 (127.1_66667) - * At e = 1024 bits, k=6 (177.142857) is best. - * At e = 1794 bits, k=7 (287.125000) < k=6 (287.142857) - * At e = 2048 bits, k=7 (318.875000) is best. - * At e = 4096 bits, k=7 (574.875000) is best. - * - * The numbers in parentheses are the expected number of multiplications - * needed to do the computation. The normal russian-peasant modular - * exponentiation technique always uses (e-1)/2. For exponents as - * small as 192 bits (below the range of current factoring algorithms), - * half of the multiplies are eliminated, 45.2 as opposed to the naive - * 95.5. Counting the 191 squarings as 3/4 a multiply each (squaring - * proper is just over half of multiplying, but the Montgomery - * reduction in each case is also a multiply), that's 143.25 - * multiplies, for totals of 188.45 vs. 238.75 - a 21% savings. - * For larger exponents (like 512 bits), it's 483.92 vs. 639.25, a - * 24.3% savings. It asymptotically approaches 25%. - * - * Given that exponents for which k>7 are useful are uncommon, - * a fixed size table for k <= 7 is used for simplicity. - * k = 8 is uzeful at 4610 bits, k = 9 at 11522 bits. - * - * The basic number of squarings needed is e-1, although a k-bit - * window (for k > 1) can save, on average, k-2 of those, too. - * That savings currently isn't counted here. It would drive the - * crossover points slightly lower. - * (Actually, this win is also reduced in the DoubleExpMod case, - * meaning we'd have to split the tables. Except for that, the - * multiplies by powers of the two bases are independent, so - * the same logic applies to each as the single case.) - * - * Table entry i is the largest number of bits in an exponent to - * process with a window size of i+1. So the window never goes above 7 - * bits, requiring 2^(7-1) = 0x40 precomputed multiples. - */ -#define BNEXPMOD_MAX_WINDOW 7 -static unsigned const bnExpModThreshTable[BNEXPMOD_MAX_WINDOW] = { - 7, 25, 81, 241, 673, 1793, (unsigned)-1 -}; - -/* - * Perform modular exponentiation, as fast as possible! This uses - * Montgomery reduction, optimized squaring, and windowed exponentiation. - * The modulus "mod" MUST be odd! - * - * This returns 0 on success, -1 on out of memory. - * - * The window algorithm: - * The idea is to keep a running product of b1 = n^(high-order bits of exp), - * and then keep appending exponent bits to it. The following patterns - * apply to a 3-bit window (k = 3): - * To append 0: square - * To append 1: square, multiply by n^1 - * To append 10: square, multiply by n^1, square - * To append 11: square, square, multiply by n^3 - * To append 100: square, multiply by n^1, square, square - * To append 101: square, square, square, multiply by n^5 - * To append 110: square, square, multiply by n^3, square - * To append 111: square, square, square, multiply by n^7 - * - * Since each pattern involves only one multiply, the longer the pattern - * the better, except that a 0 (no multiplies) can be appended directly. - * We precompute a table of odd powers of n, up to 2^k, and can then - * multiply k bits of exponent at a time. Actually, assuming random - * exponents, there is on average one zero bit between needs to - * multiply (1/2 of the time there's none, 1/4 of the time there's 1, - * 1/8 of the time, there's 2, 1/16 of the time, there's 3, etc.), so - * you have to do one multiply per k+1 bits of exponent. - * - * The loop walks down the exponent, squaring the result buffer as - * it goes. There is a wbits+1 bit lookahead buffer, buf, that is - * filled with the upcoming exponent bits. (What is read after the - * end of the exponent is unimportant, but it is filled with zero here.) - * When the most-significant bit of this buffer becomes set, i.e. - * (buf & tblmask) != 0, we have to decide what pattern to multiply - * by, and when to do it. We decide, remember to do it in future - * after a suitable number of squarings have passed (e.g. a pattern - * of "100" in the buffer requires that we multiply by n^1 immediately; - * a pattern of "110" calls for multiplying by n^3 after one more - * squaring), clear the buffer, and continue. - * - * When we start, there is one more optimization: the result buffer - * is implcitly one, so squaring it or multiplying by it can be - * optimized away. Further, if we start with a pattern like "100" - * in the lookahead window, rather than placing n into the buffer - * and then starting to square it, we have already computed n^2 - * to compute the odd-powers table, so we can place that into - * the buffer and save a squaring. - * - * This means that if you have a k-bit window, to compute n^z, - * where z is the high k bits of the exponent, 1/2 of the time - * it requires no squarings. 1/4 of the time, it requires 1 - * squaring, ... 1/2^(k-1) of the time, it reqires k-2 squarings. - * And the remaining 1/2^(k-1) of the time, the top k bits are a - * 1 followed by k-1 0 bits, so it again only requires k-2 - * squarings, not k-1. The average of these is 1. Add that - * to the one squaring we have to do to compute the table, - * and you'll see that a k-bit window saves k-2 squarings - * as well as reducing the multiplies. (It actually doesn't - * hurt in the case k = 1, either.) - * - * n must have mlen words allocated. Although fewer may be in use - * when n is passed in, all are in use on exit. - */ -int -lbnExpMod_16(BNWORD16 *result, BNWORD16 const *n, unsigned nlen, - BNWORD16 const *e, unsigned elen, BNWORD16 *mod, unsigned mlen) -{ - BNWORD16 *table[1 << (BNEXPMOD_MAX_WINDOW-1)]; - /* Table of odd powers of n */ - unsigned ebits; /* Exponent bits */ - unsigned wbits; /* Window size */ - unsigned tblmask; /* Mask of exponentiation window */ - BNWORD16 bitpos; /* Mask of current look-ahead bit */ - unsigned buf; /* Buffer of exponent bits */ - unsigned multpos; /* Where to do pending multiply */ - BNWORD16 const *mult; /* What to multiply by */ - unsigned i; /* Loop counter */ - int isone; /* Flag: accum. is implicitly one */ - BNWORD16 *a, *b; /* Working buffers/accumulators */ - BNWORD16 *t; /* Pointer into the working buffers */ - BNWORD16 inv; /* mod^-1 modulo 2^16 */ - - assert(mlen); - assert(nlen <= mlen); - - /* First, a couple of trivial cases. */ - elen = lbnNorm_16(e, elen); - if (!elen) { - /* x ^ 0 == 1 */ - lbnZero_16(result, mlen); - BIGLITTLE(result[-1],result[0]) = 1; - return 0; - } - ebits = lbnBits_16(e, elen); - if (ebits == 1) { - /* x ^ 1 == x */ - if (n != result) - lbnCopy_16(result, n, nlen); - if (mlen > nlen) - lbnZero_16(BIGLITTLE(result-nlen,result+nlen), - mlen-nlen); - return 0; - } - - /* Okay, now move the exponent pointer to the most-significant word */ - e = BIGLITTLE(e-elen, e+elen-1); - - /* Look up appropriate k-1 for the exponent - tblmask = 1<<(k-1) */ - wbits = 0; - while (ebits > bnExpModThreshTable[wbits]) - wbits++; - - /* Allocate working storage: two product buffers and the tables. */ - LBNALLOC(a, 2*mlen); - if (!a) - return -1; - LBNALLOC(b, 2*mlen); - if (!b) { - LBNFREE(a, 2*mlen); - return -1; - } - - /* Convert to the appropriate table size: tblmask = 1<<(k-1) */ - tblmask = 1u << wbits; - - /* We have the result buffer available, so use it. */ - table[0] = result; - - /* - * Okay, we now have a minimal-sized table - expand it. - * This is allowed to fail! If so, scale back the table size - * and proceed. - */ - for (i = 1; i < tblmask; i++) { - LBNALLOC(t, mlen); - if (!t) /* Out of memory! Quit the loop. */ - break; - table[i] = t; - } - - /* If we stopped, with i < tblmask, shrink the tables appropriately */ - while (tblmask > i) { - wbits--; - tblmask >>= 1; - } - /* Free up our overallocations */ - while (--i > tblmask) - LBNFREE(table[i], mlen); - - /* Okay, fill in the table */ - - /* Compute the necessary modular inverse */ - inv = lbnMontInv1_16(mod[BIGLITTLE(-1,0)]); /* LSW of modulus */ - - /* Convert n to Montgomery form */ - - /* Move n up "mlen" words into a */ - t = BIGLITTLE(a-mlen, a+mlen); - lbnCopy_16(t, n, nlen); - lbnZero_16(a, mlen); - /* Do the division - lose the quotient into the high-order words */ - (void)lbnDiv_16(t, a, mlen+nlen, mod, mlen); - /* Copy into first table entry */ - lbnCopy_16(table[0], a, mlen); - - /* Square a into b */ - lbnMontSquare_16(b, a, mod, mlen, inv); - - /* Use high half of b to initialize the table */ - t = BIGLITTLE(b-mlen, b+mlen); - for (i = 1; i < tblmask; i++) { - lbnMontMul_16(a, t, table[i-1], mod, mlen, inv); - lbnCopy_16(table[i], BIGLITTLE(a-mlen, a+mlen), mlen); - } - - /* We might use b = n^2 later... */ - - /* Initialze the fetch pointer */ - bitpos = (BNWORD16)1 << ((ebits-1) & (16-1)); /* Initialize mask */ - - /* This should point to the msbit of e */ - assert((*e & bitpos) != 0); - - /* - * Pre-load the window. Becuase the window size is - * never larger than the exponent size, there is no need to - * detect running off the end of e in here. - * - * The read-ahead is controlled by elen and the bitpos mask. - * Note that this is *ahead* of ebits, which tracks the - * most significant end of the window. The purpose of this - * initialization is to get the two wbits+1 bits apart, - * like they should be. - * - * Note that bitpos and e1len together keep track of the - * lookahead read pointer in the exponent that is used here. - */ - buf = 0; - for (i = 0; i <= wbits; i++) { - buf = (buf << 1) | ((*e & bitpos) != 0); - bitpos >>= 1; - if (!bitpos) { - BIGLITTLE(e++,e--); - bitpos = (BNWORD16)1 << (16-1); - elen--; - } - } - assert(buf & tblmask); - - /* - * Set the pending multiply positions to a location that will - * never be encountered, thus ensuring that nothing will happen - * until the need for a multiply appears and one is scheduled. - */ - multpos = ebits; /* A NULL value */ - mult = 0; /* Force a crash if we use these */ - - /* - * Okay, now begins the real work. The first step is - * slightly magic, so it's done outside the main loop, - * but it's very similar to what's inside. - */ - ebits--; /* Start processing the first bit... */ - isone = 1; - - /* - * This is just like the multiply in the loop, except that - * - We know the msbit of buf is set, and - * - We have the extra value n^2 floating around. - * So, do the usual computation, and if the result is that - * the buffer should be multiplied by n^1 immediately - * (which we'd normally then square), we multiply it - * (which reduces to a copy, which reduces to setting a flag) - * by n^2 and skip the squaring. Thus, we do the - * multiply and the squaring in one step. - */ - assert(buf & tblmask); - multpos = ebits - wbits; - while ((buf & 1) == 0) { - buf >>= 1; - multpos++; - } - /* Intermediates can wrap, but final must NOT */ - assert(multpos <= ebits); - mult = table[buf>>1]; - buf = 0; - - /* Special case: use already-computed value sitting in buffer */ - if (multpos == ebits) - isone = 0; - - /* - * At this point, the buffer (which is the high half of b) holds - * either 1 (implicitly, as the "isone" flag is set), or n^2. - */ - - /* - * The main loop. The procedure is: - * - Advance the window - * - If the most-significant bit of the window is set, - * schedule a multiply for the appropriate time in the - * future (may be immediately) - * - Perform any pending multiples - * - Check for termination - * - Square the buffer - * - * At any given time, the acumulated product is held in - * the high half of b. - */ - for (;;) { - ebits--; - - /* Advance the window */ - assert(buf < tblmask); - buf <<= 1; - /* - * This reads ahead of the current exponent position - * (controlled by ebits), so we have to be able to read - * past the lsb of the exponents without error. - */ - if (elen) { - buf |= ((*e & bitpos) != 0); - bitpos >>= 1; - if (!bitpos) { - BIGLITTLE(e++,e--); - bitpos = (BNWORD16)1 << (16-1); - elen--; - } - } - - /* Examine the window for pending multiplies */ - if (buf & tblmask) { - multpos = ebits - wbits; - while ((buf & 1) == 0) { - buf >>= 1; - multpos++; - } - /* Intermediates can wrap, but final must NOT */ - assert(multpos <= ebits); - mult = table[buf>>1]; - buf = 0; - } - - /* If we have a pending multiply, do it */ - if (ebits == multpos) { - /* Multiply by the table entry remembered previously */ - t = BIGLITTLE(b-mlen, b+mlen); - if (isone) { - /* Multiply by 1 is a trivial case */ - lbnCopy_16(t, mult, mlen); - isone = 0; - } else { - lbnMontMul_16(a, t, mult, mod, mlen, inv); - /* Swap a and b */ - t = a; a = b; b = t; - } - } - - /* Are we done? */ - if (!ebits) - break; - - /* Square the input */ - if (!isone) { - t = BIGLITTLE(b-mlen, b+mlen); - lbnMontSquare_16(a, t, mod, mlen, inv); - /* Swap a and b */ - t = a; a = b; b = t; - } - } /* for (;;) */ - - assert(!isone); - assert(!buf); - - /* DONE! */ - - /* Convert result out of Montgomery form */ - t = BIGLITTLE(b-mlen, b+mlen); - lbnCopy_16(b, t, mlen); - lbnZero_16(t, mlen); - lbnMontReduce_16(b, mod, mlen, inv); - lbnCopy_16(result, t, mlen); - /* - * Clean up - free intermediate storage. - * Do NOT free table[0], which is the result - * buffer. - */ - while (--tblmask) - LBNFREE(table[tblmask], mlen); - LBNFREE(b, 2*mlen); - LBNFREE(a, 2*mlen); - - return 0; /* Success */ -} - -/* - * Compute and return n1^e1 * n2^e2 mod "mod". - * result may be either input buffer, or something separate. - * It must be "mlen" words long. - * - * There is a current position in the exponents, which is kept in e1bits. - * (The exponents are swapped if necessary so e1 is the longer of the two.) - * At any given time, the value in the accumulator is - * n1^(e1>>e1bits) * n2^(e2>>e1bits) mod "mod". - * As e1bits is counted down, this is updated, by squaring it and doing - * any necessary multiplies. - * To decide on the necessary multiplies, two windows, each w1bits+1 bits - * wide, are maintained in buf1 and buf2, which read *ahead* of the - * e1bits position (with appropriate handling of the case when e1bits - * drops below w1bits+1). When the most-significant bit of either window - * becomes set, indicating that something needs to be multiplied by - * the accumulator or it will get out of sync, the window is examined - * to see which power of n1 or n2 to multiply by, and when (possibly - * later, if the power is greater than 1) the multiply should take - * place. Then the multiply and its location are remembered and the - * window is cleared. - * - * If we had every power of n1 in the table, the multiply would always - * be w1bits steps in the future. But we only keep the odd powers, - * so instead of waiting w1bits squarings and then multiplying - * by n1^k, we wait w1bits-k squarings and multiply by n1. - * - * Actually, w2bits can be less than w1bits, but the window is the same - * size, to make it easier to keep track of where we're reading. The - * appropriate number of low-order bits of the window are just ignored. - */ -int -lbnDoubleExpMod_16(BNWORD16 *result, - BNWORD16 const *n1, unsigned n1len, - BNWORD16 const *e1, unsigned e1len, - BNWORD16 const *n2, unsigned n2len, - BNWORD16 const *e2, unsigned e2len, - BNWORD16 *mod, unsigned mlen) -{ - BNWORD16 *table1[1 << (BNEXPMOD_MAX_WINDOW-1)]; - /* Table of odd powers of n1 */ - BNWORD16 *table2[1 << (BNEXPMOD_MAX_WINDOW-1)]; - /* Table of odd powers of n2 */ - unsigned e1bits, e2bits; /* Exponent bits */ - unsigned w1bits, w2bits; /* Window sizes */ - unsigned tblmask; /* Mask of exponentiation window */ - BNWORD16 bitpos; /* Mask of current look-ahead bit */ - unsigned buf1, buf2; /* Buffer of exponent bits */ - unsigned mult1pos, mult2pos; /* Where to do pending multiply */ - BNWORD16 const *mult1, *mult2; /* What to multiply by */ - unsigned i; /* Loop counter */ - int isone; /* Flag: accum. is implicitly one */ - BNWORD16 *a, *b; /* Working buffers/accumulators */ - const BNWORD16 *ct; /* Temp pointer */ - BNWORD16 *t; /* Pointer into the working buffers */ - BNWORD16 inv; /* mod^-1 modulo 2^16 */ - - assert(mlen); - assert(n1len <= mlen); - assert(n2len <= mlen); - - /* First, a couple of trivial cases. */ - e1len = lbnNorm_16(e1, e1len); - e2len = lbnNorm_16(e2, e2len); - - /* Ensure that the first exponent is the longer */ - e1bits = lbnBits_16(e1, e1len); - e2bits = lbnBits_16(e2, e2len); - if (e1bits < e2bits) { - i = e1len; e1len = e2len; e2len = i; - i = e1bits; e1bits = e2bits; e2bits = i; - ct = (const BNWORD16 *)n1; n1 = n2; n2 = ct; - ct = (const BNWORD16 *)e1; e1 = e2; e2 = ct; - } - assert(e1bits >= e2bits); - - /* Handle a trivial case */ - if (!e2len) - return lbnExpMod_16(result, n1, n1len, e1, e1len, mod, mlen); - assert(e2bits); - - /* The code below breaks if the exponents aren't at least 2 bits */ - if (e1bits == 1) { - assert(e2bits == 1); - - LBNALLOC(a, n1len+n2len); - if (!a) - return -1; - - lbnMul_16(a, n1, n1len, n2, n2len); - /* Do a direct modular reduction */ - if (n1len + n2len >= mlen) - (void)lbnDiv_16(a+mlen, a, n1len+n2len, mod, mlen); - lbnCopy_16(result, a, mlen); - LBNFREE(a, n1len+n2len); - return 0; - } - - /* Okay, now move the exponent pointers to the most-significant word */ - e1 = BIGLITTLE(e1-e1len, e1+e1len-1); - e2 = BIGLITTLE(e2-e2len, e2+e2len-1); - - /* Look up appropriate k-1 for the exponent - tblmask = 1<<(k-1) */ - w1bits = 0; - while (e1bits > bnExpModThreshTable[w1bits]) - w1bits++; - w2bits = 0; - while (e2bits > bnExpModThreshTable[w2bits]) - w2bits++; - - assert(w1bits >= w2bits); - - /* Allocate working storage: two product buffers and the tables. */ - LBNALLOC(a, 2*mlen); - if (!a) - return -1; - LBNALLOC(b, 2*mlen); - if (!b) { - LBNFREE(a, 2*mlen); - return -1; - } - - /* Convert to the appropriate table size: tblmask = 1<<(k-1) */ - tblmask = 1u << w1bits; - /* Use buf2 for its size, temporarily */ - buf2 = 1u << w2bits; - - LBNALLOC(t, mlen); - if (!t) { - LBNFREE(b, 2*mlen); - LBNFREE(a, 2*mlen); - return -1; - } - table1[0] = t; - table2[0] = result; - - /* - * Okay, we now have some minimal-sized tables - expand them. - * This is allowed to fail! If so, scale back the table sizes - * and proceed. We allocate both tables at the same time - * so if it fails partway through, they'll both be a reasonable - * size rather than one huge and one tiny. - * When i passes buf2 (the number of entries in the e2 window, - * which may be less than the number of entries in the e1 window), - * stop allocating e2 space. - */ - for (i = 1; i < tblmask; i++) { - LBNALLOC(t, mlen); - if (!t) /* Out of memory! Quit the loop. */ - break; - table1[i] = t; - if (i < buf2) { - LBNALLOC(t, mlen); - if (!t) { - LBNFREE(table1[i], mlen); - break; - } - table2[i] = t; - } - } - - /* If we stopped, with i < tblmask, shrink the tables appropriately */ - while (tblmask > i) { - w1bits--; - tblmask >>= 1; - } - /* Free up our overallocations */ - while (--i > tblmask) { - if (i < buf2) - LBNFREE(table2[i], mlen); - LBNFREE(table1[i], mlen); - } - /* And shrink the second window too, if needed */ - if (w2bits > w1bits) { - w2bits = w1bits; - buf2 = tblmask; - } - - /* - * From now on, use the w2bits variable for the difference - * between w1bits and w2bits. - */ - w2bits = w1bits-w2bits; - - /* Okay, fill in the tables */ - - /* Compute the necessary modular inverse */ - inv = lbnMontInv1_16(mod[BIGLITTLE(-1,0)]); /* LSW of modulus */ - - /* Convert n1 to Montgomery form */ - - /* Move n1 up "mlen" words into a */ - t = BIGLITTLE(a-mlen, a+mlen); - lbnCopy_16(t, n1, n1len); - lbnZero_16(a, mlen); - /* Do the division - lose the quotient into the high-order words */ - (void)lbnDiv_16(t, a, mlen+n1len, mod, mlen); - /* Copy into first table entry */ - lbnCopy_16(table1[0], a, mlen); - - /* Square a into b */ - lbnMontSquare_16(b, a, mod, mlen, inv); - - /* Use high half of b to initialize the first table */ - t = BIGLITTLE(b-mlen, b+mlen); - for (i = 1; i < tblmask; i++) { - lbnMontMul_16(a, t, table1[i-1], mod, mlen, inv); - lbnCopy_16(table1[i], BIGLITTLE(a-mlen, a+mlen), mlen); - } - - /* Convert n2 to Montgomery form */ - - t = BIGLITTLE(a-mlen, a+mlen); - /* Move n2 up "mlen" words into a */ - lbnCopy_16(t, n2, n2len); - lbnZero_16(a, mlen); - /* Do the division - lose the quotient into the high-order words */ - (void)lbnDiv_16(t, a, mlen+n2len, mod, mlen); - /* Copy into first table entry */ - lbnCopy_16(table2[0], a, mlen); - - /* Square it into a */ - lbnMontSquare_16(a, table2[0], mod, mlen, inv); - /* Copy to b, low half */ - lbnCopy_16(b, t, mlen); - - /* Use b to initialize the second table */ - for (i = 1; i < buf2; i++) { - lbnMontMul_16(a, b, table2[i-1], mod, mlen, inv); - lbnCopy_16(table2[i], t, mlen); - } - - /* - * Okay, a recap: at this point, the low part of b holds - * n2^2, the high part holds n1^2, and the tables are - * initialized with the odd powers of n1 and n2 from 1 - * through 2*tblmask-1 and 2*buf2-1. - * - * We might use those squares in b later, or we might not. - */ - - /* Initialze the fetch pointer */ - bitpos = (BNWORD16)1 << ((e1bits-1) & (16-1)); /* Initialize mask */ - - /* This should point to the msbit of e1 */ - assert((*e1 & bitpos) != 0); - - /* - * Pre-load the windows. Becuase the window size is - * never larger than the exponent size, there is no need to - * detect running off the end of e1 in here. - * - * The read-ahead is controlled by e1len and the bitpos mask. - * Note that this is *ahead* of e1bits, which tracks the - * most significant end of the window. The purpose of this - * initialization is to get the two w1bits+1 bits apart, - * like they should be. - * - * Note that bitpos and e1len together keep track of the - * lookahead read pointer in the exponent that is used here. - * e2len is not decremented, it is only ever compared with - * e1len as *that* is decremented. - */ - buf1 = buf2 = 0; - for (i = 0; i <= w1bits; i++) { - buf1 = (buf1 << 1) | ((*e1 & bitpos) != 0); - if (e1len <= e2len) - buf2 = (buf2 << 1) | ((*e2 & bitpos) != 0); - bitpos >>= 1; - if (!bitpos) { - BIGLITTLE(e1++,e1--); - if (e1len <= e2len) - BIGLITTLE(e2++,e2--); - bitpos = (BNWORD16)1 << (16-1); - e1len--; - } - } - assert(buf1 & tblmask); - - /* - * Set the pending multiply positions to a location that will - * never be encountered, thus ensuring that nothing will happen - * until the need for a multiply appears and one is scheduled. - */ - mult1pos = mult2pos = e1bits; /* A NULL value */ - mult1 = mult2 = 0; /* Force a crash if we use these */ - - /* - * Okay, now begins the real work. The first step is - * slightly magic, so it's done outside the main loop, - * but it's very similar to what's inside. - */ - isone = 1; /* Buffer is implicitly 1, so replace * by copy */ - e1bits--; /* Start processing the first bit... */ - - /* - * This is just like the multiply in the loop, except that - * - We know the msbit of buf1 is set, and - * - We have the extra value n1^2 floating around. - * So, do the usual computation, and if the result is that - * the buffer should be multiplied by n1^1 immediately - * (which we'd normally then square), we multiply it - * (which reduces to a copy, which reduces to setting a flag) - * by n1^2 and skip the squaring. Thus, we do the - * multiply and the squaring in one step. - */ - assert(buf1 & tblmask); - mult1pos = e1bits - w1bits; - while ((buf1 & 1) == 0) { - buf1 >>= 1; - mult1pos++; - } - /* Intermediates can wrap, but final must NOT */ - assert(mult1pos <= e1bits); - mult1 = table1[buf1>>1]; - buf1 = 0; - - /* Special case: use already-computed value sitting in buffer */ - if (mult1pos == e1bits) - isone = 0; - - /* - * The first multiply by a power of n2. Similar, but - * we might not even want to schedule a multiply if e2 is - * shorter than e1, and the window might be shorter so - * we have to leave the low w2bits bits alone. - */ - if (buf2 & tblmask) { - /* Remember low-order bits for later */ - i = buf2 & ((1u << w2bits) - 1); - buf2 >>= w2bits; - mult2pos = e1bits - w1bits + w2bits; - while ((buf2 & 1) == 0) { - buf2 >>= 1; - mult2pos++; - } - assert(mult2pos <= e1bits); - mult2 = table2[buf2>>1]; - buf2 = i; - - if (mult2pos == e1bits) { - t = BIGLITTLE(b-mlen, b+mlen); - if (isone) { - lbnCopy_16(t, b, mlen); /* Copy low to high */ - isone = 0; - } else { - lbnMontMul_16(a, t, b, mod, mlen, inv); - t = a; a = b; b = t; - } - } - } - - /* - * At this point, the buffer (which is the high half of b) - * holds either 1 (implicitly, as the "isone" flag is set), - * n1^2, n2^2 or n1^2 * n2^2. - */ - - /* - * The main loop. The procedure is: - * - Advance the windows - * - If the most-significant bit of a window is set, - * schedule a multiply for the appropriate time in the - * future (may be immediately) - * - Perform any pending multiples - * - Check for termination - * - Square the buffers - * - * At any given time, the acumulated product is held in - * the high half of b. - */ - for (;;) { - e1bits--; - - /* Advance the windows */ - assert(buf1 < tblmask); - buf1 <<= 1; - assert(buf2 < tblmask); - buf2 <<= 1; - /* - * This reads ahead of the current exponent position - * (controlled by e1bits), so we have to be able to read - * past the lsb of the exponents without error. - */ - if (e1len) { - buf1 |= ((*e1 & bitpos) != 0); - if (e1len <= e2len) - buf2 |= ((*e2 & bitpos) != 0); - bitpos >>= 1; - if (!bitpos) { - BIGLITTLE(e1++,e1--); - if (e1len <= e2len) - BIGLITTLE(e2++,e2--); - bitpos = (BNWORD16)1 << (16-1); - e1len--; - } - } - - /* Examine the first window for pending multiplies */ - if (buf1 & tblmask) { - mult1pos = e1bits - w1bits; - while ((buf1 & 1) == 0) { - buf1 >>= 1; - mult1pos++; - } - /* Intermediates can wrap, but final must NOT */ - assert(mult1pos <= e1bits); - mult1 = table1[buf1>>1]; - buf1 = 0; - } - - /* - * Examine the second window for pending multiplies. - * Window 2 can be smaller than window 1, but we - * keep the same number of bits in buf2, so we need - * to ignore any low-order bits in the buffer when - * computing what to multiply by, and recompute them - * later. - */ - if (buf2 & tblmask) { - /* Remember low-order bits for later */ - i = buf2 & ((1u << w2bits) - 1); - buf2 >>= w2bits; - mult2pos = e1bits - w1bits + w2bits; - while ((buf2 & 1) == 0) { - buf2 >>= 1; - mult2pos++; - } - assert(mult2pos <= e1bits); - mult2 = table2[buf2>>1]; - buf2 = i; - } - - - /* If we have a pending multiply for e1, do it */ - if (e1bits == mult1pos) { - /* Multiply by the table entry remembered previously */ - t = BIGLITTLE(b-mlen, b+mlen); - if (isone) { - /* Multiply by 1 is a trivial case */ - lbnCopy_16(t, mult1, mlen); - isone = 0; - } else { - lbnMontMul_16(a, t, mult1, mod, mlen, inv); - /* Swap a and b */ - t = a; a = b; b = t; - } - } - - /* If we have a pending multiply for e2, do it */ - if (e1bits == mult2pos) { - /* Multiply by the table entry remembered previously */ - t = BIGLITTLE(b-mlen, b+mlen); - if (isone) { - /* Multiply by 1 is a trivial case */ - lbnCopy_16(t, mult2, mlen); - isone = 0; - } else { - lbnMontMul_16(a, t, mult2, mod, mlen, inv); - /* Swap a and b */ - t = a; a = b; b = t; - } - } - - /* Are we done? */ - if (!e1bits) - break; - - /* Square the buffer */ - if (!isone) { - t = BIGLITTLE(b-mlen, b+mlen); - lbnMontSquare_16(a, t, mod, mlen, inv); - /* Swap a and b */ - t = a; a = b; b = t; - } - } /* for (;;) */ - - assert(!isone); - assert(!buf1); - assert(!buf2); - - /* DONE! */ - - /* Convert result out of Montgomery form */ - t = BIGLITTLE(b-mlen, b+mlen); - lbnCopy_16(b, t, mlen); - lbnZero_16(t, mlen); - lbnMontReduce_16(b, mod, mlen, inv); - lbnCopy_16(result, t, mlen); - - /* Clean up - free intermediate storage */ - buf2 = tblmask >> w2bits; - while (--tblmask) { - if (tblmask < buf2) - LBNFREE(table2[tblmask], mlen); - LBNFREE(table1[tblmask], mlen); - } - t = table1[0]; - LBNFREE(t, mlen); - LBNFREE(b, 2*mlen); - LBNFREE(a, 2*mlen); - - return 0; /* Success */ -} - -/* - * 2^exp (mod mod). This is an optimized version for use in Fermat - * tests. The input value of n is ignored; it is returned with - * "mlen" words valid. - */ -int -lbnTwoExpMod_16(BNWORD16 *n, BNWORD16 const *exp, unsigned elen, - BNWORD16 *mod, unsigned mlen) -{ - unsigned e; /* Copy of high words of the exponent */ - unsigned bits; /* Assorted counter of bits */ - BNWORD16 const *bitptr; - BNWORD16 bitword, bitpos; - BNWORD16 *a, *b, *a1; - BNWORD16 inv; - - assert(mlen); - - bitptr = BIGLITTLE(exp-elen, exp+elen-1); - bitword = *bitptr; - assert(bitword); - - /* Clear n for future use. */ - lbnZero_16(n, mlen); - - bits = lbnBits_16(exp, elen); - - /* First, a couple of trivial cases. */ - if (bits <= 1) { - /* 2 ^ 0 == 1, 2 ^ 1 == 2 */ - BIGLITTLE(n[-1],n[0]) = (BNWORD16)1<<elen; - return 0; - } - - /* Set bitpos to the most significant bit */ - bitpos = (BNWORD16)1 << ((bits-1) & (16-1)); - - /* Now, count the bits in the modulus. */ - bits = lbnBits_16(mod, mlen); - assert(bits > 1); /* a 1-bit modulus is just stupid... */ - - /* - * We start with 1<<e, where "e" is as many high bits of the - * exponent as we can manage without going over the modulus. - * This first loop finds "e". - */ - e = 1; - while (elen) { - /* Consume the first bit */ - bitpos >>= 1; - if (!bitpos) { - if (!--elen) - break; - bitword = BIGLITTLE(*++bitptr,*--bitptr); - bitpos = (BNWORD16)1<<(16-1); - } - e = (e << 1) | ((bitpos & bitword) != 0); - if (e >= bits) { /* Overflow! Back out. */ - e >>= 1; - break; - } - } - /* - * The bit in "bitpos" being examined by the bit buffer has NOT - * been consumed yet. This may be past the end of the exponent, - * in which case elen == 1. - */ - - /* Okay, now, set bit "e" in n. n is already zero. */ - inv = (BNWORD16)1 << (e & (16-1)); - e /= 16; - BIGLITTLE(n[-e-1],n[e]) = inv; - /* - * The effective length of n in words is now "e+1". - * This is used a little bit later. - */ - - if (!elen) - return 0; /* That was easy! */ - - /* - * We have now processed the first few bits. The next step - * is to convert this to Montgomery form for further squaring. - */ - - /* Allocate working storage: two product buffers */ - LBNALLOC(a, 2*mlen); - if (!a) - return -1; - LBNALLOC(b, 2*mlen); - if (!b) { - LBNFREE(a, 2*mlen); - return -1; - } - - /* Convert n to Montgomery form */ - inv = BIGLITTLE(mod[-1],mod[0]); /* LSW of modulus */ - assert(inv & 1); /* Modulus must be odd */ - inv = lbnMontInv1_16(inv); - /* Move n (length e+1, remember?) up "mlen" words into b */ - /* Note that we lie about a1 for a bit - it's pointing to b */ - a1 = BIGLITTLE(b-mlen,b+mlen); - lbnCopy_16(a1, n, e+1); - lbnZero_16(b, mlen); - /* Do the division - dump the quotient into the high-order words */ - (void)lbnDiv_16(a1, b, mlen+e+1, mod, mlen); - /* - * Now do the first squaring and modular reduction to put - * the number up in a1 where it belongs. - */ - lbnMontSquare_16(a, b, mod, mlen, inv); - /* Fix up a1 to point to where it should go. */ - a1 = BIGLITTLE(a-mlen,a+mlen); - - /* - * Okay, now, a1 holds the number being accumulated, and - * b is a scratch register. Start working: - */ - for (;;) { - /* - * Is the bit set? If so, double a1 as well. - * A modular doubling like this is very cheap. - */ - if (bitpos & bitword) { - /* - * Double the number. If there was a carry out OR - * the result is greater than the modulus, subract - * the modulus. - */ - if (lbnDouble_16(a1, mlen) || - lbnCmp_16(a1, mod, mlen) > 0) - (void)lbnSubN_16(a1, mod, mlen); - } - - /* Advance to the next exponent bit */ - bitpos >>= 1; - if (!bitpos) { - if (!--elen) - break; /* Done! */ - bitword = BIGLITTLE(*++bitptr,*--bitptr); - bitpos = (BNWORD16)1<<(16-1); - } - - /* - * The elen/bitword/bitpos bit buffer is known to be - * non-empty, i.e. there is at least one more unconsumed bit. - * Thus, it's safe to square the number. - */ - lbnMontSquare_16(b, a1, mod, mlen, inv); - /* Rename result (in b) back to a (a1, really). */ - a1 = b; b = a; a = a1; - a1 = BIGLITTLE(a-mlen,a+mlen); - } - - /* DONE! Just a little bit of cleanup... */ - - /* - * Convert result out of Montgomery form... this is - * just a Montgomery reduction. - */ - lbnCopy_16(a, a1, mlen); - lbnZero_16(a1, mlen); - lbnMontReduce_16(a, mod, mlen, inv); - lbnCopy_16(n, a1, mlen); - - /* Clean up - free intermediate storage */ - LBNFREE(b, 2*mlen); - LBNFREE(a, 2*mlen); - - return 0; /* Success */ -} - - -/* - * Returns a substring of the big-endian array of bytes representation - * of the bignum array based on two parameters, the least significant - * byte number (0 to start with the least significant byte) and the - * length. I.e. the number returned is a representation of - * (bn / 2^(8*lsbyte)) % 2 ^ (8*buflen). - * - * It is an error if the bignum is not at least buflen + lsbyte bytes - * long. - * - * This code assumes that the compiler has the minimal intelligence - * neded to optimize divides and modulo operations on an unsigned data - * type with a power of two. - */ -void -lbnExtractBigBytes_16(BNWORD16 const *n, unsigned char *buf, - unsigned lsbyte, unsigned buflen) -{ - BNWORD16 t = 0; /* Needed to shut up uninitialized var warnings */ - unsigned shift; - - lsbyte += buflen; - - shift = (8 * lsbyte) % 16; - lsbyte /= (16/8); /* Convert to word offset */ - BIGLITTLE(n -= lsbyte, n += lsbyte); - - if (shift) - t = BIGLITTLE(n[-1],n[0]); - - while (buflen--) { - if (!shift) { - t = BIGLITTLE(*n++,*--n); - shift = 16; - } - shift -= 8; - *buf++ = (unsigned char)(t>>shift); - } -} - -/* - * Merge a big-endian array of bytes into a bignum array. - * The array had better be big enough. This is - * equivalent to extracting the entire bignum into a - * large byte array, copying the input buffer into the - * middle of it, and converting back to a bignum. - * - * The buf is "len" bytes long, and its *last* byte is at - * position "lsbyte" from the end of the bignum. - * - * Note that this is a pain to get right. Fortunately, it's hardly - * critical for efficiency. - */ -void -lbnInsertBigBytes_16(BNWORD16 *n, unsigned char const *buf, - unsigned lsbyte, unsigned buflen) -{ - BNWORD16 t = 0; /* Shut up uninitialized varibale warnings */ - - lsbyte += buflen; - - BIGLITTLE(n -= lsbyte/(16/8), n += lsbyte/(16/8)); - - /* Load up leading odd bytes */ - if (lsbyte % (16/8)) { - t = BIGLITTLE(*--n,*n++); - t >>= (lsbyte * 8) % 16; - } - - /* The main loop - merge into t, storing at each word boundary. */ - while (buflen--) { - t = (t << 8) | *buf++; - if ((--lsbyte % (16/8)) == 0) - BIGLITTLE(*n++,*--n) = t; - } - - /* Merge odd bytes in t into last word */ - lsbyte = (lsbyte * 8) % 16; - if (lsbyte) { - t <<= lsbyte; - t |= (((BNWORD16)1 << lsbyte) - 1) & BIGLITTLE(n[0],n[-1]); - BIGLITTLE(n[0],n[-1]) = t; - } - - return; -} - -/* - * Returns a substring of the little-endian array of bytes representation - * of the bignum array based on two parameters, the least significant - * byte number (0 to start with the least significant byte) and the - * length. I.e. the number returned is a representation of - * (bn / 2^(8*lsbyte)) % 2 ^ (8*buflen). - * - * It is an error if the bignum is not at least buflen + lsbyte bytes - * long. - * - * This code assumes that the compiler has the minimal intelligence - * neded to optimize divides and modulo operations on an unsigned data - * type with a power of two. - */ -void -lbnExtractLittleBytes_16(BNWORD16 const *n, unsigned char *buf, - unsigned lsbyte, unsigned buflen) -{ - BNWORD16 t = 0; /* Needed to shut up uninitialized var warnings */ - - BIGLITTLE(n -= lsbyte/(16/8), n += lsbyte/(16/8)); - - if (lsbyte % (16/8)) { - t = BIGLITTLE(*--n,*n++); - t >>= (lsbyte % (16/8)) * 8 ; - } - - while (buflen--) { - if ((lsbyte++ % (16/8)) == 0) - t = BIGLITTLE(*--n,*n++); - *buf++ = (unsigned char)t; - t >>= 8; - } -} - -/* - * Merge a little-endian array of bytes into a bignum array. - * The array had better be big enough. This is - * equivalent to extracting the entire bignum into a - * large byte array, copying the input buffer into the - * middle of it, and converting back to a bignum. - * - * The buf is "len" bytes long, and its first byte is at - * position "lsbyte" from the end of the bignum. - * - * Note that this is a pain to get right. Fortunately, it's hardly - * critical for efficiency. - */ -void -lbnInsertLittleBytes_16(BNWORD16 *n, unsigned char const *buf, - unsigned lsbyte, unsigned buflen) -{ - BNWORD16 t = 0; /* Shut up uninitialized varibale warnings */ - - /* Move to most-significant end */ - lsbyte += buflen; - buf += buflen; - - BIGLITTLE(n -= lsbyte/(16/8), n += lsbyte/(16/8)); - - /* Load up leading odd bytes */ - if (lsbyte % (16/8)) { - t = BIGLITTLE(*--n,*n++); - t >>= (lsbyte * 8) % 16; - } - - /* The main loop - merge into t, storing at each word boundary. */ - while (buflen--) { - t = (t << 8) | *--buf; - if ((--lsbyte % (16/8)) == 0) - BIGLITTLE(*n++,*--n) = t; - } - - /* Merge odd bytes in t into last word */ - lsbyte = (lsbyte * 8) % 16; - if (lsbyte) { - t <<= lsbyte; - t |= (((BNWORD16)1 << lsbyte) - 1) & BIGLITTLE(n[0],n[-1]); - BIGLITTLE(n[0],n[-1]) = t; - } - - return; -} - -#ifdef DEADCODE /* This was a precursor to the more flexible lbnExtractBytes */ -/* - * Convert a big-endian array of bytes to a bignum. - * Returns the number of words in the bignum. - * Note the expression "16/8" for the number of bytes per word. - * This is so the word-size adjustment will work. - */ -unsigned -lbnFromBytes_16(BNWORD16 *a, unsigned char const *b, unsigned blen) -{ - BNWORD16 t; - unsigned alen = (blen + (16/8-1))/(16/8); - BIGLITTLE(a -= alen, a += alen); - - while (blen) { - t = 0; - do { - t = t << 8 | *b++; - } while (--blen & (16/8-1)); - BIGLITTLE(*a++,*--a) = t; - } - return alen; -} -#endif - -/* - * Computes the GCD of a and b. Modifies both arguments; - * when it returns, one of them is the GCD and the other is trash. - * The return value is the length of the GCD, with the sign telling - * whether it is in a (+ve) or b (-ve). Both inputs must have - * one extra word of precision. alen must be >= blen. - * - * TODO: use the binary algorithm (Knuth section 4.5.2, algorithm B). - * This is based on taking out common powers of 2, then repeatedly: - * gcd(2*u,v) = gcd(u,2*v) = gcd(u,v) - isolated powers of 2 can be deleted. - * gcd(u,v) = gcd(u-v,v) - the numbers can be easily reduced. - * It gets less reduction per step, but the steps are much faster than - * the division case. - */ -int -lbnGcd_16(BNWORD16 *a, unsigned alen, BNWORD16 *b, unsigned blen) -{ - assert(alen >= blen); - - while (blen != 0) { - (void)lbnDiv_16(BIGLITTLE(a-blen,a+blen), a, alen, b, blen); - alen = lbnNorm_16(a, blen); - if (alen == 0) - return -(int)blen; - (void)lbnDiv_16(BIGLITTLE(b-alen,b+alen), b, blen, a, alen); - blen = lbnNorm_16(b, alen); - } - return alen; -} - -/* - * Invert "a" modulo "mod" using the extended Euclidean algorithm. - * Note that this only computes one of the cosequences, and uses the - * theorem that the signs flip every step and the absolute value of - * the cosequence values are always bounded by the modulus to avoid - * having to work with negative numbers. - * gcd(a,mod) had better equal 1. Returns 1 if the GCD is NOT 1. - * a must be one word longer than "mod". It is overwritten with the - * result. - * TODO: Use Richard Schroeppel's *much* faster algorithm. - */ -int -lbnInv_16(BNWORD16 *a, unsigned alen, BNWORD16 const *mod, unsigned mlen) -{ - BNWORD16 *b; /* Hold a copy of mod during GCD reduction */ - BNWORD16 *p; /* Temporary for products added to t0 and t1 */ - BNWORD16 *t0, *t1; /* Inverse accumulators */ - BNWORD16 cy; - unsigned blen, t0len, t1len, plen; - - alen = lbnNorm_16(a, alen); - if (!alen) - return 1; /* No inverse */ - - mlen = lbnNorm_16(mod, mlen); - - assert (alen <= mlen); - - /* Inverse of 1 is 1 */ - if (alen == 1 && BIGLITTLE(a[-1],a[0]) == 1) { - lbnZero_16(BIGLITTLE(a-alen,a+alen), mlen-alen); - return 0; - } - - /* Allocate a pile of space */ - LBNALLOC(b, mlen+1); - if (b) { - /* - * Although products are guaranteed to always be less than the - * modulus, it can involve multiplying two 3-word numbers to - * get a 5-word result, requiring a 6th word to store a 0 - * temporarily. Thus, mlen + 1. - */ - LBNALLOC(p, mlen+1); - if (p) { - LBNALLOC(t0, mlen); - if (t0) { - LBNALLOC(t1, mlen); - if (t1) - goto allocated; - LBNFREE(t0, mlen); - } - LBNFREE(p, mlen+1); - } - LBNFREE(b, mlen+1); - } - return -1; - -allocated: - - /* Set t0 to 1 */ - t0len = 1; - BIGLITTLE(t0[-1],t0[0]) = 1; - - /* b = mod */ - lbnCopy_16(b, mod, mlen); - /* blen = mlen (implicitly) */ - - /* t1 = b / a; b = b % a */ - cy = lbnDiv_16(t1, b, mlen, a, alen); - *(BIGLITTLE(t1-(mlen-alen)-1,t1+(mlen-alen))) = cy; - t1len = lbnNorm_16(t1, mlen-alen+1); - blen = lbnNorm_16(b, alen); - - /* while (b > 1) */ - while (blen > 1 || BIGLITTLE(b[-1],b[0]) != (BNWORD16)1) { - /* q = a / b; a = a % b; */ - if (alen < blen || (alen == blen && lbnCmp_16(a, a, alen) < 0)) - assert(0); - cy = lbnDiv_16(BIGLITTLE(a-blen,a+blen), a, alen, b, blen); - *(BIGLITTLE(a-alen-1,a+alen)) = cy; - plen = lbnNorm_16(BIGLITTLE(a-blen,a+blen), alen-blen+1); - assert(plen); - alen = lbnNorm_16(a, blen); - if (!alen) - goto failure; /* GCD not 1 */ - - /* t0 += q * t1; */ - assert(plen+t1len <= mlen+1); - lbnMul_16(p, BIGLITTLE(a-blen,a+blen), plen, t1, t1len); - plen = lbnNorm_16(p, plen + t1len); - assert(plen <= mlen); - if (plen > t0len) { - lbnZero_16(BIGLITTLE(t0-t0len,t0+t0len), plen-t0len); - t0len = plen; - } - cy = lbnAddN_16(t0, p, plen); - if (cy) { - if (t0len > plen) { - cy = lbnAdd1_16(BIGLITTLE(t0-plen,t0+plen), - t0len-plen, cy); - } - if (cy) { - BIGLITTLE(t0[-t0len-1],t0[t0len]) = cy; - t0len++; - } - } - - /* if (a <= 1) return a ? t0 : FAIL; */ - if (alen <= 1 && BIGLITTLE(a[-1],a[0]) == (BNWORD16)1) { - if (alen == 0) - goto failure; /* FAIL */ - assert(t0len <= mlen); - lbnCopy_16(a, t0, t0len); - lbnZero_16(BIGLITTLE(a-t0len, a+t0len), mlen-t0len); - goto success; - } - - /* q = b / a; b = b % a; */ - if (blen < alen || (blen == alen && lbnCmp_16(b, a, alen) < 0)) - assert(0); - cy = lbnDiv_16(BIGLITTLE(b-alen,b+alen), b, blen, a, alen); - *(BIGLITTLE(b-blen-1,b+blen)) = cy; - plen = lbnNorm_16(BIGLITTLE(b-alen,b+alen), blen-alen+1); - assert(plen); - blen = lbnNorm_16(b, alen); - if (!blen) - goto failure; /* GCD not 1 */ - - /* t1 += q * t0; */ - assert(plen+t0len <= mlen+1); - lbnMul_16(p, BIGLITTLE(b-alen,b+alen), plen, t0, t0len); - plen = lbnNorm_16(p, plen + t0len); - assert(plen <= mlen); - if (plen > t1len) { - lbnZero_16(BIGLITTLE(t1-t1len,t1+t1len), plen-t1len); - t1len = plen; - } - cy = lbnAddN_16(t1, p, plen); - if (cy) { - if (t1len > plen) { - cy = lbnAdd1_16(BIGLITTLE(t1-plen,t0+plen), - t1len-plen, cy); - } - if (cy) { - BIGLITTLE(t1[-t1len-1],t1[t1len]) = cy; - t1len++; - } - } - } - - if (!blen) - goto failure; /* gcd(a, mod) != 1 -- FAIL */ - - /* return mod-t1 */ - lbnCopy_16(a, mod, mlen); - assert(t1len <= mlen); - cy = lbnSubN_16(a, t1, t1len); - if (cy) { - assert(mlen > t1len); - cy = lbnSub1_16(BIGLITTLE(a-t1len, a+t1len), mlen-t1len, cy); - assert(!cy); - } - -success: - LBNFREE(t1, mlen); - LBNFREE(t0, mlen); - LBNFREE(p, mlen+1); - LBNFREE(b, mlen+1); - - return 0; - -failure: - LBNFREE(t1, mlen); - LBNFREE(t0, mlen); - LBNFREE(p, mlen+1); - LBNFREE(b, mlen+1); - - return 1; -} diff --git a/usr/src/lib/libresolv2/common/cylink/lbn16.h b/usr/src/lib/libresolv2/common/cylink/lbn16.h deleted file mode 100644 index 52e156886e..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbn16.h +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#ifndef LBN16_H -#define LBN16_H - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "lbn.h" - -#ifndef BNWORD16 -#error 16-bit bignum library requires a 16-bit data type -#endif - -#ifndef lbnCopy_16 -void lbnCopy_16(BNWORD16 *dest, BNWORD16 const *src, unsigned len); -#endif -#ifndef lbnZero_16 -void lbnZero_16(BNWORD16 *num, unsigned len); -#endif -#ifndef lbnNeg_16 -void lbnNeg_16(BNWORD16 *num, unsigned len); -#endif - -#ifndef lbnAdd1_16 -BNWORD16 lbnAdd1_16(BNWORD16 *num, unsigned len, BNWORD16 carry); -#endif -#ifndef lbnSub1_16 -BNWORD16 lbnSub1_16(BNWORD16 *num, unsigned len, BNWORD16 borrow); -#endif - -#ifndef lbnAddN_16 -BNWORD16 lbnAddN_16(BNWORD16 *num1, BNWORD16 const *num2, unsigned len); -#endif -#ifndef lbnSubN_16 -BNWORD16 lbnSubN_16(BNWORD16 *num1, BNWORD16 const *num2, unsigned len); -#endif - -#ifndef lbnCmp_16 -int lbnCmp_16(BNWORD16 const *num1, BNWORD16 const *num2, unsigned len); -#endif - -#ifndef lbnMulN1_16 -void lbnMulN1_16(BNWORD16 *out, BNWORD16 const *in, unsigned len, BNWORD16 k); -#endif -#ifndef lbnMulAdd1_16 -BNWORD16 -lbnMulAdd1_16(BNWORD16 *out, BNWORD16 const *in, unsigned len, BNWORD16 k); -#endif -#ifndef lbnMulSub1_16 -BNWORD16 lbnMulSub1_16(BNWORD16 *out, BNWORD16 const *in, unsigned len, BNWORD16 k); -#endif - -#ifndef lbnLshift_16 -BNWORD16 lbnLshift_16(BNWORD16 *num, unsigned len, unsigned shift); -#endif -#ifndef lbnDouble_16 -BNWORD16 lbnDouble_16(BNWORD16 *num, unsigned len); -#endif -#ifndef lbnRshift_16 -BNWORD16 lbnRshift_16(BNWORD16 *num, unsigned len, unsigned shift); -#endif - -#ifndef lbnMul_16 -void lbnMul_16(BNWORD16 *prod, BNWORD16 const *num1, unsigned len1, - BNWORD16 const *num2, unsigned len2); -#endif -#ifndef lbnSquare_16 -void lbnSquare_16(BNWORD16 *prod, BNWORD16 const *num, unsigned len); -#endif - -#ifndef lbnNorm_16 -unsigned lbnNorm_16(BNWORD16 const *num, unsigned len); -#endif -#ifndef lbnBits_16 -unsigned lbnBits_16(BNWORD16 const *num, unsigned len); -#endif - -#ifndef lbnExtractBigBytes_16 -void lbnExtractBigBytes_16(BNWORD16 const *bn, unsigned char *buf, - unsigned lsbyte, unsigned buflen); -#endif -#ifndef lbnInsertBigytes_16 -void lbnInsertBigBytes_16(BNWORD16 *n, unsigned char const *buf, - unsigned lsbyte, unsigned buflen); -#endif -#ifndef lbnExtractLittleBytes_16 -void lbnExtractLittleBytes_16(BNWORD16 const *bn, unsigned char *buf, - unsigned lsbyte, unsigned buflen); -#endif -#ifndef lbnInsertLittleBytes_16 -void lbnInsertLittleBytes_16(BNWORD16 *n, unsigned char const *buf, - unsigned lsbyte, unsigned buflen); -#endif - -#ifndef lbnDiv21_16 -BNWORD16 lbnDiv21_16(BNWORD16 *q, BNWORD16 nh, BNWORD16 nl, BNWORD16 d); -#endif -#ifndef lbnDiv1_16 -BNWORD16 lbnDiv1_16(BNWORD16 *q, BNWORD16 *rem, - BNWORD16 const *n, unsigned len, BNWORD16 d); -#endif -#ifndef lbnModQ_16 -unsigned lbnModQ_16(BNWORD16 const *n, unsigned len, unsigned d); -#endif -#ifndef lbnDiv_16 -BNWORD16 -lbnDiv_16(BNWORD16 *q, BNWORD16 *n, unsigned nlen, BNWORD16 *d, unsigned dlen); -#endif - -#ifndef lbnMontInv1_16 -BNWORD16 lbnMontInv1_16(BNWORD16 const x); -#endif -#ifndef lbnMontReduce_16 -void lbnMontReduce_16(BNWORD16 *n, BNWORD16 const *mod, unsigned const mlen, - BNWORD16 inv); -#endif -#ifndef lbnToMont_16 -void lbnToMont_16(BNWORD16 *n, unsigned nlen, BNWORD16 *mod, unsigned mlen); -#endif -#ifndef lbnFromMont_16 -void lbnFromMont_16(BNWORD16 *n, BNWORD16 *mod, unsigned len); -#endif - -#ifndef lbnExpMod_16 -int lbnExpMod_16(BNWORD16 *result, BNWORD16 const *n, unsigned nlen, - BNWORD16 const *exp, unsigned elen, BNWORD16 *mod, unsigned mlen); -#endif -#ifndef lbnDoubleExpMod_16 -int lbnDoubleExpMod_16(BNWORD16 *result, - BNWORD16 const *n1, unsigned n1len, BNWORD16 const *e1, unsigned e1len, - BNWORD16 const *n2, unsigned n2len, BNWORD16 const *e2, unsigned e2len, - BNWORD16 *mod, unsigned mlen); -#endif -#ifndef lbnTwoExpMod_16 -int lbnTwoExpMod_16(BNWORD16 *n, BNWORD16 const *exp, unsigned elen, - BNWORD16 *mod, unsigned mlen); -#endif -#ifndef lbnGcd_16 -int lbnGcd_16(BNWORD16 *a, unsigned alen, BNWORD16 *b, unsigned blen); -#endif -#ifndef lbnInv_16 -int lbnInv_16(BNWORD16 *a, unsigned alen, BNWORD16 const *mod, unsigned mlen); -#endif - -#endif /* LBN16_H */ diff --git a/usr/src/lib/libresolv2/common/cylink/lbn32.c b/usr/src/lib/libresolv2/common/cylink/lbn32.c deleted file mode 100644 index 4cdfabf48e..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbn32.c +++ /dev/null @@ -1,3650 +0,0 @@ -/* - * Copyright (c) 2001 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * lbn32.c - Low-level bignum routines, 32-bit version. - * - * Copyright (c) 1995 Colin Plumb. All rights reserved. - * For licensing and other legal details, see the file legal.c. - * - * NOTE: the magic constants "32" and "64" appear in many places in this - * file, including inside identifiers. Because it is not possible to - * ask "#ifdef" of a macro expansion, it is not possible to use the - * preprocessor to conditionalize these properly. Thus, this file is - * intended to be edited with textual search and replace to produce - * alternate word size versions. Any reference to the number of bits - * in a word must be the string "32", and that string must not appear - * otherwise. Any reference to twice this number must appear as "64", - * which likewise must not appear otherwise. Is that clear? - * - * Remember, when doubling the bit size replace the larger number (64) - * first, then the smaller (32). When halving the bit size, do the - * opposite. Otherwise, things will get wierd. Also, be sure to replace - * every instance that appears. (:%s/foo/bar/g in vi) - * - * These routines work with a pointer to the least-significant end of - * an array of WORD32s. The BIG(x), LITTLE(y) and BIGLTTLE(x,y) macros - * defined in lbn.h (which expand to x on a big-edian machine and y on a - * little-endian machine) are used to conditionalize the code to work - * either way. If you have no assembly primitives, it doesn't matter. - * Note that on a big-endian machine, the least-significant-end pointer - * is ONE PAST THE END. The bytes are ptr[-1] through ptr[-len]. - * On little-endian, they are ptr[0] through ptr[len-1]. This makes - * perfect sense if you consider pointers to point *between* bytes rather - * than at them. - * - * Because the array index values are unsigned integers, ptr[-i] - * may not work properly, since the index -i is evaluated as an unsigned, - * and if pointers are wider, zero-extension will produce a positive - * number rahter than the needed negative. The expression used in this - * code, *(ptr-i) will, however, work. (The array syntax is equivalent - * to *(ptr+-i), which is a pretty subtle difference.) - * - * Many of these routines will get very unhappy if fed zero-length inputs. - * They use assert() to enforce this. An higher layer of code must make - * sure that these aren't called with zero-length inputs. - * - * Any of these routines can be replaced with more efficient versions - * elsewhere, by just #defining their names. If one of the names - * is #defined, the C code is not compiled in and no declaration is - * made. Use the BNINCLUDE file to do that. Typically, you compile - * asm subroutines with the same name and just, e.g. - * #define lbnMulAdd1_32 lbnMulAdd1_32 - * - * If you want to write asm routines, start with lbnMulAdd1_32(). - * This is the workhorse of modular exponentiation. lbnMulN1_32() is - * also used a fair bit, although not as much and it's defined in terms - * of lbnMulAdd1_32 if that has a custom version. lbnMulSub1_32 and - * lbnDiv21_32 are used in the usual division and remainder finding. - * (Not the Montgomery reduction used in modular exponentiation, though.) - * Once you have lbnMulAdd1_32 defined, writing the other two should - * be pretty easy. (Just make sure you get the sign of the subtraction - * in lbnMulSub1_32 right - it's dest = dest - source * k.) - * - * The only definitions that absolutely need a double-word (BNWORD64) - * type are lbnMulAdd1_32 and lbnMulSub1_32; if those are provided, - * the rest follows. lbnDiv21_32, however, is a lot slower unless you - * have them, and lbnModQ_32 takes after it. That one is used quite a - * bit for prime sieving. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifndef HAVE_CONFIG_H -#define HAVE_CONFIG_H 0 -#endif -#if HAVE_CONFIG_H -#include "config.h" -#endif - -/* - * Some compilers complain about #if FOO if FOO isn't defined, - * so do the ANSI-mandated thing explicitly... - */ -#ifndef NO_ASSERT_H -#define NO_ASSERT_H 0 -#endif -#ifndef NO_STRING_H -#define NO_STRING_H 0 -#endif -#ifndef HAVE_STRINGS_H -#define HAVE_STRINGS_H 0 -#endif -#ifndef NEED_MEMORY_H -#define NEED_MEMORY_H 0 -#endif - -#if !NO_ASSERT_H -#include <assert.h> -#else -#define assert(x) (void)0 -#endif - -#if !NO_STRING_H -#include <string.h> /* For memcpy */ -#elif HAVE_STRINGS_H -#include <strings.h> -#endif -#if NEED_MEMORY_H -#include <memory.h> -#endif - -#include "lbn.h" -#include "lbn32.h" -#include "lbnmem.h" -#include "legal.h" - -#include "kludge.h" -#include <port_after.h> - -#ifndef BNWORD32 -#error 32-bit bignum library requires a 32-bit data type -#endif - -/* Make sure the copyright notice gets included */ -volatile const char * volatile const lbnCopyright_32 = bnCopyright; - -/* - * Most of the multiply (and Montgomery reduce) routines use an outer - * loop that iterates over one of the operands - a so-called operand - * scanning approach. One big advantage of this is that the assembly - * support routines are simpler. The loops can be rearranged to have - * an outer loop that iterates over the product, a so-called product - * scanning approach. This has the advantage of writing less data - * and doing fewer adds to memory, so is supposedly faster. Some - * code has been written using a product-scanning approach, but - * it appears to be slower, so it is turned off by default. Some - * experimentation would be appreciated. - * - * (The code is also annoying to get right and not very well commented, - * one of my pet peeves about math libraries. I'm sorry.) - */ -#ifndef PRODUCT_SCAN -#define PRODUCT_SCAN 0 -#endif - -/* - * Copy an array of words. <Marvin mode on> Thrilling, isn't it? </Marvin> - * This is a good example of how the byte offsets and BIGLITTLE() macros work. - * Another alternative would have been - * memcpy(dest BIG(-len), src BIG(-len), len*sizeof(BNWORD32)), but I find that - * putting operators into conditional macros is confusing. - */ -#ifndef lbnCopy_32 -void -lbnCopy_32(BNWORD32 *dest, BNWORD32 const *src, unsigned len) -{ - memcpy(BIGLITTLE(dest-len,dest), BIGLITTLE(src-len,src), - len * sizeof(*src)); -} -#endif /* !lbnCopy_32 */ - -/* - * Fill n words with zero. This does it manually rather than calling - * memset because it can assume alignment to make things faster while - * memset can't. Note how big-endian numbers are naturally addressed - * using predecrement, while little-endian is postincrement. - */ -#ifndef lbnZero_32 -void -lbnZero_32(BNWORD32 *num, unsigned len) -{ - while (len--) - BIGLITTLE(*--num,*num++) = 0; -} -#endif /* !lbnZero_32 */ - -/* - * Negate an array of words. - * Negation is subtraction from zero. Negating low-order words - * entails doing nothing until a non-zero word is hit. Once that - * is negated, a borrow is generated and never dies until the end - * of the number is hit. Negation with borrow, -x-1, is the same as ~x. - * Repeat that until the end of the number. - * - * Doesn't return borrow out because that's pretty useless - it's - * always set unless the input is 0, which is easy to notice in - * normalized form. - */ -#ifndef lbnNeg_32 -void -lbnNeg_32(BNWORD32 *num, unsigned len) -{ - assert(len); - - /* Skip low-order zero words */ - while (BIGLITTLE(*--num,*num) == 0) { - if (!--len) - return; - LITTLE(num++;) - } - /* Negate the lowest-order non-zero word */ - *num = -*num; - /* Complement all the higher-order words */ - while (--len) { - BIGLITTLE(--num,++num); - *num = ~*num; - } -} -#endif /* !lbnNeg_32 */ - - -/* - * lbnAdd1_32: add the single-word "carry" to the given number. - * Used for minor increments and propagating the carry after - * adding in a shorter bignum. - * - * Technique: If we have a double-width word, presumably the compiler - * can add using its carry in inline code, so we just use a larger - * accumulator to compute the carry from the first addition. - * If not, it's more complex. After adding the first carry, which may - * be > 1, compare the sum and the carry. If the sum wraps (causing a - * carry out from the addition), the result will be less than each of the - * inputs, since the wrap subtracts a number (2^32) which is larger than - * the other input can possibly be. If the sum is >= the carry input, - * return success immediately. - * In either case, if there is a carry, enter a loop incrementing words - * until one does not wrap. Since we are adding 1 each time, the wrap - * will be to 0 and we can test for equality. - */ -#ifndef lbnAdd1_32 /* If defined, it's provided as an asm subroutine */ -#ifdef BNWORD64 -BNWORD32 -lbnAdd1_32(BNWORD32 *num, unsigned len, BNWORD32 carry) -{ - BNWORD64 t; - assert(len > 0); /* Alternative: if (!len) return carry */ - - t = (BNWORD64)BIGLITTLE(*--num,*num) + carry; - BIGLITTLE(*num,*num++) = (BNWORD32)t; - if ((t >> 32) == 0) - return 0; - while (--len) { - if (++BIGLITTLE(*--num,*num++) != 0) - return 0; - } - return 1; -} -#else /* no BNWORD64 */ -BNWORD32 -lbnAdd1_32(BNWORD32 *num, unsigned len, BNWORD32 carry) -{ - assert(len > 0); /* Alternative: if (!len) return carry */ - - if ((BIGLITTLE(*--num,*num++) += carry) >= carry) - return 0; - while (--len) { - if (++BIGLITTLE(*--num,*num++) != 0) - return 0; - } - return 1; -} -#endif -#endif/* !lbnAdd1_32 */ - -/* - * lbnSub1_32: subtract the single-word "borrow" from the given number. - * Used for minor decrements and propagating the borrow after - * subtracting a shorter bignum. - * - * Technique: Similar to the add, above. If there is a double-length type, - * use that to generate the first borrow. - * If not, after subtracting the first borrow, which may be > 1, compare - * the difference and the *negative* of the carry. If the subtract wraps - * (causing a borrow out from the subtraction), the result will be at least - * as large as -borrow. If the result < -borrow, then no borrow out has - * appeared and we may return immediately, except when borrow == 0. To - * deal with that case, use the identity that -x = ~x+1, and instead of - * comparing < -borrow, compare for <= ~borrow. - * Either way, if there is a borrow out, enter a loop decrementing words - * until a non-zero word is reached. - * - * Note the cast of ~borrow to (BNWORD32). If the size of an int is larger - * than BNWORD32, C rules say the number is expanded for the arithmetic, so - * the inversion will be done on an int and the value won't be quite what - * is expected. - */ -#ifndef lbnSub1_32 /* If defined, it's provided as an asm subroutine */ -#ifdef BNWORD64 -BNWORD32 -lbnSub1_32(BNWORD32 *num, unsigned len, BNWORD32 borrow) -{ - BNWORD64 t; - assert(len > 0); /* Alternative: if (!len) return borrow */ - - t = (BNWORD64)BIGLITTLE(*--num,*num) - borrow; - BIGLITTLE(*num,*num++) = (BNWORD32)t; - if ((t >> 32) == 0) - return 0; - while (--len) { - if ((BIGLITTLE(*--num,*num++))-- != 0) - return 0; - } - return 1; -} -#else /* no BNWORD64 */ -BNWORD32 -lbnSub1_32(BNWORD32 *num, unsigned len, BNWORD32 borrow) -{ - assert(len > 0); /* Alternative: if (!len) return borrow */ - - if ((BIGLITTLE(*--num,*num++) -= borrow) <= (BNWORD32)~borrow) - return 0; - while (--len) { - if ((BIGLITTLE(*--num,*num++))-- != 0) - return 0; - } - return 1; -} -#endif -#endif /* !lbnSub1_32 */ - -/* - * lbnAddN_32: add two bignums of the same length, returning the carry (0 or 1). - * One of the building blocks, along with lbnAdd1, of adding two bignums of - * differing lengths. - * - * Technique: Maintain a word of carry. If there is no double-width type, - * use the same technique as in lbnAdd1, above, to maintain the carry by - * comparing the inputs. Adding the carry sources is used as an OR operator; - * at most one of the two comparisons can possibly be true. The first can - * only be true if carry == 1 and x, the result, is 0. In that case the - * second can't possibly be true. - */ -#ifndef lbnAddN_32 -#ifdef BNWORD64 -BNWORD32 -lbnAddN_32(BNWORD32 *num1, BNWORD32 const *num2, unsigned len) -{ - BNWORD64 t; - - assert(len > 0); - - t = (BNWORD64)BIGLITTLE(*--num1,*num1) + BIGLITTLE(*--num2,*num2++); - BIGLITTLE(*num1,*num1++) = (BNWORD32)t; - while (--len) { - t = (BNWORD64)BIGLITTLE(*--num1,*num1) + - (BNWORD64)BIGLITTLE(*--num2,*num2++) + (t >> 32); - BIGLITTLE(*num1,*num1++) = (BNWORD32)t; - } - - return (BNWORD32)(t>>32); -} -#else /* no BNWORD64 */ -BNWORD32 -lbnAddN_32(BNWORD32 *num1, BNWORD32 const *num2, unsigned len) -{ - BNWORD32 x, carry = 0; - - assert(len > 0); /* Alternative: change loop to test at start */ - - do { - x = BIGLITTLE(*--num2,*num2++); - carry = (x += carry) < carry; - carry += (BIGLITTLE(*--num1,*num1++) += x) < x; - } while (--len); - - return carry; -} -#endif -#endif /* !lbnAddN_32 */ - -/* - * lbnSubN_32: add two bignums of the same length, returning the carry (0 or 1). - * One of the building blocks, along with subn1, of subtracting two bignums of - * differing lengths. - * - * Technique: If no double-width type is availble, maintain a word of borrow. - * First, add the borrow to the subtrahend (did you have to learn all those - * awful words in elementary school, too?), and if it overflows, set the - * borrow again. Then subtract the modified subtrahend from the next word - * of input, using the same technique as in subn1, above. - * Adding the borrows is used as an OR operator; at most one of the two - * comparisons can possibly be true. The first can only be true if - * borrow == 1 and x, the result, is 0. In that case the second can't - * possibly be true. - * - * In the double-word case, (BNWORD32)-(t>>32) is subtracted, rather than - * adding t>>32, because the shift would need to sign-extend and that's - * not guaranteed to happen in ANSI C, even with signed types. - */ -#ifndef lbnSubN_32 -#ifdef BNWORD64 -BNWORD32 -lbnSubN_32(BNWORD32 *num1, BNWORD32 const *num2, unsigned len) -{ - BNWORD64 t; - - assert(len > 0); - - t = (BNWORD64)BIGLITTLE(*--num1,*num1) - BIGLITTLE(*--num2,*num2++); - BIGLITTLE(*num1,*num1++) = (BNWORD32)t; - - while (--len) { - t = (BNWORD64)BIGLITTLE(*--num1,*num1) - - (BNWORD64)BIGLITTLE(*--num2,*num2++) - (BNWORD32)-(t >> 32); - BIGLITTLE(*num1,*num1++) = (BNWORD32)t; - } - - return -(BNWORD32)(t>>32); -} -#else -BNWORD32 -lbnSubN_32(BNWORD32 *num1, BNWORD32 const *num2, unsigned len) -{ - BNWORD32 x, borrow = 0; - - assert(len > 0); /* Alternative: change loop to test at start */ - - do { - x = BIGLITTLE(*--num2,*num2++); - borrow = (x += borrow) < borrow; - borrow += (BIGLITTLE(*--num1,*num1++) -= x) > (BNWORD32)~x; - } while (--len); - - return borrow; -} -#endif -#endif /* !lbnSubN_32 */ - -#ifndef lbnCmp_32 -/* - * lbnCmp_32: compare two bignums of equal length, returning the sign of - * num1 - num2. (-1, 0 or +1). - * - * Technique: Change the little-endian pointers to big-endian pointers - * and compare from the most-significant end until a difference if found. - * When it is, figure out the sign of the difference and return it. - */ -int -lbnCmp_32(BNWORD32 const *num1, BNWORD32 const *num2, unsigned len) -{ - BIGLITTLE(num1 -= len, num1 += len); - BIGLITTLE(num2 -= len, num2 += len); - - while (len--) { - if (BIGLITTLE(*num1++ != *num2++, *--num1 != *--num2)) { - if (BIGLITTLE(num1[-1] < num2[-1], *num1 < *num2)) - return -1; - else - return 1; - } - } - return 0; -} -#endif /* !lbnCmp_32 */ - -/* - * mul32_ppmmaa(ph,pl,x,y,a,b) is an optional routine that - * computes (ph,pl) = x * y + a + b. mul32_ppmma and mul32_ppmm - * are simpler versions. If you want to be lazy, all of these - * can be defined in terms of the others, so here we create any - * that have not been defined in terms of the ones that have been. - */ - -/* Define ones with fewer a's in terms of ones with more a's */ -#if !defined(mul32_ppmma) && defined(mul32_ppmmaa) -#define mul32_ppmma(ph,pl,x,y,a) mul32_ppmmaa(ph,pl,x,y,a,0) -#endif - -#if !defined(mul32_ppmm) && defined(mul32_ppmma) -#define mul32_ppmm(ph,pl,x,y) mul32_ppmma(ph,pl,x,y,0) -#endif - -/* - * Use this definition to test the mul32_ppmm-based operations on machines - * that do not provide mul32_ppmm. Change the final "0" to a "1" to - * enable it. - */ -#if !defined(mul32_ppmm) && defined(BNWORD64) && 0 /* Debugging */ -#define mul32_ppmm(ph,pl,x,y) \ - ({BNWORD64 _ = (BNWORD64)(x)*(y); (pl) = _; (ph) = _>>32;}) -#endif - -#if defined(mul32_ppmm) && !defined(mul32_ppmma) -#define mul32_ppmma(ph,pl,x,y,a) \ - (mul32_ppmm(ph,pl,x,y), (ph) += ((pl) += (a)) < (a)) -#endif - -#if defined(mul32_ppmma) && !defined(mul32_ppmmaa) -#define mul32_ppmmaa(ph,pl,x,y,a,b) \ - (mul32_ppmma(ph,pl,x,y,a), (ph) += ((pl) += (b)) < (b)) -#endif - -/* - * lbnMulN1_32: Multiply an n-word input by a 1-word input and store the - * n+1-word product. This uses either the mul32_ppmm and mul32_ppmma - * macros, or C multiplication with the BNWORD64 type. This uses mul32_ppmma - * if available, assuming you won't bother defining it unless you can do - * better than the normal multiplication. - */ -#ifndef lbnMulN1_32 -#ifdef lbnMulAdd1_32 /* If we have this asm primitive, use it. */ -void -lbnMulN1_32(BNWORD32 *out, BNWORD32 const *in, unsigned len, BNWORD32 k) -{ - lbnZero_32(out, len); - BIGLITTLE(*(out-len),*(out+len)) = lbnMulAdd1_32(out, in, len, k); -} -#elif defined(mul32_ppmm) -void -lbnMulN1_32(BNWORD32 *out, BNWORD32 const *in, unsigned len, BNWORD32 k) -{ - BNWORD32 prod, carry, carryin; - - assert(len > 0); - - BIG(--out;--in;); - mul32_ppmm(carry, *out, *in, k); - LITTLE(out++;in++;) - - while (--len) { - BIG(--out;--in;) - carryin = carry; - mul32_ppmma(carry, *out, *in, k, carryin); - LITTLE(out++;in++;) - } - BIGLITTLE(*--out,*out) = carry; -} -#elif defined(BNWORD64) -void -lbnMulN1_32(BNWORD32 *out, BNWORD32 const *in, unsigned len, BNWORD32 k) -{ - BNWORD64 p; - - assert(len > 0); - - p = (BNWORD64)BIGLITTLE(*--in,*in++) * k; - BIGLITTLE(*--out,*out++) = (BNWORD32)p; - - while (--len) { - p = (BNWORD64)BIGLITTLE(*--in,*in++) * k + (BNWORD32)(p >> 32); - BIGLITTLE(*--out,*out++) = (BNWORD32)p; - } - BIGLITTLE(*--out,*out) = (BNWORD32)(p >> 32); -} -#else -#error No 32x32 -> 64 multiply available for 32-bit bignum package -#endif -#endif /* lbnMulN1_32 */ - -/* - * lbnMulAdd1_32: Multiply an n-word input by a 1-word input and add the - * low n words of the product to the destination. *Returns the n+1st word - * of the product.* (That turns out to be more convenient than adding - * it into the destination and dealing with a possible unit carry out - * of *that*.) This uses either the mul32_ppmma and mul32_ppmmaa macros, - * or C multiplication with the BNWORD64 type. - * - * If you're going to write assembly primitives, this is the one to - * start with. It is by far the most commonly called function. - */ -#ifndef lbnMulAdd1_32 -#if defined(mul32_ppmm) -BNWORD32 -lbnMulAdd1_32(BNWORD32 *out, BNWORD32 const *in, unsigned len, BNWORD32 k) -{ - BNWORD32 prod, carry, carryin; - - assert(len > 0); - - BIG(--out;--in;); - carryin = *out; - mul32_ppmma(carry, *out, *in, k, carryin); - LITTLE(out++;in++;) - - while (--len) { - BIG(--out;--in;); - carryin = carry; - mul32_ppmmaa(carry, prod, *in, k, carryin, *out); - *out = prod; - LITTLE(out++;in++;) - } - - return carry; -} -#elif defined(BNWORD64) -BNWORD32 -lbnMulAdd1_32(BNWORD32 *out, BNWORD32 const *in, unsigned len, BNWORD32 k) -{ - BNWORD64 p; - - assert(len > 0); - - p = (BNWORD64)BIGLITTLE(*--in,*in++) * k + BIGLITTLE(*--out,*out); - BIGLITTLE(*out,*out++) = (BNWORD32)p; - - while (--len) { - p = (BNWORD64)BIGLITTLE(*--in,*in++) * k + - (BNWORD32)(p >> 32) + BIGLITTLE(*--out,*out); - BIGLITTLE(*out,*out++) = (BNWORD32)p; - } - - return (BNWORD32)(p >> 32); -} -#else -#error No 32x32 -> 64 multiply available for 32-bit bignum package -#endif -#endif /* lbnMulAdd1_32 */ - -/* - * lbnMulSub1_32: Multiply an n-word input by a 1-word input and subtract the - * n-word product from the destination. Returns the n+1st word of the product. - * This uses either the mul32_ppmm and mul32_ppmma macros, or - * C multiplication with the BNWORD64 type. - * - * This is rather uglier than adding, but fortunately it's only used in - * division which is not used too heavily. - */ -#ifndef lbnMulN1_32 -#if defined(mul32_ppmm) -BNWORD32 -lbnMulSub1_32(BNWORD32 *out, BNWORD32 const *in, unsigned len, BNWORD32 k) -{ - BNWORD32 prod, carry, carryin; - - assert(len > 0); - - BIG(--in;) - mul32_ppmm(carry, prod, *in, k); - LITTLE(in++;) - carry += (BIGLITTLE(*--out,*out++) -= prod) > (BNWORD32)~prod; - - while (--len) { - BIG(--in;); - carryin = carry; - mul32_ppmma(carry, prod, *in, k, carryin); - LITTLE(in++;) - carry += (BIGLITTLE(*--out,*out++) -= prod) > (BNWORD32)~prod; - } - - return carry; -} -#elif defined(BNWORD64) -BNWORD32 -lbnMulSub1_32(BNWORD32 *out, BNWORD32 const *in, unsigned len, BNWORD32 k) -{ - BNWORD64 p; - BNWORD32 carry, t; - - assert(len > 0); - - p = (BNWORD64)BIGLITTLE(*--in,*in++) * k; - t = BIGLITTLE(*--out,*out); - carry = (BNWORD32)(p>>32) + ((BIGLITTLE(*out,*out++)=t-(BNWORD32)p) > t); - - while (--len) { - p = (BNWORD64)BIGLITTLE(*--in,*in++) * k + carry; - t = BIGLITTLE(*--out,*out); - carry = (BNWORD32)(p>>32) + - ( (BIGLITTLE(*out,*out++)=t-(BNWORD32)p) > t ); - } - - return carry; -} -#else -#error No 32x32 -> 64 multiply available for 32-bit bignum package -#endif -#endif /* !lbnMulSub1_32 */ - -/* - * Shift n words left "shift" bits. 0 < shift < 32. Returns the - * carry, any bits shifted off the left-hand side (0 <= carry < 2^shift). - */ -#ifndef lbnLshift_32 -BNWORD32 -lbnLshift_32(BNWORD32 *num, unsigned len, unsigned shift) -{ - BNWORD32 x, carry; - - assert(shift > 0); - assert(shift < 32); - - carry = 0; - while (len--) { - BIG(--num;) - x = *num; - *num = (x<<shift) | carry; - LITTLE(num++;) - carry = x >> (32-shift); - } - return carry; -} -#endif /* !lbnLshift_32 */ - -/* - * An optimized version of the above, for shifts of 1. - * Some machines can use add-with-carry tricks for this. - */ -#ifndef lbnDouble_32 -BNWORD32 -lbnDouble_32(BNWORD32 *num, unsigned len) -{ - BNWORD32 x, carry; - - carry = 0; - while (len--) { - BIG(--num;) - x = *num; - *num = (x<<1) | carry; - LITTLE(num++;) - carry = x >> (32-1); - } - return carry; -} -#endif /* !lbnDouble_32 */ - -/* - * Shift n words right "shift" bits. 0 < shift < 32. Returns the - * carry, any bits shifted off the right-hand side (0 <= carry < 2^shift). - */ -#ifndef lbnRshift_32 -BNWORD32 -lbnRshift_32(BNWORD32 *num, unsigned len, unsigned shift) -{ - BNWORD32 x, carry = 0; - - assert(shift > 0); - assert(shift < 32); - - BIGLITTLE(num -= len, num += len); - - while (len--) { - LITTLE(--num;) - x = *num; - *num = (x>>shift) | carry; - BIG(num++;) - carry = x << (32-shift); - } - return carry >> (32-shift); -} -#endif /* !lbnRshift_32 */ - -/* - * Multiply two numbers of the given lengths. prod and num2 may overlap, - * provided that the low len1 bits of prod are free. (This corresponds - * nicely to the place the result is returned from lbnMontReduce_32.) - * - * TODO: Use Karatsuba multiply. The overlap constraints may have - * to get rewhacked. - */ -#ifndef lbnMul_32 -void -lbnMul_32(BNWORD32 *prod, BNWORD32 const *num1, unsigned len1, - BNWORD32 const *num2, unsigned len2) -{ - /* Special case of zero */ - if (!len1 || !len2) { - lbnZero_32(prod, len1+len2); - return; - } - - /* Multiply first word */ - lbnMulN1_32(prod, num1, len1, BIGLITTLE(*--num2,*num2++)); - - /* - * Add in subsequent words, storing the most significant word, - * which is new each time. - */ - while (--len2) { - BIGLITTLE(--prod,prod++); - BIGLITTLE(*(prod-len1-1),*(prod+len1)) = - lbnMulAdd1_32(prod, num1, len1, BIGLITTLE(*--num2,*num2++)); - } -} -#endif /* !lbnMul_32 */ - -/* - * lbnMulX_32 is a square multiply - both inputs are the same length. - * It's normally just a macro wrapper around the general multiply, - * but might be implementable in assembly more efficiently (such as - * when product scanning). - */ -#ifndef lbnMulX_32 -#if defined(BNWORD64) && PRODUCT_SCAN -/* - * Test code to see whether product scanning is any faster. It seems - * to make the C code slower, so PRODUCT_SCAN is not defined. - */ -static void -lbnMulX_32(BNWORD32 *prod, BNWORD32 const *num1, BNWORD32 const *num2, - unsigned len) -{ - BNWORD64 x, y; - BNWORD32 const *p1, *p2; - unsigned carry; - unsigned i, j; - - /* Special case of zero */ - if (!len) - return; - - x = (BNWORD64)BIGLITTLE(num1[-1] * num2[-1], num1[0] * num2[0]); - BIGLITTLE(*--prod, *prod++) = (BNWORD32)x; - x >>= 32; - - for (i = 1; i < len; i++) { - carry = 0; - p1 = num1; - p2 = BIGLITTLE(num2-i-1,num2+i+1); - for (j = 0; j <= i; j++) { - BIG(y = (BNWORD64)*--p1 * *p2++;) - LITTLE(y = (BNWORD64)*p1++ * *--p2;) - x += y; - carry += (x < y); - } - BIGLITTLE(*--prod,*prod++) = (BNWORD32)x; - x = (x >> 32) | (BNWORD64)carry << 32; - } - for (i = 1; i < len; i++) { - carry = 0; - p1 = BIGLITTLE(num1-i,num1+i); - p2 = BIGLITTLE(num2-len,num2+len); - for (j = i; j < len; j++) { - BIG(y = (BNWORD64)*--p1 * *p2++;) - LITTLE(y = (BNWORD64)*p1++ * *--p2;) - x += y; - carry += (x < y); - } - BIGLITTLE(*--prod,*prod++) = (BNWORD32)x; - x = (x >> 32) | (BNWORD64)carry << 32; - } - - BIGLITTLE(*--prod,*prod) = (BNWORD32)x; -} -#else /* !defined(BNWORD64) || !PRODUCT_SCAN */ -/* Default trivial macro definition */ -#define lbnMulX_32(prod, num1, num2, len) lbnMul_32(prod, num1, len, num2, len) -#endif /* !defined(BNWORD64) || !PRODUCT_SCAN */ -#endif /* !lbmMulX_32 */ - -#if !defined(lbnMontMul_32) && defined(BNWORD64) && PRODUCT_SCAN -/* - * Test code for product-scanning multiply. This seems to slow the C - * code down rather than speed it up. - * This does a multiply and Montgomery reduction together, using the - * same loops. The outer loop scans across the product, twice. - * The first pass computes the low half of the product and the - * Montgomery multipliers. These are stored in the product array, - * which contains no data as of yet. x and carry add up the columns - * and propagate carries forward. - * - * The second half multiplies the upper half, adding in the modulus - * times the Montgomery multipliers. The results of this multiply - * are stored. - */ -static void -lbnMontMul_32(BNWORD32 *prod, BNWORD32 const *num1, BNWORD32 const *num2, - BNWORD32 const *mod, unsigned len, BNWORD32 inv) -{ - BNWORD64 x, y; - BNWORD32 const *p1, *p2, *pm; - BNWORD32 *pp; - BNWORD32 t; - unsigned carry; - unsigned i, j; - - /* Special case of zero */ - if (!len) - return; - - /* - * This computes directly into the high half of prod, so just - * shift the pointer and consider prod only "len" elements long - * for the rest of the code. - */ - BIGLITTLE(prod -= len, prod += len); - - /* Pass 1 - compute Montgomery multipliers */ - /* First iteration can have certain simplifications. */ - x = (BNWORD64)BIGLITTLE(num1[-1] * num2[-1], num1[0] * num2[0]); - BIGLITTLE(prod[-1], prod[0]) = t = inv * (BNWORD32)x; - y = (BNWORD64)t * BIGLITTLE(mod[-1],mod[0]); - x += y; - /* Note: GCC 2.6.3 has a bug if you try to eliminate "carry" */ - carry = (x < y); - assert((BNWORD32)x == 0); - x = x >> 32 | (BNWORD64)carry << 32; - - for (i = 1; i < len; i++) { - carry = 0; - p1 = num1; - p2 = BIGLITTLE(num2-i-1,num2+i+1); - pp = prod; - pm = BIGLITTLE(mod-i-1,mod+i+1); - for (j = 0; j < i; j++) { - y = (BNWORD64)BIGLITTLE(*--p1 * *p2++, *p1++ * *--p2); - x += y; - carry += (x < y); - y = (BNWORD64)BIGLITTLE(*--pp * *pm++, *pp++ * *--pm); - x += y; - carry += (x < y); - } - y = (BNWORD64)BIGLITTLE(p1[-1] * p2[0], p1[0] * p2[-1]); - x += y; - carry += (x < y); - assert(BIGLITTLE(pp == prod-i, pp == prod+i)); - BIGLITTLE(pp[-1], pp[0]) = t = inv * (BNWORD32)x; - assert(BIGLITTLE(pm == mod-1, pm == mod+1)); - y = (BNWORD64)t * BIGLITTLE(pm[0],pm[-1]); - x += y; - carry += (x < y); - assert((BNWORD32)x == 0); - x = x >> 32 | (BNWORD64)carry << 32; - } - - /* Pass 2 - compute reduced product and store */ - for (i = 1; i < len; i++) { - carry = 0; - p1 = BIGLITTLE(num1-i,num1+i); - p2 = BIGLITTLE(num2-len,num2+len); - pm = BIGLITTLE(mod-i,mod+i); - pp = BIGLITTLE(prod-len,prod+len); - for (j = i; j < len; j++) { - y = (BNWORD64)BIGLITTLE(*--p1 * *p2++, *p1++ * *--p2); - x += y; - carry += (x < y); - y = (BNWORD64)BIGLITTLE(*--pm * *pp++, *pm++ * *--pp); - x += y; - carry += (x < y); - } - assert(BIGLITTLE(pm == mod-len, pm == mod+len)); - assert(BIGLITTLE(pp == prod-i, pp == prod+i)); - BIGLITTLE(pp[0],pp[-1]) = (BNWORD32)x; - x = (x >> 32) | (BNWORD64)carry << 32; - } - - /* Last round of second half, simplified. */ - BIGLITTLE(*(prod-len),*(prod+len-1)) = (BNWORD32)x; - carry = (x >> 32); - - while (carry) - carry -= lbnSubN_32(prod, mod, len); - while (lbnCmp_32(prod, mod, len) >= 0) - (void)lbnSubN_32(prod, mod, len); -} -/* Suppress later definition */ -#define lbnMontMul_32 lbnMontMul_32 -#endif - -#if !defined(lbnSquare_32) && defined(BNWORD64) && PRODUCT_SCAN -/* - * Trial code for product-scanning squaring. This seems to slow the C - * code down rather than speed it up. - */ -void -lbnSquare_32(BNWORD32 *prod, BNWORD32 const *num, unsigned len) -{ - BNWORD64 x, y, z; - BNWORD32 const *p1, *p2; - unsigned carry; - unsigned i, j; - - /* Special case of zero */ - if (!len) - return; - - /* Word 0 of product */ - x = (BNWORD64)BIGLITTLE(num[-1] * num[-1], num[0] * num[0]); - BIGLITTLE(*--prod, *prod++) = (BNWORD32)x; - x >>= 32; - - /* Words 1 through len-1 */ - for (i = 1; i < len; i++) { - carry = 0; - y = 0; - p1 = num; - p2 = BIGLITTLE(num-i-1,num+i+1); - for (j = 0; j < (i+1)/2; j++) { - BIG(z = (BNWORD64)*--p1 * *p2++;) - LITTLE(z = (BNWORD64)*p1++ * *--p2;) - y += z; - carry += (y < z); - } - y += z = y; - carry += carry + (y < z); - if ((i & 1) == 0) { - assert(BIGLITTLE(--p1 == p2, p1 == --p2)); - BIG(z = (BNWORD64)*p2 * *p2;) - LITTLE(z = (BNWORD64)*p1 * *p1;) - y += z; - carry += (y < z); - } - x += y; - carry += (x < y); - BIGLITTLE(*--prod,*prod++) = (BNWORD32)x; - x = (x >> 32) | (BNWORD64)carry << 32; - } - /* Words len through 2*len-2 */ - for (i = 1; i < len; i++) { - carry = 0; - y = 0; - p1 = BIGLITTLE(num-i,num+i); - p2 = BIGLITTLE(num-len,num+len); - for (j = 0; j < (len-i)/2; j++) { - BIG(z = (BNWORD64)*--p1 * *p2++;) - LITTLE(z = (BNWORD64)*p1++ * *--p2;) - y += z; - carry += (y < z); - } - y += z = y; - carry += carry + (y < z); - if ((len-i) & 1) { - assert(BIGLITTLE(--p1 == p2, p1 == --p2)); - BIG(z = (BNWORD64)*p2 * *p2;) - LITTLE(z = (BNWORD64)*p1 * *p1;) - y += z; - carry += (y < z); - } - x += y; - carry += (x < y); - BIGLITTLE(*--prod,*prod++) = (BNWORD32)x; - x = (x >> 32) | (BNWORD64)carry << 32; - } - - /* Word 2*len-1 */ - BIGLITTLE(*--prod,*prod) = (BNWORD32)x; -} -/* Suppress later definition */ -#define lbnSquare_32 lbnSquare_32 -#endif - -/* - * Square a number, using optimized squaring to reduce the number of - * primitive multiples that are executed. There may not be any - * overlap of the input and output. - * - * Technique: Consider the partial products in the multiplication - * of "abcde" by itself: - * - * a b c d e - * * a b c d e - * ================== - * ae be ce de ee - * ad bd cd dd de - * ac bc cc cd ce - * ab bb bc bd be - * aa ab ac ad ae - * - * Note that everything above the main diagonal: - * ae be ce de = (abcd) * e - * ad bd cd = (abc) * d - * ac bc = (ab) * c - * ab = (a) * b - * - * is a copy of everything below the main diagonal: - * de - * cd ce - * bc bd be - * ab ac ad ae - * - * Thus, the sum is 2 * (off the diagonal) + diagonal. - * - * This is accumulated beginning with the diagonal (which - * consist of the squares of the digits of the input), which is then - * divided by two, the off-diagonal added, and multiplied by two - * again. The low bit is simply a copy of the low bit of the - * input, so it doesn't need special care. - * - * TODO: Merge the shift by 1 with the squaring loop. - * TODO: Use Karatsuba. (a*W+b)^2 = a^2 * (W^2+W) + b^2 * (W+1) - (a-b)^2 * W. - */ -#ifndef lbnSquare_32 -void -lbnSquare_32(BNWORD32 *prod, BNWORD32 const *num, unsigned len) -{ - BNWORD32 t; - BNWORD32 *prodx = prod; /* Working copy of the argument */ - BNWORD32 const *numx = num; /* Working copy of the argument */ - unsigned lenx = len; /* Working copy of the argument */ - - if (!len) - return; - - /* First, store all the squares */ - while (lenx--) { -#ifdef mul32_ppmm - BNWORD32 ph, pl; - t = BIGLITTLE(*--numx,*numx++); - mul32_ppmm(ph,pl,t,t); - BIGLITTLE(*--prodx,*prodx++) = pl; - BIGLITTLE(*--prodx,*prodx++) = ph; -#elif defined(BNWORD64) /* use BNWORD64 */ - BNWORD64 p; - t = BIGLITTLE(*--numx,*numx++); - p = (BNWORD64)t * t; - BIGLITTLE(*--prodx,*prodx++) = (BNWORD32)p; - BIGLITTLE(*--prodx,*prodx++) = (BNWORD32)(p>>32); -#else /* Use lbnMulN1_32 */ - t = BIGLITTLE(numx[-1],*numx); - lbnMulN1_32(prodx, numx, 1, t); - BIGLITTLE(--numx,numx++); - BIGLITTLE(prodx -= 2, prodx += 2); -#endif - } - /* Then, shift right 1 bit */ - (void)lbnRshift_32(prod, 2*len, 1); - - /* Then, add in the off-diagonal sums */ - lenx = len; - numx = num; - prodx = prod; - while (--lenx) { - t = BIGLITTLE(*--numx,*numx++); - BIGLITTLE(--prodx,prodx++); - t = lbnMulAdd1_32(prodx, numx, lenx, t); - lbnAdd1_32(BIGLITTLE(prodx-lenx,prodx+lenx), lenx+1, t); - BIGLITTLE(--prodx,prodx++); - } - - /* Shift it back up */ - lbnDouble_32(prod, 2*len); - - /* And set the low bit appropriately */ - BIGLITTLE(prod[-1],prod[0]) |= BIGLITTLE(num[-1],num[0]) & 1; -} -#endif /* !lbnSquare_32 */ - -/* - * lbnNorm_32 - given a number, return a modified length such that the - * most significant digit is non-zero. Zero-length input is okay. - */ -#ifndef lbnNorm_32 -unsigned -lbnNorm_32(BNWORD32 const *num, unsigned len) -{ - BIGLITTLE(num -= len,num += len); - while (len && BIGLITTLE(*num++,*--num) == 0) - --len; - return len; -} -#endif /* lbnNorm_32 */ - -/* - * lbnBits_32 - return the number of significant bits in the array. - * It starts by normalizing the array. Zero-length input is okay. - * Then assuming there's anything to it, it fetches the high word, - * generates a bit length by multiplying the word length by 32, and - * subtracts off 32/2, 32/4, 32/8, ... bits if the high bits are clear. - */ -#ifndef lbnBits_32 -unsigned -lbnBits_32(BNWORD32 const *num, unsigned len) -{ - BNWORD32 t; - unsigned i; - - len = lbnNorm_32(num, len); - if (len) { - t = BIGLITTLE(*(num-len),*(num+(len-1))); - assert(t); - len *= 32; - i = 32/2; - do { - if (t >> i) - t >>= i; - else - len -= i; - } while ((i /= 2) != 0); - } - return len; -} -#endif /* lbnBits_32 */ - -/* - * If defined, use hand-rolled divide rather than compiler's native. - * If the machine doesn't do it in line, the manual code is probably - * faster, since it can assume normalization and the fact that the - * quotient will fit into 32 bits, which a general 64-bit divide - * in a compiler's run-time library can't do. - */ -#ifndef BN_SLOW_DIVIDE_64 -/* Assume that divisors of more than thirty-two bits are slow */ -#define BN_SLOW_DIVIDE_64 (64 > 0x20) -#endif - -/* - * Return (nh<<32|nl) % d, and place the quotient digit into *q. - * It is guaranteed that nh < d, and that d is normalized (with its high - * bit set). If we have a double-width type, it's easy. If not, ooh, - * yuk! - */ -#ifndef lbnDiv21_32 -#if defined(BNWORD64) && !BN_SLOW_DIVIDE_64 -BNWORD32 -lbnDiv21_32(BNWORD32 *q, BNWORD32 nh, BNWORD32 nl, BNWORD32 d) -{ - BNWORD64 n = (BNWORD64)nh << 32 | nl; - - /* Divisor must be normalized */ - assert(d >> (32-1) == 1); - - *q = n / d; - return n % d; -} -#else -/* - * This is where it gets ugly. - * - * Do the division in two halves, using Algorithm D from section 4.3.1 - * of Knuth. Note Theorem B from that section, that the quotient estimate - * is never more than the true quotient, and is never more than two - * too low. - * - * The mapping onto conventional long division is (everything a half word): - * _____________qh___ql_ - * dh dl ) nh.h nh.l nl.h nl.l - * - (qh * d) - * ----------- - * rrrr rrrr nl.l - * - (ql * d) - * ----------- - * rrrr rrrr - * - * The implicit 3/2-digit d*qh and d*ql subtractors are computed this way: - * First, estimate a q digit so that nh/dh works. Subtracting qh*dh from - * the (nh.h nh.l) list leaves a 1/2-word remainder r. Then compute the - * low part of the subtractor, qh * dl. This also needs to be subtracted - * from (nh.h nh.l nl.h) to get the final remainder. So we take the - * remainder, which is (nh.h nh.l) - qh*dl, shift it and add in nl.h, and - * try to subtract qh * dl from that. Since the remainder is 1/2-word - * long, shifting and adding nl.h results in a single word r. - * It is possible that the remainder we're working with, r, is less than - * the product qh * dl, if we estimated qh too high. The estimation - * technique can produce a qh that is too large (never too small), leading - * to r which is too small. In that case, decrement the digit qh, add - * shifted dh to r (to correct for that error), and subtract dl from the - * product we're comparing r with. That's the "correct" way to do it, but - * just adding dl to r instead of subtracting it from the product is - * equivalent and a lot simpler. You just have to watch out for overflow. - * - * The process is repeated with (rrrr rrrr nl.l) for the low digit of the - * quotient ql. - * - * The various uses of 32/2 for shifts are because of the note about - * automatic editing of this file at the very top of the file. - */ -#define highhalf(x) ( (x) >> 32/2 ) -#define lowhalf(x) ( (x) & (((BNWORD32)1 << 32/2)-1) ) -BNWORD32 -lbnDiv21_32(BNWORD32 *q, BNWORD32 nh, BNWORD32 nl, BNWORD32 d) -{ - BNWORD32 dh = highhalf(d), dl = lowhalf(d); - BNWORD32 qh, ql, prod, r; - - /* Divisor must be normalized */ - assert((d >> (32-1)) == 1); - - /* Do first half-word of division */ - qh = nh / dh; - r = nh % dh; - prod = qh * dl; - - /* - * Add next half-word of numerator to remainder and correct. - * qh may be up to two too large. - */ - r = (r << (32/2)) | highhalf(nl); - if (r < prod) { - --qh; r += d; - if (r >= d && r < prod) { - --qh; r += d; - } - } - r -= prod; - - /* Do second half-word of division */ - ql = r / dh; - r = r % dh; - prod = ql * dl; - - r = (r << (32/2)) | lowhalf(nl); - if (r < prod) { - --ql; r += d; - if (r >= d && r < prod) { - --ql; r += d; - } - } - r -= prod; - - *q = (qh << (32/2)) | ql; - - return r; -} -#endif -#endif /* lbnDiv21_32 */ - - -/* - * In the division functions, the dividend and divisor are referred to - * as "n" and "d", which stand for "numerator" and "denominator". - * - * The quotient is (nlen-dlen+1) digits long. It may be overlapped with - * the high (nlen-dlen) words of the dividend, but one extra word is needed - * on top to hold the top word. - */ - -/* - * Divide an n-word number by a 1-word number, storing the remainder - * and n-1 words of the n-word quotient. The high word is returned. - * It IS legal for rem to point to the same address as n, and for - * q to point one word higher. - * - * TODO: If BN_SLOW_DIVIDE_64, add a divnhalf_32 which uses 32-bit - * dividends if the divisor is half that long. - * TODO: Shift the dividend on the fly to avoid the last division and - * instead have a remainder that needs shifting. - * TODO: Use reciprocals rather than dividing. - */ -#ifndef lbnDiv1_32 -BNWORD32 -lbnDiv1_32(BNWORD32 *q, BNWORD32 *rem, BNWORD32 const *n, unsigned len, - BNWORD32 d) -{ - unsigned shift; - unsigned xlen; - BNWORD32 r; - BNWORD32 qhigh; - - assert(len > 0); - assert(d); - - if (len == 1) { - r = *n; - *rem = r%d; - return r/d; - } - - shift = 0; - r = d; - xlen = 32/2; - do { - if (r >> xlen) - r >>= xlen; - else - shift += xlen; - } while ((xlen /= 2) != 0); - assert((d >> (32-1-shift)) == 1); - d <<= shift; - - BIGLITTLE(q -= len-1,q += len-1); - BIGLITTLE(n -= len,n += len); - - r = BIGLITTLE(*n++,*--n); - if (r < d) { - qhigh = 0; - } else { - qhigh = r/d; - r %= d; - } - - xlen = len; - while (--xlen) - r = lbnDiv21_32(BIGLITTLE(q++,--q), r, BIGLITTLE(*n++,*--n), d); - - /* - * Final correction for shift - shift the quotient up "shift" - * bits, and merge in the extra bits of quotient. Then reduce - * the final remainder mod the real d. - */ - if (shift) { - d >>= shift; - qhigh = (qhigh << shift) | lbnLshift_32(q, len-1, shift); - BIGLITTLE(q[-1],*q) |= r/d; - r %= d; - } - *rem = r; - - return qhigh; -} -#endif - -/* - * This function performs a "quick" modulus of a number with a divisor - * d which is guaranteed to be at most sixteen bits, i.e. less than 65536. - * This applies regardless of the word size the library is compiled with. - * - * This function is important to prime generation, for sieving. - */ -#ifndef lbnModQ_32 -/* If there's a custom lbnMod21_32, no normalization needed */ -#ifdef lbnMod21_32 -unsigned -lbnModQ_32(BNWORD32 const *n, unsigned len, unsigned d) -{ - unsigned i, shift; - BNWORD32 r; - - assert(len > 0); - - BIGLITTLE(n -= len,n += len); - - /* Try using a compare to avoid the first divide */ - r = BIGLITTLE(*n++,*--n); - if (r >= d) - r %= d; - while (--len) - r = lbnMod21_32(r, BIGLITTLE(*n++,*--n), d); - - return r; -} -#elif defined(BNWORD64) && !BN_SLOW_DIVIDE_64 -unsigned -lbnModQ_32(BNWORD32 const *n, unsigned len, unsigned d) -{ - BNWORD32 r; - - if (!--len) - return BIGLITTLE(n[-1],n[0]) % d; - - BIGLITTLE(n -= len,n += len); - r = BIGLITTLE(n[-1],n[0]); - - do { - r = (BNWORD32)((((BNWORD64)r<<32) | BIGLITTLE(*n++,*--n)) % d); - } while (--len); - - return r; -} -#elif 32 >= 0x20 -/* - * If the single word size can hold 65535*65536, then this function - * is avilable. - */ -#ifndef highhalf -#define highhalf(x) ( (x) >> 32/2 ) -#define lowhalf(x) ( (x) & ((1 << 32/2)-1) ) -#endif -unsigned -lbnModQ_32(BNWORD32 const *n, unsigned len, unsigned d) -{ - BNWORD32 r, x; - - BIGLITTLE(n -= len,n += len); - - r = BIGLITTLE(*n++,*--n); - while (--len) { - x = BIGLITTLE(*n++,*--n); - r = (r%d << 32/2) | highhalf(x); - r = (r%d << 32/2) | lowhalf(x); - } - - return r%d; -} -#else -/* Default case - use lbnDiv21_32 */ -unsigned -lbnModQ_32(BNWORD32 const *n, unsigned len, unsigned d) -{ - unsigned i, shift; - BNWORD32 r; - BNWORD32 q; - - assert(len > 0); - - shift = 0; - r = d; - i = 32; - while (i /= 2) { - if (r >> i) - r >>= i; - else - shift += i; - } - assert(d >> (32-1-shift) == 1); - d <<= shift; - - BIGLITTLE(n -= len,n += len); - - r = BIGLITTLE(*n++,*--n); - if (r >= d) - r %= d; - - while (--len) - r = lbnDiv21_32(&q, r, BIGLITTLE(*n++,*--n), d); - - /* - * Final correction for shift - shift the quotient up "shift" - * bits, and merge in the extra bits of quotient. Then reduce - * the final remainder mod the real d. - */ - if (shift) - r %= d >> shift; - - return r; -} -#endif -#endif /* lbnModQ_32 */ - -/* - * Reduce n mod d and return the quotient. That is, find: - * q = n / d; - * n = n % d; - * d is altered during the execution of this subroutine by normalizing it. - * It must already have its most significant word non-zero; it is shifted - * so its most significant bit is non-zero. - * - * The quotient q is nlen-dlen+1 words long. To make it possible to - * overlap the quptient with the input (you can store it in the high dlen - * words), the high word of the quotient is *not* stored, but is returned. - * (If all you want is the remainder, you don't care about it, anyway.) - * - * This uses algorithm D from Knuth (4.3.1), except that we do binary - * (shift) normalization of the divisor. WARNING: This is hairy! - * - * This function is used for some modular reduction, but it is not used in - * the modular exponentiation loops; they use Montgomery form and the - * corresponding, more efficient, Montgomery reduction. This code - * is needed for the conversion to Montgomery form, however, so it - * has to be here and it might as well be reasonably efficient. - * - * The overall operation is as follows ("top" and "up" refer to the - * most significant end of the number; "bottom" and "down", the least): - * - * - Shift the divisor up until the most significant bit is set. - * - Shift the dividend up the same amount. This will produce the - * correct quotient, and the remainder can be recovered by shifting - * it back down the same number of bits. This may produce an overflow - * word, but the word is always strictly less than the most significant - * divisor word. - * - Estimate the first quotient digit qhat: - * - First take the top two words (one of which is the overflow) of the - * dividend and divide by the top word of the divisor: - * qhat = (nh,nm)/dh. This qhat is >= the correct quotient digit - * and, since dh is normalized, it is at most two over. - * - Second, correct by comparing the top three words. If - * (dh,dl) * qhat > (nh,nm,ml), decrease qhat and try again. - * The second iteration can be simpler because there can't be a third. - * The computation can be simplified by subtracting dh*qhat from - * both sides, suitably shifted. This reduces the left side to - * dl*qhat. On the right, (nh,nm)-dh*qhat is simply the - * remainder r from (nh,nm)%dh, so the right is (r,nl). - * This produces qhat that is almost always correct and at - * most (prob ~ 2/2^32) one too high. - * - Subtract qhat times the divisor (suitably shifted) from the dividend. - * If there is a borrow, qhat was wrong, so decrement it - * and add the divisor back in (once). - * - Store the final quotient digit qhat in the quotient array q. - * - * Repeat the quotient digit computation for successive digits of the - * quotient until the whole quotient has been computed. Then shift the - * divisor and the remainder down to correct for the normalization. - * - * TODO: Special case 2-word divisors. - * TODO: Use reciprocals rather than dividing. - */ -#ifndef divn_32 -BNWORD32 -lbnDiv_32(BNWORD32 *q, BNWORD32 *n, unsigned nlen, BNWORD32 *d, unsigned dlen) -{ - BNWORD32 nh,nm,nl; /* Top three words of the dividend */ - BNWORD32 dh,dl; /* Top two words of the divisor */ - BNWORD32 qhat; /* Extimate of quotient word */ - BNWORD32 r; /* Remainder from quotient estimate division */ - BNWORD32 qhigh; /* High word of quotient */ - unsigned i; /* Temp */ - unsigned shift; /* Bits shifted by normalization */ - unsigned qlen = nlen-dlen; /* Size of quotient (less 1) */ -#ifdef mul32_ppmm - BNWORD32 t32; -#elif defined(BNWORD64) - BNWORD64 t64; -#else /* use lbnMulN1_32 */ - BNWORD32 t2[2]; -#define t2high BIGLITTLE(t2[0],t2[1]) -#define t2low BIGLITTLE(t2[1],t2[0]) -#endif - - assert(dlen); - assert(nlen >= dlen); - - /* - * Special cases for short divisors. The general case uses the - * top top 2 digits of the divisor (d) to estimate a quotient digit, - * so it breaks if there are fewer digits available. Thus, we need - * special cases for a divisor of length 1. A divisor of length - * 2 can have a *lot* of administrivia overhead removed removed, - * so it's probably worth special-casing that case, too. - */ - if (dlen == 1) - return lbnDiv1_32(q, BIGLITTLE(n-1,n), n, nlen, - BIGLITTLE(d[-1],d[0])); - -#if 0 - /* - * @@@ This is not yet written... The general loop will do, - * albeit less efficiently - */ - if (dlen == 2) { - /* - * divisor two digits long: - * use the 3/2 technique from Knuth, but we know - * it's exact. - */ - dh = BIGLITTLE(d[-1],d[0]); - dl = BIGLITTLE(d[-2],d[1]); - shift = 0; - if ((sh & ((BNWORD32)1 << 32-1-shift)) == 0) { - do { - shift++; - } while (dh & (BNWORD32)1<<32-1-shift) == 0); - dh = dh << shift | dl >> (32-shift); - dl <<= shift; - - - } - - - for (shift = 0; (dh & (BNWORD32)1 << 32-1-shift)) == 0; shift++) - ; - if (shift) { - } - dh = dh << shift | dl >> (32-shift); - shift = 0; - while (dh - } -#endif - - dh = BIGLITTLE(*(d-dlen),*(d+(dlen-1))); - assert(dh); - - /* Normalize the divisor */ - shift = 0; - r = dh; - i = 32/2; - do { - if (r >> i) - r >>= i; - else - shift += i; - } while ((i /= 2) != 0); - - nh = 0; - if (shift) { - lbnLshift_32(d, dlen, shift); - dh = BIGLITTLE(*(d-dlen),*(d+(dlen-1))); - nh = lbnLshift_32(n, nlen, shift); - } - - /* Assert that dh is now normalized */ - assert(dh >> (32-1)); - - /* Also get the second-most significant word of the divisor */ - dl = BIGLITTLE(*(d-(dlen-1)),*(d+(dlen-2))); - - /* - * Adjust pointers: n to point to least significant end of first - * first subtract, and q to one the most-significant end of the - * quotient array. - */ - BIGLITTLE(n -= qlen,n += qlen); - BIGLITTLE(q -= qlen,q += qlen); - - /* Fetch the most significant stored word of the dividend */ - nm = BIGLITTLE(*(n-dlen),*(n+(dlen-1))); - - /* - * Compute the first digit of the quotient, based on the - * first two words of the dividend (the most significant of which - * is the overflow word h). - */ - if (nh) { - assert(nh < dh); - r = lbnDiv21_32(&qhat, nh, nm, dh); - } else if (nm >= dh) { - qhat = nm/dh; - r = nm % dh; - } else { /* Quotient is zero */ - qhigh = 0; - goto divloop; - } - - /* Now get the third most significant word of the dividend */ - nl = BIGLITTLE(*(n-(dlen-1)),*(n+(dlen-2))); - - /* - * Correct qhat, the estimate of quotient digit. - * qhat can only be high, and at most two words high, - * so the loop can be unrolled and abbreviated. - */ -#ifdef mul32_ppmm - mul32_ppmm(nm, t32, qhat, dl); - if (nm > r || (nm == r && t32 > nl)) { - /* Decrement qhat and adjust comparison parameters */ - qhat--; - if ((r += dh) >= dh) { - nm -= (t32 < dl); - t32 -= dl; - if (nm > r || (nm == r && t32 > nl)) - qhat--; - } - } -#elif defined(BNWORD64) - t64 = (BNWORD64)qhat * dl; - if (t64 > ((BNWORD64)r << 32) + nl) { - /* Decrement qhat and adjust comparison parameters */ - qhat--; - if ((r += dh) > dh) { - t64 -= dl; - if (t64 > ((BNWORD64)r << 32) + nl) - qhat--; - } - } -#else /* Use lbnMulN1_32 */ - lbnMulN1_32(BIGLITTLE(t2+2,t2), &dl, 1, qhat); - if (t2high > r || (t2high == r && t2low > nl)) { - /* Decrement qhat and adjust comparison parameters */ - qhat--; - if ((r += dh) >= dh) { - t2high -= (t2low < dl); - t2low -= dl; - if (t2high > r || (t2high == r && t2low > nl)) - qhat--; - } - } -#endif - - /* Do the multiply and subtract */ - r = lbnMulSub1_32(n, d, dlen, qhat); - /* If there was a borrow, add back once. */ - if (r > nh) { /* Borrow? */ - (void)lbnAddN_32(n, d, dlen); - qhat--; - } - - /* Remember the first quotient digit. */ - qhigh = qhat; - - /* Now, the main division loop: */ -divloop: - while (qlen--) { - - /* Advance n */ - nh = BIGLITTLE(*(n-dlen),*(n+(dlen-1))); - BIGLITTLE(++n,--n); - nm = BIGLITTLE(*(n-dlen),*(n+(dlen-1))); - - if (nh == dh) { - qhat = ~(BNWORD32)0; - /* Optimized computation of r = (nh,nm) - qhat * dh */ - r = nh + nm; - if (r < nh) - goto subtract; - } else { - assert(nh < dh); - r = lbnDiv21_32(&qhat, nh, nm, dh); - } - - nl = BIGLITTLE(*(n-(dlen-1)),*(n+(dlen-2))); -#ifdef mul32_ppmm - mul32_ppmm(nm, t32, qhat, dl); - if (nm > r || (nm == r && t32 > nl)) { - /* Decrement qhat and adjust comparison parameters */ - qhat--; - if ((r += dh) >= dh) { - nm -= (t32 < dl); - t32 -= dl; - if (nm > r || (nm == r && t32 > nl)) - qhat--; - } - } -#elif defined(BNWORD64) - t64 = (BNWORD64)qhat * dl; - if (t64 > ((BNWORD64)r<<32) + nl) { - /* Decrement qhat and adjust comparison parameters */ - qhat--; - if ((r += dh) >= dh) { - t64 -= dl; - if (t64 > ((BNWORD64)r << 32) + nl) - qhat--; - } - } -#else /* Use lbnMulN1_32 */ - lbnMulN1_32(BIGLITTLE(t2+2,t2), &dl, 1, qhat); - if (t2high > r || (t2high == r && t2low > nl)) { - /* Decrement qhat and adjust comparison parameters */ - qhat--; - if ((r += dh) >= dh) { - t2high -= (t2low < dl); - t2low -= dl; - if (t2high > r || (t2high == r && t2low > nl)) - qhat--; - } - } -#endif - - /* - * As a point of interest, note that it is not worth checking - * for qhat of 0 or 1 and installing special-case code. These - * occur with probability 2^-32, so spending 1 cycle to check - * for them is only worth it if we save more than 2^15 cycles, - * and a multiply-and-subtract for numbers in the 1024-bit - * range just doesn't take that long. - */ -subtract: - /* - * n points to the least significant end of the substring - * of n to be subtracted from. qhat is either exact or - * one too large. If the subtract gets a borrow, it was - * one too large and the divisor is added back in. It's - * a dlen+1 word add which is guaranteed to produce a - * carry out, so it can be done very simply. - */ - r = lbnMulSub1_32(n, d, dlen, qhat); - if (r > nh) { /* Borrow? */ - (void)lbnAddN_32(n, d, dlen); - qhat--; - } - /* Store the quotient digit */ - BIGLITTLE(*q++,*--q) = qhat; - } - /* Tah dah! */ - - if (shift) { - lbnRshift_32(d, dlen, shift); - lbnRshift_32(n, dlen, shift); - } - - return qhigh; -} -#endif - -/* - * Find the negative multiplicative inverse of x (x must be odd!) modulo 2^32. - * - * This just performs Newton's iteration until it gets the - * inverse. The initial estimate is always correct to 3 bits, and - * sometimes 4. The number of valid bits doubles each iteration. - * (To prove it, assume x * y == 1 (mod 2^n), and introduce a variable - * for the error mod 2^2n. x * y == 1 + k*2^n (mod 2^2n) and follow - * the iteration through.) - */ -#ifndef lbnMontInv1_32 -BNWORD32 -lbnMontInv1_32(BNWORD32 const x) -{ - BNWORD32 y = x, z; - - assert(x & 1); - - while ((z = x*y) != 1) - y *= 2 - z; - return -y; -} -#endif /* !lbnMontInv1_32 */ - -#if defined(BNWORD64) && PRODUCT_SCAN -/* - * Test code for product-scanning Montgomery reduction. - * This seems to slow the C code down rather than speed it up. - * - * The first loop computes the Montgomery multipliers, storing them over - * the low half of the number n. - * - * The second half multiplies the upper half, adding in the modulus - * times the Montgomery multipliers. The results of this multiply - * are stored. - */ -void -lbnMontReduce_32(BNWORD32 *n, BNWORD32 const *mod, unsigned mlen, BNWORD32 inv) -{ - BNWORD64 x, y; - BNWORD32 const *pm; - BNWORD32 *pn; - BNWORD32 t; - unsigned carry; - unsigned i, j; - - /* Special case of zero */ - if (!mlen) - return; - - /* Pass 1 - compute Montgomery multipliers */ - /* First iteration can have certain simplifications. */ - t = BIGLITTLE(n[-1],n[0]); - x = t; - t *= inv; - BIGLITTLE(n[-1], n[0]) = t; - x += (BNWORD64)t * BIGLITTLE(mod[-1],mod[0]); /* Can't overflow */ - assert((BNWORD32)x == 0); - x = x >> 32; - - for (i = 1; i < mlen; i++) { - carry = 0; - pn = n; - pm = BIGLITTLE(mod-i-1,mod+i+1); - for (j = 0; j < i; j++) { - y = (BNWORD64)BIGLITTLE(*--pn * *pm++, *pn++ * *--pm); - x += y; - carry += (x < y); - } - assert(BIGLITTLE(pn == n-i, pn == n+i)); - y = t = BIGLITTLE(pn[-1], pn[0]); - x += y; - carry += (x < y); - BIGLITTLE(pn[-1], pn[0]) = t = inv * (BNWORD32)x; - assert(BIGLITTLE(pm == mod-1, pm == mod+1)); - y = (BNWORD64)t * BIGLITTLE(pm[0],pm[-1]); - x += y; - carry += (x < y); - assert((BNWORD32)x == 0); - x = x >> 32 | (BNWORD64)carry << 32; - } - - BIGLITTLE(n -= mlen, n += mlen); - - /* Pass 2 - compute upper words and add to n */ - for (i = 1; i < mlen; i++) { - carry = 0; - pm = BIGLITTLE(mod-i,mod+i); - pn = n; - for (j = i; j < mlen; j++) { - y = (BNWORD64)BIGLITTLE(*--pm * *pn++, *pm++ * *--pn); - x += y; - carry += (x < y); - } - assert(BIGLITTLE(pm == mod-mlen, pm == mod+mlen)); - assert(BIGLITTLE(pn == n+mlen-i, pn == n-mlen+i)); - y = t = BIGLITTLE(*(n-i),*(n+i-1)); - x += y; - carry += (x < y); - BIGLITTLE(*(n-i),*(n+i-1)) = (BNWORD32)x; - x = (x >> 32) | (BNWORD64)carry << 32; - } - - /* Last round of second half, simplified. */ - t = BIGLITTLE(*(n-mlen),*(n+mlen-1)); - x += t; - BIGLITTLE(*(n-mlen),*(n+mlen-1)) = (BNWORD32)x; - carry = (unsigned)(x >> 32); - - while (carry) - carry -= lbnSubN_32(n, mod, mlen); - while (lbnCmp_32(n, mod, mlen) >= 0) - (void)lbnSubN_32(n, mod, mlen); -} -#define lbnMontReduce_32 lbnMontReduce_32 -#endif - -/* - * Montgomery reduce n, modulo mod. This reduces modulo mod and divides by - * 2^(32*mlen). Returns the result in the *top* mlen words of the argument n. - * This is ready for another multiplication using lbnMul_32. - * - * Montgomery representation is a very useful way to encode numbers when - * you're doing lots of modular reduction. What you do is pick a multiplier - * R which is relatively prime to the modulus and very easy to divide by. - * Since the modulus is odd, R is closen as a power of 2, so the division - * is a shift. In fact, it's a shift of an integral number of words, - * so the shift can be implicit - just drop the low-order words. - * - * Now, choose R *larger* than the modulus m, 2^(32*mlen). Then convert - * all numbers a, b, etc. to Montgomery form M(a), M(b), etc using the - * relationship M(a) = a*R mod m, M(b) = b*R mod m, etc. Note that: - * - The Montgomery form of a number depends on the modulus m. - * A fixed modulus m is assumed throughout this discussion. - * - Since R is relaitvely prime to m, multiplication by R is invertible; - * no information about the numbers is lost, they're just scrambled. - * - Adding (and subtracting) numbers in this form works just as usual. - * M(a+b) = (a+b)*R mod m = (a*R + b*R) mod m = (M(a) + M(b)) mod m - * - Multiplying numbers in this form produces a*b*R*R. The problem - * is to divide out the excess factor of R, modulo m as well as to - * reduce to the given length mlen. It turns out that this can be - * done *faster* than a normal divide, which is where the speedup - * in Montgomery division comes from. - * - * Normal reduction chooses a most-significant quotient digit q and then - * subtracts q*m from the number to be reduced. Choosing q is tricky - * and involved (just look at lbnDiv_32 to see!) and is usually - * imperfect, requiring a check for correction after the subtraction. - * - * Montgomery reduction *adds* a multiple of m to the *low-order* part - * of the number to be reduced. This multiple is chosen to make the - * low-order part of the number come out to zero. This can be done - * with no trickery or error using a precomputed inverse of the modulus. - * In this code, the "part" is one word, but any width can be used. - * - * Repeating this step sufficiently often results in a value which - * is a multiple of R (a power of two, remember) but is still (since - * the additions were to the low-order part and thus did not increase - * the value of the number being reduced very much) still not much - * larger than m*R. Then implicitly divide by R and subtract off - * m until the result is in the correct range. - * - * Since the low-order part being cancelled is less than R, the - * multiple of m added must have a multiplier which is at most R-1. - * Assuming that the input is at most m*R-1, the final number is - * at most m*(2*R-1)-1 = 2*m*R - m - 1, so subtracting m once from - * the high-order part, equivalent to subtracting m*R from the - * while number, produces a result which is at most m*R - m - 1, - * which divided by R is at most m-1. - * - * To convert *to* Montgomery form, you need a regular remainder - * routine, although you can just compute R*R (mod m) and do the - * conversion using Montgomery multiplication. To convert *from* - * Montgomery form, just Montgomery reduce the number to - * remove the extra factor of R. - * - * TODO: Change to a full inverse and use Karatsuba's multiplication - * rather than this word-at-a-time. - */ -#ifndef lbnMontReduce_32 -void -lbnMontReduce_32(BNWORD32 *n, BNWORD32 const *mod, unsigned const mlen, - BNWORD32 inv) -{ - BNWORD32 t; - BNWORD32 c = 0; - unsigned len = mlen; - - /* inv must be the negative inverse of mod's least significant word */ - assert((BNWORD32)(inv * BIGLITTLE(mod[-1],mod[0])) == (BNWORD32)-1); - - assert(len); - - do { - t = lbnMulAdd1_32(n, mod, mlen, inv * BIGLITTLE(n[-1],n[0])); - c += lbnAdd1_32(BIGLITTLE(n-mlen,n+mlen), len, t); - BIGLITTLE(--n,++n); - } while (--len); - - /* - * All that adding can cause an overflow past the modulus size, - * but it's unusual, and never by much, so a subtraction loop - * is the right way to deal with it. - * This subtraction happens infrequently - I've only ever seen it - * invoked once per reduction, and then just under 22.5% of the time. - */ - while (c) - c -= lbnSubN_32(n, mod, mlen); - while (lbnCmp_32(n, mod, mlen) >= 0) - (void)lbnSubN_32(n, mod, mlen); -} -#endif /* !lbnMontReduce_32 */ - -/* - * A couple of helpers that you might want to implement atomically - * in asm sometime. - */ -#ifndef lbnMontMul_32 -/* - * Multiply "num1" by "num2", modulo "mod", all of length "len", and - * place the result in the high half of "prod". "inv" is the inverse - * of the least-significant word of the modulus, modulo 2^32. - * This uses numbers in Montgomery form. Reduce using "len" and "inv". - * - * This is implemented as a macro to win on compilers that don't do - * inlining, since it's so trivial. - */ -#define lbnMontMul_32(prod, n1, n2, mod, len, inv) \ - (lbnMulX_32(prod, n1, n2, len), lbnMontReduce_32(prod, mod, len, inv)) -#endif /* !lbnMontMul_32 */ - -#ifndef lbnMontSquare_32 -/* - * Square "num", modulo "mod", both of length "len", and place the result - * in the high half of "prod". "inv" is the inverse of the least-significant - * word of the modulus, modulo 2^32. - * This uses numbers in Montgomery form. Reduce using "len" and "inv". - * - * This is implemented as a macro to win on compilers that don't do - * inlining, since it's so trivial. - */ -#define lbnMontSquare_32(prod, n, mod, len, inv) \ - (lbnSquare_32(prod, n, len), lbnMontReduce_32(prod, mod, len, inv)) - -#endif /* !lbnMontSquare_32 */ - -/* - * Convert a number to Montgomery form - requires mlen + nlen words - * of memory in "n". - */ -void -lbnToMont_32(BNWORD32 *n, unsigned nlen, BNWORD32 *mod, unsigned mlen) -{ - /* Move n up "mlen" words */ - lbnCopy_32(BIGLITTLE(n-mlen,n+mlen), n, nlen); - lbnZero_32(n, mlen); - /* Do the division - dump the quotient in the high-order words */ - (void)lbnDiv_32(BIGLITTLE(n-mlen,n+mlen), n, mlen+nlen, mod, mlen); -} - -/* - * Convert from Montgomery form. Montgomery reduction is all that is - * needed. - */ -void -lbnFromMont_32(BNWORD32 *n, BNWORD32 *mod, unsigned len) -{ - /* Zero the high words of n */ - lbnZero_32(BIGLITTLE(n-len,n+len), len); - lbnMontReduce_32(n, mod, len, lbnMontInv1_32(BIGLITTLE(mod[-1],mod[0]))); - /* Move n down len words */ - lbnCopy_32(n, BIGLITTLE(n-len,n+len), len); -} - -/* - * The windowed exponentiation algorithm, precomputes a table of odd - * powers of n up to 2^k. It takes 2^(k-1)-1 multiplies to compute - * the table, and (e-1)/(k+1) multiplies (on average) to perform the - * exponentiation. To minimize the sum, k must vary with e. - * The optimal window sizes vary with the exponent length. Here are - * some selected values and the boundary cases. - * (An underscore _ has been inserted into some of the numbers to ensure - * that magic strings like 32 do not appear in this table. It should be - * ignored.) - * - * At e = 1 bits, k=1 (0.000000) is best. - * At e = 2 bits, k=1 (0.500000) is best. - * At e = 4 bits, k=1 (1.500000) is best. - * At e = 8 bits, k=2 (3.333333) < k=1 (3.500000) - * At e = 1_6 bits, k=2 (6.000000) is best. - * At e = 26 bits, k=3 (9.250000) < k=2 (9.333333) - * At e = 3_2 bits, k=3 (10.750000) is best. - * At e = 6_4 bits, k=3 (18.750000) is best. - * At e = 82 bits, k=4 (23.200000) < k=3 (23.250000) - * At e = 128 bits, k=4 (3_2.400000) is best. - * At e = 242 bits, k=5 (55.1_66667) < k=4 (55.200000) - * At e = 256 bits, k=5 (57.500000) is best. - * At e = 512 bits, k=5 (100.1_66667) is best. - * At e = 674 bits, k=6 (127.142857) < k=5 (127.1_66667) - * At e = 1024 bits, k=6 (177.142857) is best. - * At e = 1794 bits, k=7 (287.125000) < k=6 (287.142857) - * At e = 2048 bits, k=7 (318.875000) is best. - * At e = 4096 bits, k=7 (574.875000) is best. - * - * The numbers in parentheses are the expected number of multiplications - * needed to do the computation. The normal russian-peasant modular - * exponentiation technique always uses (e-1)/2. For exponents as - * small as 192 bits (below the range of current factoring algorithms), - * half of the multiplies are eliminated, 45.2 as opposed to the naive - * 95.5. Counting the 191 squarings as 3/4 a multiply each (squaring - * proper is just over half of multiplying, but the Montgomery - * reduction in each case is also a multiply), that's 143.25 - * multiplies, for totals of 188.45 vs. 238.75 - a 21% savings. - * For larger exponents (like 512 bits), it's 483.92 vs. 639.25, a - * 24.3% savings. It asymptotically approaches 25%. - * - * Given that exponents for which k>7 are useful are uncommon, - * a fixed size table for k <= 7 is used for simplicity. - * k = 8 is uzeful at 4610 bits, k = 9 at 11522 bits. - * - * The basic number of squarings needed is e-1, although a k-bit - * window (for k > 1) can save, on average, k-2 of those, too. - * That savings currently isn't counted here. It would drive the - * crossover points slightly lower. - * (Actually, this win is also reduced in the DoubleExpMod case, - * meaning we'd have to split the tables. Except for that, the - * multiplies by powers of the two bases are independent, so - * the same logic applies to each as the single case.) - * - * Table entry i is the largest number of bits in an exponent to - * process with a window size of i+1. So the window never goes above 7 - * bits, requiring 2^(7-1) = 0x40 precomputed multiples. - */ -#define BNEXPMOD_MAX_WINDOW 7 -static unsigned const bnExpModThreshTable[BNEXPMOD_MAX_WINDOW] = { - 7, 25, 81, 241, 673, 1793, (unsigned)-1 -}; - -/* - * Perform modular exponentiation, as fast as possible! This uses - * Montgomery reduction, optimized squaring, and windowed exponentiation. - * The modulus "mod" MUST be odd! - * - * This returns 0 on success, -1 on out of memory. - * - * The window algorithm: - * The idea is to keep a running product of b1 = n^(high-order bits of exp), - * and then keep appending exponent bits to it. The following patterns - * apply to a 3-bit window (k = 3): - * To append 0: square - * To append 1: square, multiply by n^1 - * To append 10: square, multiply by n^1, square - * To append 11: square, square, multiply by n^3 - * To append 100: square, multiply by n^1, square, square - * To append 101: square, square, square, multiply by n^5 - * To append 110: square, square, multiply by n^3, square - * To append 111: square, square, square, multiply by n^7 - * - * Since each pattern involves only one multiply, the longer the pattern - * the better, except that a 0 (no multiplies) can be appended directly. - * We precompute a table of odd powers of n, up to 2^k, and can then - * multiply k bits of exponent at a time. Actually, assuming random - * exponents, there is on average one zero bit between needs to - * multiply (1/2 of the time there's none, 1/4 of the time there's 1, - * 1/8 of the time, there's 2, 1/32 of the time, there's 3, etc.), so - * you have to do one multiply per k+1 bits of exponent. - * - * The loop walks down the exponent, squaring the result buffer as - * it goes. There is a wbits+1 bit lookahead buffer, buf, that is - * filled with the upcoming exponent bits. (What is read after the - * end of the exponent is unimportant, but it is filled with zero here.) - * When the most-significant bit of this buffer becomes set, i.e. - * (buf & tblmask) != 0, we have to decide what pattern to multiply - * by, and when to do it. We decide, remember to do it in future - * after a suitable number of squarings have passed (e.g. a pattern - * of "100" in the buffer requires that we multiply by n^1 immediately; - * a pattern of "110" calls for multiplying by n^3 after one more - * squaring), clear the buffer, and continue. - * - * When we start, there is one more optimization: the result buffer - * is implcitly one, so squaring it or multiplying by it can be - * optimized away. Further, if we start with a pattern like "100" - * in the lookahead window, rather than placing n into the buffer - * and then starting to square it, we have already computed n^2 - * to compute the odd-powers table, so we can place that into - * the buffer and save a squaring. - * - * This means that if you have a k-bit window, to compute n^z, - * where z is the high k bits of the exponent, 1/2 of the time - * it requires no squarings. 1/4 of the time, it requires 1 - * squaring, ... 1/2^(k-1) of the time, it reqires k-2 squarings. - * And the remaining 1/2^(k-1) of the time, the top k bits are a - * 1 followed by k-1 0 bits, so it again only requires k-2 - * squarings, not k-1. The average of these is 1. Add that - * to the one squaring we have to do to compute the table, - * and you'll see that a k-bit window saves k-2 squarings - * as well as reducing the multiplies. (It actually doesn't - * hurt in the case k = 1, either.) - * - * n must have mlen words allocated. Although fewer may be in use - * when n is passed in, all are in use on exit. - */ -int -lbnExpMod_32(BNWORD32 *result, BNWORD32 const *n, unsigned nlen, - BNWORD32 const *e, unsigned elen, BNWORD32 *mod, unsigned mlen) -{ - BNWORD32 *table[1 << (BNEXPMOD_MAX_WINDOW-1)]; - /* Table of odd powers of n */ - unsigned ebits; /* Exponent bits */ - unsigned wbits; /* Window size */ - unsigned tblmask; /* Mask of exponentiation window */ - BNWORD32 bitpos; /* Mask of current look-ahead bit */ - unsigned buf; /* Buffer of exponent bits */ - unsigned multpos; /* Where to do pending multiply */ - BNWORD32 const *mult; /* What to multiply by */ - unsigned i; /* Loop counter */ - int isone; /* Flag: accum. is implicitly one */ - BNWORD32 *a, *b; /* Working buffers/accumulators */ - BNWORD32 *t; /* Pointer into the working buffers */ - BNWORD32 inv; /* mod^-1 modulo 2^32 */ - - assert(mlen); - assert(nlen <= mlen); - - /* First, a couple of trivial cases. */ - elen = lbnNorm_32(e, elen); - if (!elen) { - /* x ^ 0 == 1 */ - lbnZero_32(result, mlen); - BIGLITTLE(result[-1],result[0]) = 1; - return 0; - } - ebits = lbnBits_32(e, elen); - if (ebits == 1) { - /* x ^ 1 == x */ - if (n != result) - lbnCopy_32(result, n, nlen); - if (mlen > nlen) - lbnZero_32(BIGLITTLE(result-nlen,result+nlen), - mlen-nlen); - return 0; - } - - /* Okay, now move the exponent pointer to the most-significant word */ - e = BIGLITTLE(e-elen, e+elen-1); - - /* Look up appropriate k-1 for the exponent - tblmask = 1<<(k-1) */ - wbits = 0; - while (ebits > bnExpModThreshTable[wbits]) - wbits++; - - /* Allocate working storage: two product buffers and the tables. */ - LBNALLOC(a, 2*mlen); - if (!a) - return -1; - LBNALLOC(b, 2*mlen); - if (!b) { - LBNFREE(a, 2*mlen); - return -1; - } - - /* Convert to the appropriate table size: tblmask = 1<<(k-1) */ - tblmask = 1u << wbits; - - /* We have the result buffer available, so use it. */ - table[0] = result; - - /* - * Okay, we now have a minimal-sized table - expand it. - * This is allowed to fail! If so, scale back the table size - * and proceed. - */ - for (i = 1; i < tblmask; i++) { - LBNALLOC(t, mlen); - if (!t) /* Out of memory! Quit the loop. */ - break; - table[i] = t; - } - - /* If we stopped, with i < tblmask, shrink the tables appropriately */ - while (tblmask > i) { - wbits--; - tblmask >>= 1; - } - /* Free up our overallocations */ - while (--i > tblmask) - LBNFREE(table[i], mlen); - - /* Okay, fill in the table */ - - /* Compute the necessary modular inverse */ - inv = lbnMontInv1_32(mod[BIGLITTLE(-1,0)]); /* LSW of modulus */ - - /* Convert n to Montgomery form */ - - /* Move n up "mlen" words into a */ - t = BIGLITTLE(a-mlen, a+mlen); - lbnCopy_32(t, n, nlen); - lbnZero_32(a, mlen); - /* Do the division - lose the quotient into the high-order words */ - (void)lbnDiv_32(t, a, mlen+nlen, mod, mlen); - /* Copy into first table entry */ - lbnCopy_32(table[0], a, mlen); - - /* Square a into b */ - lbnMontSquare_32(b, a, mod, mlen, inv); - - /* Use high half of b to initialize the table */ - t = BIGLITTLE(b-mlen, b+mlen); - for (i = 1; i < tblmask; i++) { - lbnMontMul_32(a, t, table[i-1], mod, mlen, inv); - lbnCopy_32(table[i], BIGLITTLE(a-mlen, a+mlen), mlen); - } - - /* We might use b = n^2 later... */ - - /* Initialze the fetch pointer */ - bitpos = (BNWORD32)1 << ((ebits-1) & (32-1)); /* Initialize mask */ - - /* This should point to the msbit of e */ - assert((*e & bitpos) != 0); - - /* - * Pre-load the window. Becuase the window size is - * never larger than the exponent size, there is no need to - * detect running off the end of e in here. - * - * The read-ahead is controlled by elen and the bitpos mask. - * Note that this is *ahead* of ebits, which tracks the - * most significant end of the window. The purpose of this - * initialization is to get the two wbits+1 bits apart, - * like they should be. - * - * Note that bitpos and e1len together keep track of the - * lookahead read pointer in the exponent that is used here. - */ - buf = 0; - for (i = 0; i <= wbits; i++) { - buf = (buf << 1) | ((*e & bitpos) != 0); - bitpos >>= 1; - if (!bitpos) { - BIGLITTLE(e++,e--); - bitpos = (BNWORD32)1 << (32-1); - elen--; - } - } - assert(buf & tblmask); - - /* - * Set the pending multiply positions to a location that will - * never be encountered, thus ensuring that nothing will happen - * until the need for a multiply appears and one is scheduled. - */ - multpos = ebits; /* A NULL value */ - mult = 0; /* Force a crash if we use these */ - - /* - * Okay, now begins the real work. The first step is - * slightly magic, so it's done outside the main loop, - * but it's very similar to what's inside. - */ - ebits--; /* Start processing the first bit... */ - isone = 1; - - /* - * This is just like the multiply in the loop, except that - * - We know the msbit of buf is set, and - * - We have the extra value n^2 floating around. - * So, do the usual computation, and if the result is that - * the buffer should be multiplied by n^1 immediately - * (which we'd normally then square), we multiply it - * (which reduces to a copy, which reduces to setting a flag) - * by n^2 and skip the squaring. Thus, we do the - * multiply and the squaring in one step. - */ - assert(buf & tblmask); - multpos = ebits - wbits; - while ((buf & 1) == 0) { - buf >>= 1; - multpos++; - } - /* Intermediates can wrap, but final must NOT */ - assert(multpos <= ebits); - mult = table[buf>>1]; - buf = 0; - - /* Special case: use already-computed value sitting in buffer */ - if (multpos == ebits) - isone = 0; - - /* - * At this point, the buffer (which is the high half of b) holds - * either 1 (implicitly, as the "isone" flag is set), or n^2. - */ - - /* - * The main loop. The procedure is: - * - Advance the window - * - If the most-significant bit of the window is set, - * schedule a multiply for the appropriate time in the - * future (may be immediately) - * - Perform any pending multiples - * - Check for termination - * - Square the buffer - * - * At any given time, the acumulated product is held in - * the high half of b. - */ - for (;;) { - ebits--; - - /* Advance the window */ - assert(buf < tblmask); - buf <<= 1; - /* - * This reads ahead of the current exponent position - * (controlled by ebits), so we have to be able to read - * past the lsb of the exponents without error. - */ - if (elen) { - buf |= ((*e & bitpos) != 0); - bitpos >>= 1; - if (!bitpos) { - BIGLITTLE(e++,e--); - bitpos = (BNWORD32)1 << (32-1); - elen--; - } - } - - /* Examine the window for pending multiplies */ - if (buf & tblmask) { - multpos = ebits - wbits; - while ((buf & 1) == 0) { - buf >>= 1; - multpos++; - } - /* Intermediates can wrap, but final must NOT */ - assert(multpos <= ebits); - mult = table[buf>>1]; - buf = 0; - } - - /* If we have a pending multiply, do it */ - if (ebits == multpos) { - /* Multiply by the table entry remembered previously */ - t = BIGLITTLE(b-mlen, b+mlen); - if (isone) { - /* Multiply by 1 is a trivial case */ - lbnCopy_32(t, mult, mlen); - isone = 0; - } else { - lbnMontMul_32(a, t, mult, mod, mlen, inv); - /* Swap a and b */ - t = a; a = b; b = t; - } - } - - /* Are we done? */ - if (!ebits) - break; - - /* Square the input */ - if (!isone) { - t = BIGLITTLE(b-mlen, b+mlen); - lbnMontSquare_32(a, t, mod, mlen, inv); - /* Swap a and b */ - t = a; a = b; b = t; - } - } /* for (;;) */ - - assert(!isone); - assert(!buf); - - /* DONE! */ - - /* Convert result out of Montgomery form */ - t = BIGLITTLE(b-mlen, b+mlen); - lbnCopy_32(b, t, mlen); - lbnZero_32(t, mlen); - lbnMontReduce_32(b, mod, mlen, inv); - lbnCopy_32(result, t, mlen); - /* - * Clean up - free intermediate storage. - * Do NOT free table[0], which is the result - * buffer. - */ - while (--tblmask) - LBNFREE(table[tblmask], mlen); - LBNFREE(b, 2*mlen); - LBNFREE(a, 2*mlen); - - return 0; /* Success */ -} - -/* - * Compute and return n1^e1 * n2^e2 mod "mod". - * result may be either input buffer, or something separate. - * It must be "mlen" words long. - * - * There is a current position in the exponents, which is kept in e1bits. - * (The exponents are swapped if necessary so e1 is the longer of the two.) - * At any given time, the value in the accumulator is - * n1^(e1>>e1bits) * n2^(e2>>e1bits) mod "mod". - * As e1bits is counted down, this is updated, by squaring it and doing - * any necessary multiplies. - * To decide on the necessary multiplies, two windows, each w1bits+1 bits - * wide, are maintained in buf1 and buf2, which read *ahead* of the - * e1bits position (with appropriate handling of the case when e1bits - * drops below w1bits+1). When the most-significant bit of either window - * becomes set, indicating that something needs to be multiplied by - * the accumulator or it will get out of sync, the window is examined - * to see which power of n1 or n2 to multiply by, and when (possibly - * later, if the power is greater than 1) the multiply should take - * place. Then the multiply and its location are remembered and the - * window is cleared. - * - * If we had every power of n1 in the table, the multiply would always - * be w1bits steps in the future. But we only keep the odd powers, - * so instead of waiting w1bits squarings and then multiplying - * by n1^k, we wait w1bits-k squarings and multiply by n1. - * - * Actually, w2bits can be less than w1bits, but the window is the same - * size, to make it easier to keep track of where we're reading. The - * appropriate number of low-order bits of the window are just ignored. - */ -int -lbnDoubleExpMod_32(BNWORD32 *result, - BNWORD32 const *n1, unsigned n1len, - BNWORD32 const *e1, unsigned e1len, - BNWORD32 const *n2, unsigned n2len, - BNWORD32 const *e2, unsigned e2len, - BNWORD32 *mod, unsigned mlen) -{ - BNWORD32 *table1[1 << (BNEXPMOD_MAX_WINDOW-1)]; - /* Table of odd powers of n1 */ - BNWORD32 *table2[1 << (BNEXPMOD_MAX_WINDOW-1)]; - /* Table of odd powers of n2 */ - unsigned e1bits, e2bits; /* Exponent bits */ - unsigned w1bits, w2bits; /* Window sizes */ - unsigned tblmask; /* Mask of exponentiation window */ - BNWORD32 bitpos; /* Mask of current look-ahead bit */ - unsigned buf1, buf2; /* Buffer of exponent bits */ - unsigned mult1pos, mult2pos; /* Where to do pending multiply */ - BNWORD32 const *mult1, *mult2; /* What to multiply by */ - unsigned i; /* Loop counter */ - int isone; /* Flag: accum. is implicitly one */ - BNWORD32 *a, *b; /* Working buffers/accumulators */ - BNWORD32 *t; /* Pointer into the working buffers */ - BNWORD32 inv; /* mod^-1 modulo 2^32 */ - - assert(mlen); - assert(n1len <= mlen); - assert(n2len <= mlen); - - /* First, a couple of trivial cases. */ - e1len = lbnNorm_32(e1, e1len); - e2len = lbnNorm_32(e2, e2len); - - /* Ensure that the first exponent is the longer */ - e1bits = lbnBits_32(e1, e1len); - e2bits = lbnBits_32(e2, e2len); - if (e1bits < e2bits) { - i = e1len; e1len = e2len; e2len = i; - i = e1bits; e1bits = e2bits; e2bits = i; - t = (BNWORD32 *)n1; n1 = n2; n2 = t; - t = (BNWORD32 *)e1; e1 = e2; e2 = t; - } - assert(e1bits >= e2bits); - - /* Handle a trivial case */ - if (!e2len) - return lbnExpMod_32(result, n1, n1len, e1, e1len, mod, mlen); - assert(e2bits); - - /* The code below breaks if the exponents aren't at least 2 bits */ - if (e1bits == 1) { - assert(e2bits == 1); - - LBNALLOC(a, n1len+n2len); - if (!a) - return -1; - - lbnMul_32(a, n1, n1len, n2, n2len); - /* Do a direct modular reduction */ - if (n1len + n2len >= mlen) - (void)lbnDiv_32(a+mlen, a, n1len+n2len, mod, mlen); - lbnCopy_32(result, a, mlen); - LBNFREE(a, n1len+n2len); - return 0; - } - - /* Okay, now move the exponent pointers to the most-significant word */ - e1 = BIGLITTLE(e1-e1len, e1+e1len-1); - e2 = BIGLITTLE(e2-e2len, e2+e2len-1); - - /* Look up appropriate k-1 for the exponent - tblmask = 1<<(k-1) */ - w1bits = 0; - while (e1bits > bnExpModThreshTable[w1bits]) - w1bits++; - w2bits = 0; - while (e2bits > bnExpModThreshTable[w2bits]) - w2bits++; - - assert(w1bits >= w2bits); - - /* Allocate working storage: two product buffers and the tables. */ - LBNALLOC(a, 2*mlen); - if (!a) - return -1; - LBNALLOC(b, 2*mlen); - if (!b) { - LBNFREE(a, 2*mlen); - return -1; - } - - /* Convert to the appropriate table size: tblmask = 1<<(k-1) */ - tblmask = 1u << w1bits; - /* Use buf2 for its size, temporarily */ - buf2 = 1u << w2bits; - - LBNALLOC(t, mlen); - if (!t) { - LBNFREE(b, 2*mlen); - LBNFREE(a, 2*mlen); - return -1; - } - table1[0] = t; - table2[0] = result; - - /* - * Okay, we now have some minimal-sized tables - expand them. - * This is allowed to fail! If so, scale back the table sizes - * and proceed. We allocate both tables at the same time - * so if it fails partway through, they'll both be a reasonable - * size rather than one huge and one tiny. - * When i passes buf2 (the number of entries in the e2 window, - * which may be less than the number of entries in the e1 window), - * stop allocating e2 space. - */ - for (i = 1; i < tblmask; i++) { - LBNALLOC(t, mlen); - if (!t) /* Out of memory! Quit the loop. */ - break; - table1[i] = t; - if (i < buf2) { - LBNALLOC(t, mlen); - if (!t) { - LBNFREE(table1[i], mlen); - break; - } - table2[i] = t; - } - } - - /* If we stopped, with i < tblmask, shrink the tables appropriately */ - while (tblmask > i) { - w1bits--; - tblmask >>= 1; - } - /* Free up our overallocations */ - while (--i > tblmask) { - if (i < buf2) - LBNFREE(table2[i], mlen); - LBNFREE(table1[i], mlen); - } - /* And shrink the second window too, if needed */ - if (w2bits > w1bits) { - w2bits = w1bits; - buf2 = tblmask; - } - - /* - * From now on, use the w2bits variable for the difference - * between w1bits and w2bits. - */ - w2bits = w1bits-w2bits; - - /* Okay, fill in the tables */ - - /* Compute the necessary modular inverse */ - inv = lbnMontInv1_32(mod[BIGLITTLE(-1,0)]); /* LSW of modulus */ - - /* Convert n1 to Montgomery form */ - - /* Move n1 up "mlen" words into a */ - t = BIGLITTLE(a-mlen, a+mlen); - lbnCopy_32(t, n1, n1len); - lbnZero_32(a, mlen); - /* Do the division - lose the quotient into the high-order words */ - (void)lbnDiv_32(t, a, mlen+n1len, mod, mlen); - /* Copy into first table entry */ - lbnCopy_32(table1[0], a, mlen); - - /* Square a into b */ - lbnMontSquare_32(b, a, mod, mlen, inv); - - /* Use high half of b to initialize the first table */ - t = BIGLITTLE(b-mlen, b+mlen); - for (i = 1; i < tblmask; i++) { - lbnMontMul_32(a, t, table1[i-1], mod, mlen, inv); - lbnCopy_32(table1[i], BIGLITTLE(a-mlen, a+mlen), mlen); - } - - /* Convert n2 to Montgomery form */ - - t = BIGLITTLE(a-mlen, a+mlen); - /* Move n2 up "mlen" words into a */ - lbnCopy_32(t, n2, n2len); - lbnZero_32(a, mlen); - /* Do the division - lose the quotient into the high-order words */ - (void)lbnDiv_32(t, a, mlen+n2len, mod, mlen); - /* Copy into first table entry */ - lbnCopy_32(table2[0], a, mlen); - - /* Square it into a */ - lbnMontSquare_32(a, table2[0], mod, mlen, inv); - /* Copy to b, low half */ - lbnCopy_32(b, t, mlen); - - /* Use b to initialize the second table */ - for (i = 1; i < buf2; i++) { - lbnMontMul_32(a, b, table2[i-1], mod, mlen, inv); - lbnCopy_32(table2[i], t, mlen); - } - - /* - * Okay, a recap: at this point, the low part of b holds - * n2^2, the high part holds n1^2, and the tables are - * initialized with the odd powers of n1 and n2 from 1 - * through 2*tblmask-1 and 2*buf2-1. - * - * We might use those squares in b later, or we might not. - */ - - /* Initialze the fetch pointer */ - bitpos = (BNWORD32)1 << ((e1bits-1) & (32-1)); /* Initialize mask */ - - /* This should point to the msbit of e1 */ - assert((*e1 & bitpos) != 0); - - /* - * Pre-load the windows. Becuase the window size is - * never larger than the exponent size, there is no need to - * detect running off the end of e1 in here. - * - * The read-ahead is controlled by e1len and the bitpos mask. - * Note that this is *ahead* of e1bits, which tracks the - * most significant end of the window. The purpose of this - * initialization is to get the two w1bits+1 bits apart, - * like they should be. - * - * Note that bitpos and e1len together keep track of the - * lookahead read pointer in the exponent that is used here. - * e2len is not decremented, it is only ever compared with - * e1len as *that* is decremented. - */ - buf1 = buf2 = 0; - for (i = 0; i <= w1bits; i++) { - buf1 = (buf1 << 1) | ((*e1 & bitpos) != 0); - if (e1len <= e2len) - buf2 = (buf2 << 1) | ((*e2 & bitpos) != 0); - bitpos >>= 1; - if (!bitpos) { - BIGLITTLE(e1++,e1--); - if (e1len <= e2len) - BIGLITTLE(e2++,e2--); - bitpos = (BNWORD32)1 << (32-1); - e1len--; - } - } - assert(buf1 & tblmask); - - /* - * Set the pending multiply positions to a location that will - * never be encountered, thus ensuring that nothing will happen - * until the need for a multiply appears and one is scheduled. - */ - mult1pos = mult2pos = e1bits; /* A NULL value */ - mult1 = mult2 = 0; /* Force a crash if we use these */ - - /* - * Okay, now begins the real work. The first step is - * slightly magic, so it's done outside the main loop, - * but it's very similar to what's inside. - */ - isone = 1; /* Buffer is implicitly 1, so replace * by copy */ - e1bits--; /* Start processing the first bit... */ - - /* - * This is just like the multiply in the loop, except that - * - We know the msbit of buf1 is set, and - * - We have the extra value n1^2 floating around. - * So, do the usual computation, and if the result is that - * the buffer should be multiplied by n1^1 immediately - * (which we'd normally then square), we multiply it - * (which reduces to a copy, which reduces to setting a flag) - * by n1^2 and skip the squaring. Thus, we do the - * multiply and the squaring in one step. - */ - assert(buf1 & tblmask); - mult1pos = e1bits - w1bits; - while ((buf1 & 1) == 0) { - buf1 >>= 1; - mult1pos++; - } - /* Intermediates can wrap, but final must NOT */ - assert(mult1pos <= e1bits); - mult1 = table1[buf1>>1]; - buf1 = 0; - - /* Special case: use already-computed value sitting in buffer */ - if (mult1pos == e1bits) - isone = 0; - - /* - * The first multiply by a power of n2. Similar, but - * we might not even want to schedule a multiply if e2 is - * shorter than e1, and the window might be shorter so - * we have to leave the low w2bits bits alone. - */ - if (buf2 & tblmask) { - /* Remember low-order bits for later */ - i = buf2 & ((1u << w2bits) - 1); - buf2 >>= w2bits; - mult2pos = e1bits - w1bits + w2bits; - while ((buf2 & 1) == 0) { - buf2 >>= 1; - mult2pos++; - } - assert(mult2pos <= e1bits); - mult2 = table2[buf2>>1]; - buf2 = i; - - if (mult2pos == e1bits) { - t = BIGLITTLE(b-mlen, b+mlen); - if (isone) { - lbnCopy_32(t, b, mlen); /* Copy low to high */ - isone = 0; - } else { - lbnMontMul_32(a, t, b, mod, mlen, inv); - t = a; a = b; b = t; - } - } - } - - /* - * At this point, the buffer (which is the high half of b) - * holds either 1 (implicitly, as the "isone" flag is set), - * n1^2, n2^2 or n1^2 * n2^2. - */ - - /* - * The main loop. The procedure is: - * - Advance the windows - * - If the most-significant bit of a window is set, - * schedule a multiply for the appropriate time in the - * future (may be immediately) - * - Perform any pending multiples - * - Check for termination - * - Square the buffers - * - * At any given time, the acumulated product is held in - * the high half of b. - */ - for (;;) { - e1bits--; - - /* Advance the windows */ - assert(buf1 < tblmask); - buf1 <<= 1; - assert(buf2 < tblmask); - buf2 <<= 1; - /* - * This reads ahead of the current exponent position - * (controlled by e1bits), so we have to be able to read - * past the lsb of the exponents without error. - */ - if (e1len) { - buf1 |= ((*e1 & bitpos) != 0); - if (e1len <= e2len) - buf2 |= ((*e2 & bitpos) != 0); - bitpos >>= 1; - if (!bitpos) { - BIGLITTLE(e1++,e1--); - if (e1len <= e2len) - BIGLITTLE(e2++,e2--); - bitpos = (BNWORD32)1 << (32-1); - e1len--; - } - } - - /* Examine the first window for pending multiplies */ - if (buf1 & tblmask) { - mult1pos = e1bits - w1bits; - while ((buf1 & 1) == 0) { - buf1 >>= 1; - mult1pos++; - } - /* Intermediates can wrap, but final must NOT */ - assert(mult1pos <= e1bits); - mult1 = table1[buf1>>1]; - buf1 = 0; - } - - /* - * Examine the second window for pending multiplies. - * Window 2 can be smaller than window 1, but we - * keep the same number of bits in buf2, so we need - * to ignore any low-order bits in the buffer when - * computing what to multiply by, and recompute them - * later. - */ - if (buf2 & tblmask) { - /* Remember low-order bits for later */ - i = buf2 & ((1u << w2bits) - 1); - buf2 >>= w2bits; - mult2pos = e1bits - w1bits + w2bits; - while ((buf2 & 1) == 0) { - buf2 >>= 1; - mult2pos++; - } - assert(mult2pos <= e1bits); - mult2 = table2[buf2>>1]; - buf2 = i; - } - - - /* If we have a pending multiply for e1, do it */ - if (e1bits == mult1pos) { - /* Multiply by the table entry remembered previously */ - t = BIGLITTLE(b-mlen, b+mlen); - if (isone) { - /* Multiply by 1 is a trivial case */ - lbnCopy_32(t, mult1, mlen); - isone = 0; - } else { - lbnMontMul_32(a, t, mult1, mod, mlen, inv); - /* Swap a and b */ - t = a; a = b; b = t; - } - } - - /* If we have a pending multiply for e2, do it */ - if (e1bits == mult2pos) { - /* Multiply by the table entry remembered previously */ - t = BIGLITTLE(b-mlen, b+mlen); - if (isone) { - /* Multiply by 1 is a trivial case */ - lbnCopy_32(t, mult2, mlen); - isone = 0; - } else { - lbnMontMul_32(a, t, mult2, mod, mlen, inv); - /* Swap a and b */ - t = a; a = b; b = t; - } - } - - /* Are we done? */ - if (!e1bits) - break; - - /* Square the buffer */ - if (!isone) { - t = BIGLITTLE(b-mlen, b+mlen); - lbnMontSquare_32(a, t, mod, mlen, inv); - /* Swap a and b */ - t = a; a = b; b = t; - } - } /* for (;;) */ - - assert(!isone); - assert(!buf1); - assert(!buf2); - - /* DONE! */ - - /* Convert result out of Montgomery form */ - t = BIGLITTLE(b-mlen, b+mlen); - lbnCopy_32(b, t, mlen); - lbnZero_32(t, mlen); - lbnMontReduce_32(b, mod, mlen, inv); - lbnCopy_32(result, t, mlen); - - /* Clean up - free intermediate storage */ - buf2 = tblmask >> w2bits; - while (--tblmask) { - if (tblmask < buf2) - LBNFREE(table2[tblmask], mlen); - LBNFREE(table1[tblmask], mlen); - } - t = table1[0]; - LBNFREE(t, mlen); - LBNFREE(b, 2*mlen); - LBNFREE(a, 2*mlen); - - return 0; /* Success */ -} - -/* - * 2^exp (mod mod). This is an optimized version for use in Fermat - * tests. The input value of n is ignored; it is returned with - * "mlen" words valid. - */ -int -lbnTwoExpMod_32(BNWORD32 *n, BNWORD32 const *exp, unsigned elen, - BNWORD32 *mod, unsigned mlen) -{ - unsigned e; /* Copy of high words of the exponent */ - unsigned bits; /* Assorted counter of bits */ - BNWORD32 const *bitptr; - BNWORD32 bitword, bitpos; - BNWORD32 *a, *b, *a1; - BNWORD32 inv; - - assert(mlen); - - bitptr = BIGLITTLE(exp-elen, exp+elen-1); - bitword = *bitptr; - assert(bitword); - - /* Clear n for future use. */ - lbnZero_32(n, mlen); - - bits = lbnBits_32(exp, elen); - - /* First, a couple of trivial cases. */ - if (bits <= 1) { - /* 2 ^ 0 == 1, 2 ^ 1 == 2 */ - BIGLITTLE(n[-1],n[0]) = (BNWORD32)1<<elen; - return 0; - } - - /* Set bitpos to the most significant bit */ - bitpos = (BNWORD32)1 << ((bits-1) & (32-1)); - - /* Now, count the bits in the modulus. */ - bits = lbnBits_32(mod, mlen); - assert(bits > 1); /* a 1-bit modulus is just stupid... */ - - /* - * We start with 1<<e, where "e" is as many high bits of the - * exponent as we can manage without going over the modulus. - * This first loop finds "e". - */ - e = 1; - while (elen) { - /* Consume the first bit */ - bitpos >>= 1; - if (!bitpos) { - if (!--elen) - break; - bitword = BIGLITTLE(*++bitptr,*--bitptr); - bitpos = (BNWORD32)1<<(32-1); - } - e = (e << 1) | ((bitpos & bitword) != 0); - if (e >= bits) { /* Overflow! Back out. */ - e >>= 1; - break; - } - } - /* - * The bit in "bitpos" being examined by the bit buffer has NOT - * been consumed yet. This may be past the end of the exponent, - * in which case elen == 1. - */ - - /* Okay, now, set bit "e" in n. n is already zero. */ - inv = (BNWORD32)1 << (e & (32-1)); - e /= 32; - BIGLITTLE(n[-e-1],n[e]) = inv; - /* - * The effective length of n in words is now "e+1". - * This is used a little bit later. - */ - - if (!elen) - return 0; /* That was easy! */ - - /* - * We have now processed the first few bits. The next step - * is to convert this to Montgomery form for further squaring. - */ - - /* Allocate working storage: two product buffers */ - LBNALLOC(a, 2*mlen); - if (!a) - return -1; - LBNALLOC(b, 2*mlen); - if (!b) { - LBNFREE(a, 2*mlen); - return -1; - } - - /* Convert n to Montgomery form */ - inv = BIGLITTLE(mod[-1],mod[0]); /* LSW of modulus */ - assert(inv & 1); /* Modulus must be odd */ - inv = lbnMontInv1_32(inv); - /* Move n (length e+1, remember?) up "mlen" words into b */ - /* Note that we lie about a1 for a bit - it's pointing to b */ - a1 = BIGLITTLE(b-mlen,b+mlen); - lbnCopy_32(a1, n, e+1); - lbnZero_32(b, mlen); - /* Do the division - dump the quotient into the high-order words */ - (void)lbnDiv_32(a1, b, mlen+e+1, mod, mlen); - /* - * Now do the first squaring and modular reduction to put - * the number up in a1 where it belongs. - */ - lbnMontSquare_32(a, b, mod, mlen, inv); - /* Fix up a1 to point to where it should go. */ - a1 = BIGLITTLE(a-mlen,a+mlen); - - /* - * Okay, now, a1 holds the number being accumulated, and - * b is a scratch register. Start working: - */ - for (;;) { - /* - * Is the bit set? If so, double a1 as well. - * A modular doubling like this is very cheap. - */ - if (bitpos & bitword) { - /* - * Double the number. If there was a carry out OR - * the result is greater than the modulus, subract - * the modulus. - */ - if (lbnDouble_32(a1, mlen) || - lbnCmp_32(a1, mod, mlen) > 0) - (void)lbnSubN_32(a1, mod, mlen); - } - - /* Advance to the next exponent bit */ - bitpos >>= 1; - if (!bitpos) { - if (!--elen) - break; /* Done! */ - bitword = BIGLITTLE(*++bitptr,*--bitptr); - bitpos = (BNWORD32)1<<(32-1); - } - - /* - * The elen/bitword/bitpos bit buffer is known to be - * non-empty, i.e. there is at least one more unconsumed bit. - * Thus, it's safe to square the number. - */ - lbnMontSquare_32(b, a1, mod, mlen, inv); - /* Rename result (in b) back to a (a1, really). */ - a1 = b; b = a; a = a1; - a1 = BIGLITTLE(a-mlen,a+mlen); - } - - /* DONE! Just a little bit of cleanup... */ - - /* - * Convert result out of Montgomery form... this is - * just a Montgomery reduction. - */ - lbnCopy_32(a, a1, mlen); - lbnZero_32(a1, mlen); - lbnMontReduce_32(a, mod, mlen, inv); - lbnCopy_32(n, a1, mlen); - - /* Clean up - free intermediate storage */ - LBNFREE(b, 2*mlen); - LBNFREE(a, 2*mlen); - - return 0; /* Success */ -} - - -/* - * Returns a substring of the big-endian array of bytes representation - * of the bignum array based on two parameters, the least significant - * byte number (0 to start with the least significant byte) and the - * length. I.e. the number returned is a representation of - * (bn / 2^(8*lsbyte)) % 2 ^ (8*buflen). - * - * It is an error if the bignum is not at least buflen + lsbyte bytes - * long. - * - * This code assumes that the compiler has the minimal intelligence - * neded to optimize divides and modulo operations on an unsigned data - * type with a power of two. - */ -void -lbnExtractBigBytes_32(BNWORD32 const *n, unsigned char *buf, - unsigned lsbyte, unsigned buflen) -{ - BNWORD32 t = 0; /* Needed to shut up uninitialized var warnings */ - unsigned shift; - - lsbyte += buflen; - - shift = (8 * lsbyte) % 32; - lsbyte /= (32/8); /* Convert to word offset */ - BIGLITTLE(n -= lsbyte, n += lsbyte); - - if (shift) - t = BIGLITTLE(n[-1],n[0]); - - while (buflen--) { - if (!shift) { - t = BIGLITTLE(*n++,*--n); - shift = 32; - } - shift -= 8; - *buf++ = (unsigned char)(t>>shift); - } -} - -/* - * Merge a big-endian array of bytes into a bignum array. - * The array had better be big enough. This is - * equivalent to extracting the entire bignum into a - * large byte array, copying the input buffer into the - * middle of it, and converting back to a bignum. - * - * The buf is "len" bytes long, and its *last* byte is at - * position "lsbyte" from the end of the bignum. - * - * Note that this is a pain to get right. Fortunately, it's hardly - * critical for efficiency. - */ -void -lbnInsertBigBytes_32(BNWORD32 *n, unsigned char const *buf, - unsigned lsbyte, unsigned buflen) -{ - BNWORD32 t = 0; /* Shut up uninitialized varibale warnings */ - - lsbyte += buflen; - - BIGLITTLE(n -= lsbyte/(32/8), n += lsbyte/(32/8)); - - /* Load up leading odd bytes */ - if (lsbyte % (32/8)) { - t = BIGLITTLE(*--n,*n++); - t >>= (lsbyte * 8) % 32; - } - - /* The main loop - merge into t, storing at each word boundary. */ - while (buflen--) { - t = (t << 8) | *buf++; - if ((--lsbyte % (32/8)) == 0) - BIGLITTLE(*n++,*--n) = t; - } - - /* Merge odd bytes in t into last word */ - lsbyte = (lsbyte * 8) % 32; - if (lsbyte) { - t <<= lsbyte; - t |= (((BNWORD32)1 << lsbyte) - 1) & BIGLITTLE(n[0],n[-1]); - BIGLITTLE(n[0],n[-1]) = t; - } - - return; -} - -/* - * Returns a substring of the little-endian array of bytes representation - * of the bignum array based on two parameters, the least significant - * byte number (0 to start with the least significant byte) and the - * length. I.e. the number returned is a representation of - * (bn / 2^(8*lsbyte)) % 2 ^ (8*buflen). - * - * It is an error if the bignum is not at least buflen + lsbyte bytes - * long. - * - * This code assumes that the compiler has the minimal intelligence - * neded to optimize divides and modulo operations on an unsigned data - * type with a power of two. - */ -void -lbnExtractLittleBytes_32(BNWORD32 const *n, unsigned char *buf, - unsigned lsbyte, unsigned buflen) -{ - BNWORD32 t = 0; /* Needed to shut up uninitialized var warnings */ - - BIGLITTLE(n -= lsbyte/(32/8), n += lsbyte/(32/8)); - - if (lsbyte % (32/8)) { - t = BIGLITTLE(*--n,*n++); - t >>= (lsbyte % (32/8)) * 8 ; - } - - while (buflen--) { - if ((lsbyte++ % (32/8)) == 0) - t = BIGLITTLE(*--n,*n++); - *buf++ = (unsigned char)t; - t >>= 8; - } -} - -/* - * Merge a little-endian array of bytes into a bignum array. - * The array had better be big enough. This is - * equivalent to extracting the entire bignum into a - * large byte array, copying the input buffer into the - * middle of it, and converting back to a bignum. - * - * The buf is "len" bytes long, and its first byte is at - * position "lsbyte" from the end of the bignum. - * - * Note that this is a pain to get right. Fortunately, it's hardly - * critical for efficiency. - */ -void -lbnInsertLittleBytes_32(BNWORD32 *n, unsigned char const *buf, - unsigned lsbyte, unsigned buflen) -{ - BNWORD32 t = 0; /* Shut up uninitialized varibale warnings */ - - /* Move to most-significant end */ - lsbyte += buflen; - buf += buflen; - - BIGLITTLE(n -= lsbyte/(32/8), n += lsbyte/(32/8)); - - /* Load up leading odd bytes */ - if (lsbyte % (32/8)) { - t = BIGLITTLE(*--n,*n++); - t >>= (lsbyte * 8) % 32; - } - - /* The main loop - merge into t, storing at each word boundary. */ - while (buflen--) { - t = (t << 8) | *--buf; - if ((--lsbyte % (32/8)) == 0) - BIGLITTLE(*n++,*--n) = t; - } - - /* Merge odd bytes in t into last word */ - lsbyte = (lsbyte * 8) % 32; - if (lsbyte) { - t <<= lsbyte; - t |= (((BNWORD32)1 << lsbyte) - 1) & BIGLITTLE(n[0],n[-1]); - BIGLITTLE(n[0],n[-1]) = t; - } - - return; -} - -#ifdef DEADCODE /* This was a precursor to the more flexible lbnExtractBytes */ -/* - * Convert a big-endian array of bytes to a bignum. - * Returns the number of words in the bignum. - * Note the expression "32/8" for the number of bytes per word. - * This is so the word-size adjustment will work. - */ -unsigned -lbnFromBytes_32(BNWORD32 *a, unsigned char const *b, unsigned blen) -{ - BNWORD32 t; - unsigned alen = (blen + (32/8-1))/(32/8); - BIGLITTLE(a -= alen, a += alen); - - while (blen) { - t = 0; - do { - t = t << 8 | *b++; - } while (--blen & (32/8-1)); - BIGLITTLE(*a++,*--a) = t; - } - return alen; -} -#endif - -/* - * Computes the GCD of a and b. Modifies both arguments; - * when it returns, one of them is the GCD and the other is trash. - * The return value is the length of the GCD, with the sign telling - * whether it is in a (+ve) or b (-ve). Both inputs must have - * one extra word of precision. alen must be >= blen. - * - * TODO: use the binary algorithm (Knuth section 4.5.2, algorithm B). - * This is based on taking out common powers of 2, then repeatedly: - * gcd(2*u,v) = gcd(u,2*v) = gcd(u,v) - isolated powers of 2 can be deleted. - * gcd(u,v) = gcd(u-v,v) - the numbers can be easily reduced. - * It gets less reduction per step, but the steps are much faster than - * the division case. - */ -int -lbnGcd_32(BNWORD32 *a, unsigned alen, BNWORD32 *b, unsigned blen) -{ - assert(alen >= blen); - - while (blen != 0) { - (void)lbnDiv_32(BIGLITTLE(a-blen,a+blen), a, alen, b, blen); - alen = lbnNorm_32(a, blen); - if (alen == 0) - return -(int)blen; - (void)lbnDiv_32(BIGLITTLE(b-alen,b+alen), b, blen, a, alen); - blen = lbnNorm_32(b, alen); - } - return alen; -} - -/* - * Invert "a" modulo "mod" using the extended Euclidean algorithm. - * Note that this only computes one of the cosequences, and uses the - * theorem that the signs flip every step and the absolute value of - * the cosequence values are always bounded by the modulus to avoid - * having to work with negative numbers. - * gcd(a,mod) had better equal 1. Returns 1 if the GCD is NOT 1. - * a must be one word longer than "mod". It is overwritten with the - * result. - * TODO: Use Richard Schroeppel's *much* faster algorithm. - */ -int -lbnInv_32(BNWORD32 *a, unsigned alen, BNWORD32 const *mod, unsigned mlen) -{ - BNWORD32 *b; /* Hold a copy of mod during GCD reduction */ - BNWORD32 *p; /* Temporary for products added to t0 and t1 */ - BNWORD32 *t0, *t1; /* Inverse accumulators */ - BNWORD32 cy; - unsigned blen, t0len, t1len, plen; - - alen = lbnNorm_32(a, alen); - if (!alen) - return 1; /* No inverse */ - - mlen = lbnNorm_32(mod, mlen); - - assert (alen <= mlen); - - /* Inverse of 1 is 1 */ - if (alen == 1 && BIGLITTLE(a[-1],a[0]) == 1) { - lbnZero_32(BIGLITTLE(a-alen,a+alen), mlen-alen); - return 0; - } - - /* Allocate a pile of space */ - LBNALLOC(b, mlen+1); - if (b) { - /* - * Although products are guaranteed to always be less than the - * modulus, it can involve multiplying two 3-word numbers to - * get a 5-word result, requiring a 6th word to store a 0 - * temporarily. Thus, mlen + 1. - */ - LBNALLOC(p, mlen+1); - if (p) { - LBNALLOC(t0, mlen); - if (t0) { - LBNALLOC(t1, mlen); - if (t1) - goto allocated; - LBNFREE(t0, mlen); - } - LBNFREE(p, mlen+1); - } - LBNFREE(b, mlen+1); - } - return -1; - -allocated: - - /* Set t0 to 1 */ - t0len = 1; - BIGLITTLE(t0[-1],t0[0]) = 1; - - /* b = mod */ - lbnCopy_32(b, mod, mlen); - /* blen = mlen (implicitly) */ - - /* t1 = b / a; b = b % a */ - cy = lbnDiv_32(t1, b, mlen, a, alen); - *(BIGLITTLE(t1-(mlen-alen)-1,t1+(mlen-alen))) = cy; - t1len = lbnNorm_32(t1, mlen-alen+1); - blen = lbnNorm_32(b, alen); - - /* while (b > 1) */ - while (blen > 1 || BIGLITTLE(b[-1],b[0]) != (BNWORD32)1) { - /* q = a / b; a = a % b; */ - if (alen < blen || (alen == blen && lbnCmp_32(a, a, alen) < 0)) - assert(0); - cy = lbnDiv_32(BIGLITTLE(a-blen,a+blen), a, alen, b, blen); - *(BIGLITTLE(a-alen-1,a+alen)) = cy; - plen = lbnNorm_32(BIGLITTLE(a-blen,a+blen), alen-blen+1); - assert(plen); - alen = lbnNorm_32(a, blen); - if (!alen) - goto failure; /* GCD not 1 */ - - /* t0 += q * t1; */ - assert(plen+t1len <= mlen+1); - lbnMul_32(p, BIGLITTLE(a-blen,a+blen), plen, t1, t1len); - plen = lbnNorm_32(p, plen + t1len); - assert(plen <= mlen); - if (plen > t0len) { - lbnZero_32(BIGLITTLE(t0-t0len,t0+t0len), plen-t0len); - t0len = plen; - } - cy = lbnAddN_32(t0, p, plen); - if (cy) { - if (t0len > plen) { - cy = lbnAdd1_32(BIGLITTLE(t0-plen,t0+plen), - t0len-plen, cy); - } - if (cy) { - BIGLITTLE(t0[-t0len-1],t0[t0len]) = cy; - t0len++; - } - } - - /* if (a <= 1) return a ? t0 : FAIL; */ - if (alen <= 1 && BIGLITTLE(a[-1],a[0]) == (BNWORD32)1) { - if (alen == 0) - goto failure; /* FAIL */ - assert(t0len <= mlen); - lbnCopy_32(a, t0, t0len); - lbnZero_32(BIGLITTLE(a-t0len, a+t0len), mlen-t0len); - goto success; - } - - /* q = b / a; b = b % a; */ - if (blen < alen || (blen == alen && lbnCmp_32(b, a, alen) < 0)) - assert(0); - cy = lbnDiv_32(BIGLITTLE(b-alen,b+alen), b, blen, a, alen); - *(BIGLITTLE(b-blen-1,b+blen)) = cy; - plen = lbnNorm_32(BIGLITTLE(b-alen,b+alen), blen-alen+1); - assert(plen); - blen = lbnNorm_32(b, alen); - if (!blen) - goto failure; /* GCD not 1 */ - - /* t1 += q * t0; */ - assert(plen+t0len <= mlen+1); - lbnMul_32(p, BIGLITTLE(b-alen,b+alen), plen, t0, t0len); - plen = lbnNorm_32(p, plen + t0len); - assert(plen <= mlen); - if (plen > t1len) { - lbnZero_32(BIGLITTLE(t1-t1len,t1+t1len), plen-t1len); - t1len = plen; - } - cy = lbnAddN_32(t1, p, plen); - if (cy) { - if (t1len > plen) { - cy = lbnAdd1_32(BIGLITTLE(t1-plen,t0+plen), - t1len-plen, cy); - } - if (cy) { - BIGLITTLE(t1[-t1len-1],t1[t1len]) = cy; - t1len++; - } - } - } - - if (!blen) - goto failure; /* gcd(a, mod) != 1 -- FAIL */ - - /* return mod-t1 */ - lbnCopy_32(a, mod, mlen); - assert(t1len <= mlen); - cy = lbnSubN_32(a, t1, t1len); - if (cy) { - assert(mlen > t1len); - cy = lbnSub1_32(BIGLITTLE(a-t1len, a+t1len), mlen-t1len, cy); - assert(!cy); - } - -success: - LBNFREE(t1, mlen); - LBNFREE(t0, mlen); - LBNFREE(p, mlen+1); - LBNFREE(b, mlen+1); - - return 0; - -failure: - LBNFREE(t1, mlen); - LBNFREE(t0, mlen); - LBNFREE(p, mlen+1); - LBNFREE(b, mlen+1); - - return 1; -} diff --git a/usr/src/lib/libresolv2/common/cylink/lbn32.h b/usr/src/lib/libresolv2/common/cylink/lbn32.h deleted file mode 100644 index d0347390c2..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbn32.h +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#ifndef LBN32_H -#define LBN32_H - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "lbn.h" - -#ifndef BNWORD32 -#error 32-bit bignum library requires a 32-bit data type -#endif - -#ifndef lbnCopy_32 -void lbnCopy_32(BNWORD32 *dest, BNWORD32 const *src, unsigned len); -#endif -#ifndef lbnZero_32 -void lbnZero_32(BNWORD32 *num, unsigned len); -#endif -#ifndef lbnNeg_32 -void lbnNeg_32(BNWORD32 *num, unsigned len); -#endif - -#ifndef lbnAdd1_32 -BNWORD32 lbnAdd1_32(BNWORD32 *num, unsigned len, BNWORD32 carry); -#endif -#ifndef lbnSub1_32 -BNWORD32 lbnSub1_32(BNWORD32 *num, unsigned len, BNWORD32 borrow); -#endif - -#ifndef lbnAddN_32 -BNWORD32 lbnAddN_32(BNWORD32 *num1, BNWORD32 const *num2, unsigned len); -#endif -#ifndef lbnSubN_32 -BNWORD32 lbnSubN_32(BNWORD32 *num1, BNWORD32 const *num2, unsigned len); -#endif - -#ifndef lbnCmp_32 -int lbnCmp_32(BNWORD32 const *num1, BNWORD32 const *num2, unsigned len); -#endif - -#ifndef lbnMulN1_32 -void lbnMulN1_32(BNWORD32 *out, BNWORD32 const *in, unsigned len, BNWORD32 k); -#endif -#ifndef lbnMulAdd1_32 -BNWORD32 -lbnMulAdd1_32(BNWORD32 *out, BNWORD32 const *in, unsigned len, BNWORD32 k); -#endif -#ifndef lbnMulSub1_32 -BNWORD32 lbnMulSub1_32(BNWORD32 *out, BNWORD32 const *in, unsigned len, BNWORD32 k); -#endif - -#ifndef lbnLshift_32 -BNWORD32 lbnLshift_32(BNWORD32 *num, unsigned len, unsigned shift); -#endif -#ifndef lbnDouble_32 -BNWORD32 lbnDouble_32(BNWORD32 *num, unsigned len); -#endif -#ifndef lbnRshift_32 -BNWORD32 lbnRshift_32(BNWORD32 *num, unsigned len, unsigned shift); -#endif - -#ifndef lbnMul_32 -void lbnMul_32(BNWORD32 *prod, BNWORD32 const *num1, unsigned len1, - BNWORD32 const *num2, unsigned len2); -#endif -#ifndef lbnSquare_32 -void lbnSquare_32(BNWORD32 *prod, BNWORD32 const *num, unsigned len); -#endif - -#ifndef lbnNorm_32 -unsigned lbnNorm_32(BNWORD32 const *num, unsigned len); -#endif -#ifndef lbnBits_32 -unsigned lbnBits_32(BNWORD32 const *num, unsigned len); -#endif - -#ifndef lbnExtractBigBytes_32 -void lbnExtractBigBytes_32(BNWORD32 const *bn, unsigned char *buf, - unsigned lsbyte, unsigned buflen); -#endif -#ifndef lbnInsertBigytes_32 -void lbnInsertBigBytes_32(BNWORD32 *n, unsigned char const *buf, - unsigned lsbyte, unsigned buflen); -#endif -#ifndef lbnExtractLittleBytes_32 -void lbnExtractLittleBytes_32(BNWORD32 const *bn, unsigned char *buf, - unsigned lsbyte, unsigned buflen); -#endif -#ifndef lbnInsertLittleBytes_32 -void lbnInsertLittleBytes_32(BNWORD32 *n, unsigned char const *buf, - unsigned lsbyte, unsigned buflen); -#endif - -#ifndef lbnDiv21_32 -BNWORD32 lbnDiv21_32(BNWORD32 *q, BNWORD32 nh, BNWORD32 nl, BNWORD32 d); -#endif -#ifndef lbnDiv1_32 -BNWORD32 lbnDiv1_32(BNWORD32 *q, BNWORD32 *rem, - BNWORD32 const *n, unsigned len, BNWORD32 d); -#endif -#ifndef lbnModQ_32 -unsigned lbnModQ_32(BNWORD32 const *n, unsigned len, unsigned d); -#endif -#ifndef lbnDiv_32 -BNWORD32 -lbnDiv_32(BNWORD32 *q, BNWORD32 *n, unsigned nlen, BNWORD32 *d, unsigned dlen); -#endif - -#ifndef lbnMontInv1_32 -BNWORD32 lbnMontInv1_32(BNWORD32 const x); -#endif -#ifndef lbnMontReduce_32 -void lbnMontReduce_32(BNWORD32 *n, BNWORD32 const *mod, unsigned const mlen, - BNWORD32 inv); -#endif -#ifndef lbnToMont_32 -void lbnToMont_32(BNWORD32 *n, unsigned nlen, BNWORD32 *mod, unsigned mlen); -#endif -#ifndef lbnFromMont_32 -void lbnFromMont_32(BNWORD32 *n, BNWORD32 *mod, unsigned len); -#endif - -#ifndef lbnExpMod_32 -int lbnExpMod_32(BNWORD32 *result, BNWORD32 const *n, unsigned nlen, - BNWORD32 const *exp, unsigned elen, BNWORD32 *mod, unsigned mlen); -#endif -#ifndef lbnDoubleExpMod_32 -int lbnDoubleExpMod_32(BNWORD32 *result, - BNWORD32 const *n1, unsigned n1len, BNWORD32 const *e1, unsigned e1len, - BNWORD32 const *n2, unsigned n2len, BNWORD32 const *e2, unsigned e2len, - BNWORD32 *mod, unsigned mlen); -#endif -#ifndef lbnTwoExpMod_32 -int lbnTwoExpMod_32(BNWORD32 *n, BNWORD32 const *exp, unsigned elen, - BNWORD32 *mod, unsigned mlen); -#endif -#ifndef lbnGcd_32 -int lbnGcd_32(BNWORD32 *a, unsigned alen, BNWORD32 *b, unsigned blen); -#endif -#ifndef lbnInv_32 -int lbnInv_32(BNWORD32 *a, unsigned alen, BNWORD32 const *mod, unsigned mlen); -#endif - -#endif /* LBN32_H */ diff --git a/usr/src/lib/libresolv2/common/cylink/lbn68000.c b/usr/src/lib/libresolv2/common/cylink/lbn68000.c deleted file mode 100644 index 96404d674f..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbn68000.c +++ /dev/null @@ -1,507 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * lbn68000.c - 16-bit bignum primitives for the 68000 (or 68010) processors. - * - * Copyright (c) 1995 Colin Plumb. All rights reserved. - * For licensing and other legal details, see the file legal.c. - * - * This was written for Metrowerks C, and while it should be reasonably - * portable, NOTE that Metrowerks lets a callee trash a0, a1, d0, d1, and d2. - * Some 680x0 compilers make d2 callee-save, so instructions to save it - * will have to be added. - * - * This code supports 16 or 32-bit ints, based on UINT_MAX. - * Regardless of UINT_MAX, only bignums up to 64K words (1 million bits) - * are supported. (68k hackers will recognize this as a consequence of - * using dbra.) - * - * These primitives use little-endian word order. - * (The order of bytes within words is irrelevant to this issue.) - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <limits.h> - -#include "lbn.h" /* Should include lbn68000.h */ - -/* - * The Metrowerks C compiler (1.2.2) produces bad 68k code for the - * following input, which happens to be the inner loop of lbnSub1, - * so a few less than critical routines have been recoded in assembly - * to avoid the bug. (Optimizer on or off does not matter.) - * - * unsigned - * decrement(unsigned *num, unsigned len) - * { - * do { - * if ((*num++)-- != 0) - * return 0; - * } while (--len); - * return 1; - * } - */ -asm BNWORD16 -lbnSub1_16(BNWORD16 *num, unsigned len, BNWORD16 borrow) -{ - movea.l 4(sp),a0 /* num */ -#if UINT_MAX == 0xffff - move.w 10(sp),d0 /* borrow */ -#else - move.w 12(sp),d0 /* borrow */ -#endif - sub.w d0,(a0)+ - bcc done -#if UINT_MAX == 0xffff - move.w 8(sp),d0 /* len */ -#else - move.w 10(sp),d0 /* len */ -#endif - subq.w #2,d0 - bcs done -loop: - subq.w #1,(a0)+ - dbcc d0,loop -done: - moveq.l #0,d0 - addx.w d0,d0 - rts -} - -asm BNWORD16 -lbnAdd1_16(BNWORD16 *num, unsigned len, BNWORD16 carry) -{ - movea.l 4(sp),a0 /* num */ -#if UINT_MAX == 0xffff - move.w 10(sp),d0 /* carry */ -#else - move.w 12(sp),d0 /* carry */ -#endif - add.w d0,(a0)+ - bcc done -#if UINT_MAX == 0xffff - move.w 8(sp),d0 /* len */ -#else - move.w 10(sp),d0 /* len */ -#endif - subq.w #2,d0 - bcs done -loop: - addq.w #1,(a0)+ - dbcc d0,loop -done: - moveq.l #0,d0 - addx.w d0,d0 - rts -} - -asm void -lbnMulN1_16(BNWORD16 *out, BNWORD16 const *in, unsigned len, BNWORD16 k) -{ - move.w d3,-(sp) /* 2 bytes of stack frame */ - move.l 2+4(sp),a1 /* out */ - move.l 2+8(sp),a0 /* in */ -#if UINT_MAX == 0xffff - move.w 2+12(sp),d3 /* len */ - move.w 2+14(sp),d2 /* k */ -#else - move.w 2+14(sp),d3 /* len (low 16 bits) */ - move.w 2+16(sp),d2 /* k */ -#endif - - move.w (a0)+,d1 /* First multiply */ - mulu.w d2,d1 - move.w d1,(a1)+ - clr.w d1 - swap d1 - - subq.w #1,d3 /* Setup for loop unrolling */ - lsr.w #1,d3 - bcs.s m16_even - beq.s m16_short - - subq.w #1,d3 /* Set up software pipeline properly */ - move.l d1,d0 - -m16_loop: - move.w (a0)+,d1 - mulu.w d2,d1 - add.l d0,d1 - move.w d1,(a1)+ - clr.w d1 - swap d1 -m16_even: - - move.w (a0)+,d0 - mulu.w d2,d0 - add.l d1,d0 - move.w d0,(a1)+ - clr.w d0 - swap d0 - - dbra d3,m16_loop - - move.w d0,(a1) - move.w (sp)+,d3 - rts -m16_short: - move.w d1,(a1) - move.w (sp)+,d3 - rts -} - - -asm BNWORD16 -lbnMulAdd1_16(BNWORD16 *out, BNWORD16 const *in, unsigned len, BNWORD16 k) -{ - move.w d4,-(sp) - clr.w d4 - move.w d3,-(sp) /* 4 bytes of stack frame */ - move.l 4+4(sp),a1 /* out */ - move.l 4+8(sp),a0 /* in */ -#if UINT_MAX == 0xffff - move.w 4+12(sp),d3 /* len */ - move.w 4+14(sp),d2 /* k */ -#else - move.w 4+14(sp),d3 /* len (low 16 bits) */ - move.w 4+16(sp),d2 /* k */ -#endif - - move.w (a0)+,d1 /* First multiply */ - mulu.w d2,d1 - add.w d1,(a1)+ - clr.w d1 - swap d1 - addx.w d4,d1 - - subq.w #1,d3 /* Setup for loop unrolling */ - lsr.w #1,d3 - bcs.s ma16_even - beq.s ma16_short - - subq.w #1,d3 /* Set up software pipeline properly */ - move.l d1,d0 - -ma16_loop: - move.w (a0)+,d1 - mulu.w d2,d1 - add.l d0,d1 - add.w d1,(a1)+ - clr.w d1 - swap d1 - addx.w d4,d1 -ma16_even: - - move.w (a0)+,d0 - mulu.w d2,d0 - add.l d1,d0 - add.w d0,(a1)+ - clr.w d0 - swap d0 - addx.w d4,d0 - - dbra d3,ma16_loop - - move.w (sp)+,d3 - move.w (sp)+,d4 - rts -ma16_short: - move.w (sp)+,d3 - move.l d1,d0 - move.w (sp)+,d4 - rts -} - - - -asm BNWORD16 -lbnMulSub1_16(BNWORD16 *out, BNWORD16 const *in, unsigned len, BNWORD16 k) -{ - move.w d4,-(sp) - clr.w d4 - move.w d3,-(sp) /* 4 bytes of stack frame */ - move.l 4+4(sp),a1 /* out */ - move.l 4+8(sp),a0 /* in */ -#if UINT_MAX == 0xffff - move.w 4+12(sp),d3 /* len */ - move.w 4+14(sp),d2 /* k */ -#else - move.w 4+14(sp),d3 /* len (low 16 bits) */ - move.w 4+16(sp),d2 /* k */ -#endif - - move.w (a0)+,d1 /* First multiply */ - mulu.w d2,d1 - sub.w d1,(a1)+ - clr.w d1 - swap d1 - addx.w d4,d1 - - subq.w #1,d3 /* Setup for loop unrolling */ - lsr.w #1,d3 - bcs.s ms16_even - beq.s ms16_short - - subq.w #1,d3 /* Set up software pipeline properly */ - move.l d1,d0 - -ms16_loop: - move.w (a0)+,d1 - mulu.w d2,d1 - add.l d0,d1 - sub.w d1,(a1)+ - clr.w d1 - swap d1 - addx.w d4,d1 -ms16_even: - - move.w (a0)+,d0 - mulu.w d2,d0 - add.l d1,d0 - sub.w d0,(a1)+ - clr.w d0 - swap d0 - addx.w d4,d0 - - dbra d3,ms16_loop - - move.w (sp)+,d3 - move.w (sp)+,d4 - rts -ms16_short: - move.w (sp)+,d3 - move.l d1,d0 - move.w (sp)+,d4 - rts -} - -/* The generic long/short divide doesn't know that nh < d */ -asm BNWORD16 -lbnDiv21_16(BNWORD16 *q, BNWORD16 nh, BNWORD16 nl, BNWORD16 d) -{ - move.l 8(sp),d0 /* nh *and* nl */ - divu.w 12(sp),d0 - move.l 4(sp),a0 - move.w d0,(a0) - clr.w d0 - swap d0 - rts -} - -asm unsigned -lbnModQ_16(BNWORD16 const *n, unsigned len, BNWORD16 d) -{ - move.l 4(sp),a0 /* n */ - moveq.l #0,d1 -#if UINT_MAX == 0xffff - move.w 8(sp),d1 /* len */ - move.w 10(sp),d2 /* d */ -#else - move.w 10(sp),d1 /* len (low 16 bits) */ - move.w 12(sp),d2 /* d */ -#endif - - add.l d1,a0 - add.l d1,a0 /* n += len */ - moveq.l #0,d0 - subq.w #1,d1 - -mq16_loop: - move.w -(a0),d0 /* Assemble remainder and new word */ - divu.w d2,d0 /* Put remainder in high half of d0 */ - dbra d1,mq16_loop - -mq16_done: - clr.w d0 - swap d0 - rts -} - -/* - * Detect if this is a 32-bit processor (68020+ *or* CPU32). - * Both the 68020+ and CPU32 processors (which have 32x32->64-bit - * multiply, what the 32-bit math library wants) support scaled indexed - * addressing. The 68000 and 68010 ignore the scale selection - * bits, treating it as *1 all the time. So a 32-bit processor - * will evaluate -2(a0,a0.w*2) as 1+1*2-2 = 1. - * A 16-bit processor will compute 1+1-2 = 0. - * - * Thus, the return value will indicate whether the chip this is - * running on supports 32x32->64-bit multiply (mulu.l). - */ -asm int -is68020(void) -{ - machine 68020 - lea 1,a0 -#if 0 - lea -2(a0,a0.w*2),a0 /* Metrowerks won't assemble this, arrgh */ -#else - dc.w 0x41f0, 0x82fe -#endif - move.l a0,d0 - rts -} -/* - * Since I had to hand-assemble that fancy addressing mode, I had to study - * up on 680x0 addressing modes. - * A summary of 680x0 addressing modes. - * A 68000 effective address specifies an operand on an instruction, which - * may be a register or in memory. It is made up of a 3-bit mode and a - * 3-bit register specifier. The meanings of the various modes are: - * - * 000 reg - Dn, n specified by "reg" - * 001 reg - An, n specified by "reg" - * 010 reg - (An) - * 011 reg - (An)+ - * 100 reg - -(An) - * 101 reg - d16(An), one 16-bit displacement word follows, sign-extended - * 110 reg - Fancy addressing mode off of An, see extension word below - * 111 000 - abs.W, one 16-bit signed absolute address follows - * 111 001 - abs.L, one 32-bit absolute address follows - * 111 010 - d16(PC), one 16-bit displacemnt word follows, sign-extended - * 111 011 - Fancy addressing mode off of PC, see extension word below - * 111 100 - #immediate, followed by 16 or 32 bits of immediate value - * 111 101 - unused, reserved - * 111 110 - unused, reserved - * 111 111 - unused, reserved - * - * Memory references are to data space, except that PC-relative references - * are to program space, and are read-only. - * - * Fancy addressing modes are followed by a 16-bit extension word, and come - * in "brief" and "full" forms. - * The "brief" form looks like this. Bit 8 is 0 to indicate this form: - * - * 1 1 1 1 1 1 1 - * 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 - * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ - * |A/D| register |L/W| scale | 0 | 8-bit signed displacement | - * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ - * - * The basic effective address specifies a 32-bit base register - A0 through - * A7 or PC (the address of the following instruction). - * The A/D and register fields specify an index register. A/D is 1 for - * address registers, and 0 for data registers. L/W specifies the length - * of the index register, 1 for 32 bits, and 0 for 16 bits (sign-extended). - * The scale field is a left shift amount (0 to 3 bits) to apply to the - * sign-extended index register. The final address is d8(An,Rn.X*SCALE), - * also written (d8,An,Rn.X*SCALE). X is "W" or "L", SCALE is 1, 2, 4 or 8. - * "*1" may be omitted, as may a d8 of 0. - * - * The 68000 supports this form, but only with a scale field of 0. - * It does NOT (says the MC68030 User's Manual MC68030UM/AD, section 2.7) - * decode the scale field and the following format bit. They are treated - * as 0. - * I recall (I don't have the data book handy) that the CPU32 processor - * core used in the 683xx series processors supports variable scales, - * but only the brief extension word form. I suspect it decodes the - * format bit and traps if it is not zero, but I don't recall. - * - * The "full" form (680x0, x >= 2 processors only) looks like this: - * - * 1 1 1 1 1 1 1 - * 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 - * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ - * |A/D| register |L/W| scale | 1 | BS| IS|BD size| 0 | P |OD size| - * +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ - * - * The first 8 bits are interpreted the same way as in the brief form, - * except that bit 8 is set to 1 to indicate the full form. - * BS, Base Suppress, if set, causes a value of 0 to be used in place of - * the base register value. If this is set, the base register - * specified is irrelevant, except that if it is the PC, the fetch is - * still done from program space. The specifier "ZPC" can be used in - * place of "PC" in the effective address mnemonic to represent this - * case. - * IS, Index Suppress, if set, causes a value of 0 to be used in place - * of the scaled index register. In this case, the first 7 bits of the - * extension word are irrelevant. - * BD size specifies the base displacement size. A value of 00 - * in this field is illegal, while 01, 10 and 11 indicate that the - * extension word is followed by 0, 1 or 2 16-bit words of base displacement - * (zero, sign-extended to 32 bits, and most-significant word first, - * respectively) to add to the base register value. - * Bit 3 is unused. - * The P bit is the pre/post indexing bit, and only applies if an outer - * displacement is used. This is explained later. - * OD size specifies the size of an outer displacement. In the simple - * case, this field is set to 00 and the effective address is - * (disp,An,Rn.X*SCALE) or (disp,PC,Rn.X*SCALE). - * In this case the P bit must be 0. Any of those compnents may be - * suppressed, with a BD size of 01, the BS bit, or the IS bit. - * If the OD size is not 00, it encodes an outer displacement in the same - * manner as the BD size, and 0, 1 or 2 16-bit words of outer displacement - * follow the base displacement in the instruction stream. In this case, - * this is a double-indirect addressing mode. The base, base displacement, - * and possibly the index, specify a 32-bit memory word which holds a value - * which is fetched, and the outer displacement and possibly the index are - * added to produce the address of the operand. - * If the P bit is 0, this is pre-indexed, and the index value is added - * before the fetch of the indirect word, producing an effective address - * of ([disp,An,Rn.X*SCALE],disp). If the P bit is 1, the post-indexed case, - * the memory word is fectched from base+base displacement, then the index - * and outer displacement are added to compute the address of the operand. - * This effective address is written ([disp,An],Rn.X*SCALE,disp). - * (In both cases, "An" may also be "PC" or "ZPC".) - * Any of the components may be omitted. If the index is omitted (using the - * IS bit), the P bit is irrelevant, but must be written as 0. - * Thus, legal combinations of IS, P and OD size are: - * 0 0 00 - (disp,An,Rn.X*SCALE), also written disp(An,Rn.X*SCALE) - * 0 0 01 - ([disp,An,Rn.X*SCALE]) - * 0 0 10 - ([disp,An,Rn.X*SCALE],d16) - * 0 0 11 - ([disp,An,Rn.X*SCALE],d32) - * 0 1 01 - ([disp,An],Rn.X*SCALE) - * 0 1 10 - ([disp,An],Rn.X*SCALE,d16) - * 0 1 11 - ([disp,An],Rn.X*SCALE,d32) - * 1 0 00 - (disp,An), also written disp(An) - * 1 0 01 - ([disp,An]) - * 1 0 10 - ([disp,An],d16) - * 1 0 11 - ([disp,An],d32) - */ - -/* 45678901234567890123456789012345678901234567890123456789012345678901234567 */ diff --git a/usr/src/lib/libresolv2/common/cylink/lbn68000.h b/usr/src/lib/libresolv2/common/cylink/lbn68000.h deleted file mode 100644 index ebd667d177..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbn68000.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * lbn68000.h - 16-bit bignum primitives for the 68000 (or 68010) processors. - * - * These primitives use little-endian word order. - * (The order of bytes within words is irrelevant.) - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#define BN_LITTLE_ENDIAN 1 - -typedef unsigned short bnword16 -#define BNWORD16 bnword16 - -bnword16 lbnSub1_16(bnword16 *num, unsigned len, bnword16 borrow); -bnword16 lbnAdd1_16(bnword16 *num, unsigned len, bnword16 carry); -void lbnMulN1_16(bnword16 *out, bnword16 const *in, unsigned len, bnword16 k); -bnword16 -lbnMulAdd1_16(bnword16 *out, bnword16 const *in, unsigned len, bnword16 k); -bnword16 -lbnMulSub1_16(bnword16 *out, bnword16 const *in, unsigned len, bnword16 k); -bnword16 lbnDiv21_16(bnword16 *q, bnword16 nh, bnword16 nl, bnword16 d); -unsigned lbnModQ_16(bnword16 const *n, unsigned len, bnword16 d); - -int is68020(void); - -/* #define the values to exclude the C versions */ -#define lbnSub1_16 lbnSub1_16 -#define lbnAdd1_16 lbnAdd1_16 -#define lbnMulN1_16 lbnMulN1_16 -#define lbnMulAdd1_16 lbnMulAdd1_16 -#define lbnMulSub1_16 lbnMulSub1_16 -#define lbnDiv21_16 lbnDiv21_16 -#define lbnModQ_16 lbnModQ_16 - -/* Also include the 68020 definitions for 16/32 bit switching versions. */ -#include <lbn68020.h> diff --git a/usr/src/lib/libresolv2/common/cylink/lbn68020.c b/usr/src/lib/libresolv2/common/cylink/lbn68020.c deleted file mode 100644 index f3562a3463..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbn68020.c +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * lbn68020.c - 32-bit bignum primitives for the 68020+ (0r 683xx) processors. - * - * Copyright (c) 1995 Colin Plumb. All rights reserved. - * For licensing and other legal details, see the file legal.c. - * - * This was written for Metrowerks C, and while it should be reasonably - * portable, NOTE that Metrowerks lets a callee trash a0, a1, d0, d1, and d2. - * Some 680x0 compilers make d2 callee-save, so instructions to save it - * will have to be added. - * - * This code supports 16 or 32-bit ints, based on UINT_MAX. - * Regardless of UINT_MAX, only bignums up to 64K words (2 million bits) - * are supported. (68k hackers will recognize this as a consequence of - * using dbra.) - * - * These primitives use little-endian word order. - * (The order of bytes within words is irrelevant to this issue.) - * - * TODO: Schedule this for the 68040's pipeline. (When I get a 68040 manual.) - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <limits.h> - -#include "lbn.h" /* Should include lbn68020.h */ - -/* - * The Metrowerks C compiler (1.2.2) produces bad 68k code for the - * following input, which happens to be the inner loop of lbnSub1, - * so a few less than critical routines have been recoded in assembly - * to avoid the bug. (Optimizer on or off does not matter.) - * - * unsigned - * decrement(unsigned *num, unsigned len) - * { - * do { - * if ((*num++)-- != 0) - * return 0; - * } while (--len); - * return 1; - * } - */ -asm BNWORD32 -lbnSub1_32(BNWORD32 *num, unsigned len, BNWORD32 borrow) -{ - movea.l 4(sp),a0 /* num */ -#if UINT_MAX == 0xffff - move.l 10(sp),d0 /* borrow */ -#else - move.l 12(sp),d0 /* borrow */ -#endif - sub.l d0,(a0)+ - bcc done -#if UINT_MAX == 0xffff - move.w 8(sp),d0 /* len */ -#else - move.w 10(sp),d0 /* len */ -#endif - subq.w #2,d0 - bcs done -loop: - subq.l #1,(a0)+ - dbcc d0,loop -done: - moveq.l #0,d0 - addx.w d0,d0 - rts -} - -asm BNWORD32 -lbnAdd1_32(BNWORD32 *num, unsigned len, BNWORD32 carry) -{ - movea.l 4(sp),a0 /* num */ -#if UINT_MAX == 0xffff - move.l 10(sp),d0 /* carry */ -#else - move.l 12(sp),d0 /* carry */ -#endif - add.l d0,(a0)+ - bcc done -#if UINT_MAX == 0xffff - move.w 8(sp),d0 /* len */ -#else - move.w 10(sp),d0 /* len */ -#endif - subq.w #2,d0 - bcs done -loop: - addq.l #1,(a0)+ - dbcc d0,loop -done: - moveq.l #0,d0 - addx.w d0,d0 - rts -} - -asm void -lbnMulN1_32(BNWORD32 *out, BNWORD32 const *in, unsigned len, BNWORD32 k) -{ - machine 68020 - - movem.l d3-d5,-(sp) /* 12 bytes of extra data */ - moveq.l #0,d4 - move.l 16(sp),a1 /* out */ - move.l 20(sp),a0 /* in */ -#if UINT_MAX == 0xffff - move.w 24(sp),d5 /* len */ - move.l 26(sp),d2 /* k */ -#else - move.w 26(sp),d5 /* len */ - move.l 28(sp),d2 /* k */ -#endif - - move.l (a0)+,d3 /* First multiply */ - mulu.l d2,d1:d3 /* dc.w 0x4c02, 0x3401 */ - move.l d3,(a1)+ - - subq.w #1,d5 /* Setup for loop unrolling */ - lsr.w #1,d5 - bcs.s m32_even - beq.s m32_short - - subq.w #1,d5 /* Set up software pipeline properly */ - move.l d1,d0 - -m32_loop: - move.l (a0)+,d3 - mulu.l d2,d1:d3 /* dc.w 0x4c02, 0x3401 */ - add.l d0,d3 - addx.l d4,d1 - move.l d3,(a1)+ -m32_even: - - move.l (a0)+,d3 - mulu.l d2,d0:d3 /* dc.w 0x4c02, 0x3400 */ - add.l d1,d3 - addx.l d4,d0 - move.l d3,(a1)+ - - dbra d5,m32_loop - - move.l d0,(a1) - movem.l (sp)+,d3-d5 - rts -m32_short: - move.l d1,(a1) - movem.l (sp)+,d3-d5 - rts -} - - -asm BNWORD32 -lbnMulAdd1_32(BNWORD32 *out, BNWORD32 const *in, unsigned len, BNWORD32 k) -{ - machine 68020 - movem.l d3-d5,-(sp) /* 12 bytes of extra data */ - moveq.l #0,d4 - move.l 16(sp),a1 /* out */ - move.l 20(sp),a0 /* in */ -#if UINT_MAX == 0xffff - move.w 24(sp),d5 /* len */ - move.l 26(sp),d2 /* k */ -#else - move.w 26(sp),d5 /* len */ - move.l 28(sp),d2 /* k */ -#endif - - move.l (a0)+,d3 /* First multiply */ - mulu.l d2,d1:d3 /* dc.w 0x4c02, 0x3401 */ - add.l d3,(a1)+ - addx.l d4,d1 - - subq.w #1,d5 /* Setup for loop unrolling */ - lsr.w #1,d5 - bcs.s ma32_even - beq.s ma32_short - - subq.w #1,d5 /* Set up software pipeline properly */ - move.l d1,d0 - -ma32_loop: - move.l (a0)+,d3 - mulu.l d2,d1:d3 /* dc.w 0x4c02, 0x3401 */ - add.l d0,d3 - addx.l d4,d1 - add.l d3,(a1)+ - addx.l d4,d1 -ma32_even: - - move.l (a0)+,d3 - mulu.l d2,d0:d3 /* dc.w 0x4c02, 0x3400 */ - add.l d1,d3 - addx.l d4,d0 - add.l d3,(a1)+ - addx.l d4,d0 - - dbra d5,ma32_loop - - movem.l (sp)+,d3-d5 - rts -ma32_short: - move.l d1,d0 - movem.l (sp)+,d3-d5 - rts -} - - -asm BNWORD32 -lbnMulSub1_32(BNWORD32 *out, BNWORD32 const *in, unsigned len, BNWORD32 k) -{ - machine 68020 - movem.l d3-d5,-(sp) /* 12 bytes of extra data */ - moveq.l #0,d4 - move.l 16(sp),a1 /* out */ - move.l 20(sp),a0 /* in */ -#if UINT_MAX == 0xffff - move.w 24(sp),d5 /* len */ - move.l 26(sp),d2 /* k */ -#else - move.w 26(sp),d5 /* len */ - move.l 28(sp),d2 /* k */ -#endif - - move.l (a0)+,d3 /* First multiply */ - mulu.l d2,d1:d3 /* dc.w 0x4c02, 0x3401 */ - sub.l d3,(a1)+ - addx.l d4,d1 - - subq.w #1,d5 /* Setup for loop unrolling */ - lsr.w #1,d5 - bcs.s ms32_even - beq.s ms32_short - - subq.w #1,d5 /* Set up software pipeline properly */ - move.l d1,d0 - -ms32_loop: - move.l (a0)+,d3 - mulu.l d2,d1:d3 /* dc.w 0x4c02, 0x3401 */ - add.l d0,d3 - addx.l d4,d1 - sub.l d3,(a1)+ - addx.l d4,d1 -ms32_even: - - move.l (a0)+,d3 - mulu.l d2,d0:d3 /* dc.w 0x4c02, 0x3400 */ - add.l d1,d3 - addx.l d4,d0 - sub.l d3,(a1)+ - addx.l d4,d0 - - dbra d5,ms32_loop - - movem.l (sp)+,d3-d5 - rts - -ms32_short: - move.l d1,d0 - movem.l (sp)+,d3-d5 - rts -} - - -asm BNWORD32 -lbnDiv21_32(BNWORD32 *q, BNWORD32 nh, BNWORD32 nl, BNWORD32 d) -{ - machine 68020 - move.l 8(sp),d0 - move.l 12(sp),d1 - move.l 4(sp),a0 - divu.l 16(sp),d0:d1 /* dc.w 0x4c6f, 0x1400, 16 */ - move.l d1,(a0) - rts -} - -asm unsigned -lbnModQ_32(BNWORD32 const *n, unsigned len, unsigned d) -{ - machine 68020 - move.l 4(sp),a0 /* n */ - move.l d3,a1 -#if UINT_MAX == 0xffff - moveq.l #0,d2 - move.w 8(sp),d1 /* len */ - move.w 10(sp),d2 /* d */ -#else - move.w 10(sp),d1 /* len */ - move.l 12(sp),d2 /* d */ -#endif - dc.w 0x41f0, 0x1cfc /* lea -4(a0,d1.L*4),a0 */ - - /* First time, divide 32/32 - may be faster than 64/32 */ - move.l (a0),d3 - divul.l d2,d0:d3 /* dc.w 0x4c02, 0x3000 */ - subq.w #2,d1 - bmi mq32_done - -mq32_loop: - move.l -(a0),d3 - divu.l d2,d0:d3 /* dc.w 0x4c02,0x3400 */ - dbra d1,mq32_loop - -mq32_done: - move.l a1,d3 - rts -} - -/* 45678901234567890123456789012345678901234567890123456789012345678901234567 */ diff --git a/usr/src/lib/libresolv2/common/cylink/lbn68020.h b/usr/src/lib/libresolv2/common/cylink/lbn68020.h deleted file mode 100644 index 4aff67f5ed..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbn68020.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * lbn68020.h - 32-bit bignum primitives for the 68020 (or 683xx) processors. - * - * These primitives use little-endian word order. - * (The order of bytes within words is irrelevant.) - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#define BN_LITTLE_ENDIAN 1 - -typedef unsigned long bnword32 -#define BNWORD32 bnword32 - -bnword32 lbnSub1_32(bnword32 *num, unsigned len, bnword32 borrow); -bnword32 lbnAdd1_32(bnword32 *num, unsigned len, bnword32 carry); -void lbnMulN1_32(bnword32 *out, bnword32 const *in, unsigned len, bnword32 k); -bnword32 -lbnMulAdd1_32(bnword32 *out, bnword32 const *in, unsigned len, bnword32 k); -bnword32 -lbnMulSub1_32(bnword32 *out, bnword32 const *in, unsigned len, bnword32 k); -bnword32 lbnDiv21_32(bnword32 *q, bnword32 nh, bnword32 nl, bnword32 d); -unsigned lbnModQ_32(bnword32 const *n, unsigned len, unsigned d); - -/* #define the values to exclude the C versions */ -#define lbnSub1_32 lbnSub1_32 -#define lbnAdd1_32 lbnAdd1_32 -#define lbnMulN1_32 lbnMulN1_32 -#define lbnMulAdd1_32 lbnMulAdd1_32 -#define lbnMulSub1_32 lbnMulSub1_32 -#define lbnDiv21_32 lbnDiv21_32 -#define lbnModQ_32 lbnModQ_32 diff --git a/usr/src/lib/libresolv2/common/cylink/lbn80386.h b/usr/src/lib/libresolv2/common/cylink/lbn80386.h deleted file mode 100644 index 10e10e10a5..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbn80386.h +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * lbn80386.h - This file defines the interfaces to the 80386 - * assembly primitives. It is intended to be included in "lbn.h" - * via the "#include BNINCLUDE" mechanism. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#define BN_LITTLE_ENDIAN 1 - -typedef unsigned long bnword32; -#define BNWORD32 bnword32 - -/* MS-DOS needs the calling convention described to it. */ -#ifndef MSDOS -#ifdef __MSDOS__ -#define MSDOS 1 -#endif -#endif - -#ifdef MSDOS -#define CDECL __cdecl -#else -#define CDECL /*nothing*/ -#endif - -#ifdef __cplusplus -/* These assembly-language primitives use C names */ -extern "C" { -#endif - -/* Function prototypes for the asm routines */ -void CDECL -lbnMulN1_32(bnword32 *out, bnword32 const *in, unsigned len, bnword32 k); -#define lbnMulN1_32 lbnMulN1_32 - -bnword32 CDECL -lbnMulAdd1_32(bnword32 *out, bnword32 const *in, unsigned len, bnword32 k); -#define lbnMulAdd1_32 lbnMulAdd1_32 - -bnword32 CDECL -lbnMulSub1_32(bnword32 *out, bnword32 const *in, unsigned len, bnword32 k); -#define lbnMulSub1_32 lbnMulSub1_32 - -bnword32 CDECL -lbnDiv21_32(bnword32 *q, bnword32 nh, bnword32 nl, bnword32 d); -#define lbnDiv21_32 lbnDiv21_32 - -unsigned CDECL -lbnModQ_32(bnword32 const *n, unsigned len, bnword32 d); -#define lbnModQ_32 lbnModQ_32 - -#ifdef __cplusplus -} -#endif - - -#if __GNUC__ -/* - * Use the (massively cool) GNU inline-assembler extension to define - * inline expansions for various operations. - * - * The massively cool part is that the assembler can have inputs - * and outputs, and you specify the operands and which effective - * addresses are legal and they get substituted into the code. - * (For example, some of the code requires a zero. Rather than - * specify an immediate constant, the expansion specifies an operand - * of zero which can be in various places. This lets GCC use an - * immediate zero, or a register which contains zero if it's available.) - * - * The syntax is asm("asm_code" : outputs : inputs : trashed) - * %0, %1 and so on in the asm code are substituted by the operands - * in left-to-right order (outputs, then inputs). - * The operands contain constraint strings and values to use. - * Outputs must be lvalues, inputs may be rvalues. In the constraints: - * "a" means that the operand must be in eax. - * "d" means that the operand must be in edx. - * "g" means that the operand may be any effective address. - * "=" means that the operand is assigned to. - * "%" means that this operand and the following one may be - * interchanged if desirable. - * "bcDSmn" means that the operand must be in ebx, ecx, esi, edi, memory, - * or an immediate constant. (This is almost the same as "g" - * but allowing it in eax wouldn't help because x is already - * assigned there, and it must not be in edx, since edx is - * overwritten by the multiply before a and b are read.) - * - * Note that GCC uses AT&T assembler syntax, which is rather - * different from Intel syntax. The length (b, w or l) of the - * operation is appended to the opcode, and the *second* operand - * is the destination, not the first. Finally, the register names - * are all preceded with "%". (Doubled here because % is a - * magic character.) - */ - -/* (ph<<32) + pl = x*y */ -#define mul32_ppmm(ph,pl,x,y) \ - __asm__("mull %3" : "=d"(ph), "=a"(pl) : "%a"(x), "g"(y)) - -/* (ph<<32) + pl = x*y + a */ -#define mul32_ppmma(ph,pl,x,y,a) \ - __asm__("mull %3\n\t" \ - "addl %4,%%eax\n\t" \ - "adcl %5,%%edx" \ - : "=&d"(ph), "=a"(pl) \ - : "%a"(x), "g"(y), "bcDSmn"(a), "bcDSmn"(0)) - -/* (ph<<32) + pl = x*y + a + b */ -#define mul32_ppmmaa(ph,pl,x,y,a,b) \ - __asm__("mull %3\n\t" \ - "addl %4,%%eax\n\t" \ - "adcl %6,%%edx\n\t" \ - "addl %5,%%eax\n\t" \ - "adcl %6,%%edx" \ - : "=&d"(ph), "=a"(pl) \ - : "%a"(x), "g"(y), "%bcDSmn"(a), "bcDSmn"(b), "bcDSmn"(0)) - -/* q = ((nh<<32) + nl) / d, return remainder. nh guaranteed < d. */ -#undef lbnDiv21_32 -#define lbnDiv21_32(q,nh,nl,d) \ - ({unsigned _; \ - __asm__("divl %4" : "=d"(_), "=a"(*q) : "d"(nh), "a"(nl), "g"(d)); \ - _;}) - -/* No quotient, just return remainder ((nh<<32) + nl) % d */ -#define lbnMod21_32(nh,nl,d) \ - ({unsigned _; \ - __asm__("divl %3" : "=d"(_) : "d"(nh), "a"(nl), "g"(d) : "ax"); \ - _;}) - -#endif /* __GNUC__ */ diff --git a/usr/src/lib/libresolv2/common/cylink/lbn8086.h b/usr/src/lib/libresolv2/common/cylink/lbn8086.h deleted file mode 100644 index be9c2fab27..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbn8086.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * lbn8086.h - This file defines the interfaces to the 8086 - * assembly primitives for 16-bit MS-DOS environments. - * It is intended to be included in "lbn.h" - * via the "#include BNINCLUDE" mechanism. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#define BN_LITTLE_ENDIAN 1 - -#ifdef __cplusplus -/* These assembly-language primitives use C names */ -extern "C" { -#endif - -/* Set up the appropriate types */ -typedef unsigned short bnword16; -#define BNWORD16 bnword16 -typedef unsigned long bnword32; -#define BNWORD32 bnword32 - -void __cdecl __far -lbnMulN1_16(bnword16 __far *out, bnword16 const __far *in, - unsigned len, bnword16 k); -#define lbnMulN1_16 lbnMulN1_16 - -bnword16 __cdecl __far -lbnMulAdd1_16(bnword16 __far *out, bnword16 const __far *in, - unsigned len, bnword16 k); -#define lbnMulAdd1_16 lbnMulAdd1_16 - -bnword16 __cdecl __far -lbnMulSub1_16(bnword16 __far *out, bnword16 const __far *in, - unsigned len, bnword16 k); -#define lbnMulSub1_16 lbnMulSub1_16 - -bnword16 __cdecl __far -lbnDiv21_16(bnword16 __far *q, bnword16 nh, bnword16 nl, bnword16 d); -#define lbnDiv21_16 lbnDiv21_16 - -bnword16 __cdecl __far -lbnModQ_16(bnword16 const __far *n, unsigned len, bnword16 d); -#define lbnModQ_16 lbnModQ_16 - - - -void __cdecl __far -lbnMulN1_32(bnword32 __far *out, bnword32 const __far *in, - unsigned len, bnword32 k); -#define lbnMulN1_32 lbnMulN1_32 - -bnword32 __cdecl __far -lbnMulAdd1_32(bnword32 __far *out, bnword32 const __far *in, - unsigned len, bnword32 k); -#define lbnMulAdd1_32 lbnMulAdd1_32 - -bnword32 __cdecl __far -lbnMulSub1_32(bnword32 __far *out, bnword32 const __far *in, - unsigned len, bnword32 k); -#define lbnMulSub1_32 lbnMulSub1_32 - -bnword32 __cdecl __far -lbnDiv21_32(bnword32 __far *q, bnword32 nh, bnword32 nl, bnword32 d); -#define lbnDiv21_32 lbnDiv21_32 - -bnword16 __cdecl __far -lbnModQ_32(bnword32 const __far *n, unsigned len, bnword32 d); -#define lbnModQ_32 lbnModQ_32 - -int __cdecl __far not386(void); - -#ifdef __cplusplus -} -#endif diff --git a/usr/src/lib/libresolv2/common/cylink/lbnmem.c b/usr/src/lib/libresolv2/common/cylink/lbnmem.c deleted file mode 100644 index ebb44a2aae..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbnmem.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/* - * lbnmem.c - low-level bignum memory handling. - * - * Copyright (c) 1995 Colin Plumb. All rights reserved. - * For licensing and other legal details, see the file legal.c. - * - * Note that in all cases, the pointers passed around - * are pointers to the *least* significant end of the word. - * On big-endian machines, these are pointers to the *end* - * of the allocated range. - * - * BNSECURE is a simple level of security; for more security - * change these function to use locked unswappable memory. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "port_before.h" - -#ifndef HAVE_CONFIG_H -#define HAVE_CONFIG_H 0 -#endif -#if HAVE_CONFIG_H -#include "config.h" -#endif - -/* - * Some compilers complain about #if FOO if FOO isn't defined, - * so do the ANSI-mandated thing explicitly... - */ -#ifndef NO_STDLIB_H -#define NO_STDLIB_H 0 -#endif -#ifndef NO_STRING_H -#define NO_STRING_H 0 -#endif -#ifndef HAVE_STRINGS_H -#define HAVE_STRINGS_H 0 -#endif -#ifndef NEED_MEMORY_H -#define NEED_MEMORY_H 0 -#endif - -#if !NO_STDLIB_H -#include <stdlib.h> /* For malloc() & co. */ -#else -void *malloc(); -void *realloc(); -void free(); -#endif - -#if !NO_STRING_H -#include <string.h> /* For memset */ -#elif HAVE_STRINGS_H -#include <strings.h> -#endif -#if NEED_MEMORY_H -#include <memory.h> -#endif - -#ifndef DBMALLOC -#define DBMALLOC 0 -#endif -#if DBMALLOC -/* Development debugging */ -#include "../dbmalloc/malloc.h" -#endif - -#include "lbn.h" -#include "lbnmem.h" - -#include "kludge.h" - -#ifndef lbnMemWipe -void -lbnMemWipe(void *ptr, unsigned bytes) -{ - memset(ptr, 0, bytes); -} -#define lbnMemWipe(ptr, bytes) memset(ptr, 0, bytes) -#endif - -#ifndef lbnMemAlloc -void * -lbnMemAlloc(unsigned bytes) -{ - return malloc(bytes); -} -#define lbnMemAlloc(bytes) malloc(bytes) -#endif - -#ifndef lbnMemFree -void -lbnMemFree(void *ptr, unsigned bytes) -{ - lbnMemWipe(ptr, bytes); - free(ptr); -} -#endif - -#ifndef lbnRealloc -#if defined(lbnMemRealloc) || !BNSECURE -void * -lbnRealloc(void *ptr, unsigned oldbytes, unsigned newbytes) -{ - if (ptr) { - BIG(ptr = (char *)ptr - oldbytes;) - if (newbytes < oldbytes) - memmove(ptr, (char *)ptr + oldbytes-newbytes, oldbytes); - } -#ifdef lbnMemRealloc - ptr = lbnMemRealloc(ptr, oldbytes, newbytes); -#else - ptr = realloc(ptr, newbytes); -#endif - if (ptr) { - if (newbytes > oldbytes) - memmove((char *)ptr + newbytes-oldbytes, ptr, oldbytes); - BIG(ptr = (char *)ptr + newbytes;) - } - - return ptr; -} - -#else /* BNSECURE */ - -void * -lbnRealloc(void *oldptr, unsigned oldbytes, unsigned newbytes) -{ - void *newptr = lbnMemAlloc(newbytes); - - if (!newptr) - return newptr; - if (!oldptr) - return BIGLITTLE((char *)newptr+newbytes, newptr); - - /* - * The following copies are a bit non-obvious in the big-endian case - * because one of the pointers points to the *end* of allocated memory. - */ - if (newbytes > oldbytes) { /* Copy all of old into part of new */ - BIG(newptr = (char *)newptr + newbytes;) - BIG(oldptr = (char *)oldptr - oldbytes;) - memcpy(BIGLITTLE((char *)newptr-oldbytes, newptr), oldptr, - oldbytes); - } else { /* Copy part of old into all of new */ - memcpy(newptr, BIGLITTLE((char *)oldptr-newbytes, oldptr), - newbytes); - BIG(newptr = (char *)newptr + newbytes;) - BIG(oldptr = (char *)oldptr - oldbytes;) - } - - lbnMemFree(oldptr, oldbytes); - return newptr; -} -#endif /* BNSECURE */ -#endif /* !lbnRealloc */ diff --git a/usr/src/lib/libresolv2/common/cylink/lbnmem.h b/usr/src/lib/libresolv2/common/cylink/lbnmem.h deleted file mode 100644 index 8a86eeaf0e..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbnmem.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Operations on the usual buffers of bytes - */ -#ifndef BNSECURE -#define BNSECURE 1 -#endif - -/* - * These operations act on buffers of memory, just like malloc & free. - * One exception: it is not legal to pass a NULL pointer to lbnMemFree. - */ - -#ifndef lbnMemAlloc -void *lbnMemAlloc(unsigned bytes); -#endif - -#ifndef lbnMemFree -void lbnMemFree(void *ptr, unsigned bytes); -#endif - -/* This wipes out a buffer of bytes if necessary needed. */ - -#ifndef lbnMemWipe -#if BNSECURE -void lbnMemWipe(void *ptr, unsigned bytes); -#else -#define lbnMemWipe(ptr, bytes) (void)(ptr,bytes) -#endif -#endif /* !lbnMemWipe */ - -/* - * lbnRealloc is NOT like realloc(); it's endian-sensitive! - * If lbnMemRealloc is #defined, lbnRealloc will be defined in terms of it. - * It is legal to pass a NULL pointer to lbnRealloc, although oldbytes - * will always be sero. - */ -#ifndef lbnRealloc -void *lbnRealloc(void *ptr, unsigned oldbytes, unsigned newbytes); -#endif - - -/* - * These macros are the ones actually used most often in the math library. - * They take and return pointers to the *end* of the given buffer, and - * take sizes in terms of words, not bytes. - * - * Note that LBNALLOC takes the pointer as an argument instead of returning - * the value. - * - * Note also that these macros are only useable if you have included - * lbn.h (for the BIG and BIGLITTLE macros), which this file does NOT include. - */ - -#define LBNALLOC(p,words) BIGLITTLE( \ - if ( ((p) = lbnMemAlloc((words)*sizeof*(p))) != 0) (p) += (words), \ - (p) = lbnMemAlloc((words) * sizeof*(p)) \ - ) -#define LBNFREE(p,words) lbnMemFree((p) BIG(-(words)), (words) * sizeof*(p)) -#define LBNREALLOC(p,old,new) \ - lbnRealloc(p, (old) * sizeof*(p), (new) * sizeof*(p)) -#define LBNWIPE(p,words) lbnMemWipe((p) BIG(-(words)), (words) * sizeof*(p)) - diff --git a/usr/src/lib/libresolv2/common/cylink/lbnppc.c b/usr/src/lib/libresolv2/common/cylink/lbnppc.c deleted file mode 100644 index 15eef0e28e..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbnppc.c +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "lbnppc.h" - -/* - * lbnppc.c - Assembly primitives for the bignum library, PowerPC version. - * - * Copyright (c) 1995 Colin Plumb. All rights reserved. - * For licensing and other legal details, see the file legal.c - * - * Register usage during function calls is: - * r0 - volatile - * r1 - stack pointer, preserved - * r2 - TOC pointer, preserved - * r3 - First argument and return value register - * r4-r10 - More argument registers, volatile - * r11-r12 - Volatile - * r13-r31 - Preserved - * LR, CTR, XER and MQ are all volatile. - * LR holds return address on entry. - * - * On the PPC 601, unrolling the loops more doesn't seem to speed things - * up at all. I'd be curious if other chips differed. - */ -#if __MWERKS__ < 0x800 - -#include "ppcasm.h" /* PowerPC assembler */ - -/* - * MulN1 expects (*out, *in, len, k), count >= 1 - * r3 r4 r5 r6 - */ -static const unsigned mulN1[] = { - PPC_LWZ(7,4,0), /* Load first word of in in r7 */ - PPC_MULLW(8,7,6), /* Low half of multiply in r8 */ - PPC_MTCTR(5), /* Move len into CTR */ - PPC_ADDIC(0,0,0), /* Clear carry bit for loop */ - PPC_MULHWU(5,7,6), /* High half of multiply in r5 */ - PPC_STW(8,3,0), - PPC_BC(18,31,7), /* Branch to Label if --ctr == 0 */ -/* Loop: */ - PPC_LWZU(7,4,4), /* r7 = *++in */ - PPC_MULLW(8,7,6), /* r8 = low word of product */ - PPC_ADDE(8,8,5), /* Add carry word r5 and bit CF to r8 */ - PPC_STWU(8,3,4), /* *++out = r8 */ - PPC_MULHWU(5,7,6), /* r5 is high word of product, for carry word */ - PPC_BC(16,31,-5), /* Branch to Loop if --ctr != 0 */ -/* Label: */ - PPC_ADDZE(5,5), /* Add carry flag to r5 */ - PPC_STW(5,3,4), /* out[1] = r5 */ - PPC_BLR() -}; - -/* - * MulAdd1 expects (*out, *in, len, k), count >= 1 - * r3 r4 r5 r6 - */ -static unsigned const mulAdd1[] = { - PPC_LWZ(7,4,0), /* Load first word of in in r7 */ - PPC_LWZ(0,3,0), /* Load first word of out into r0 */ - PPC_MULLW(8,7,6), /* Low half of multiply in r8 */ - PPC_MTCTR(5), /* Move len into CTR */ - PPC_MULHWU(5,7,6), /* High half of multiply in r5 */ - PPC_ADDC(8,8,0), /* r8 = r8 + r0 */ - PPC_STW(8,3,0), /* Store result to memory */ - PPC_BC(18,31,10), /* Branch to Label if --ctr == 0 */ -/* Loop: */ - PPC_LWZU(7,4,4), /* r7 = *++in */ - PPC_LWZU(0,3,4), /* r0 = *++out */ - PPC_MULLW(8,7,6), /* r8 = low word of product */ - PPC_ADDE(8,8,5), /* Add carry word r5 and carry bit CF to r8 */ - PPC_MULHWU(5,7,6), /* r5 is high word of product, for carry word */ - PPC_ADDZE(5,5), /* Add carry bit from low add to r5 */ - PPC_ADDC(8,8,0), /* r8 = r8 + r0 */ - PPC_STW(8,3,0), /* *out = r8 */ - PPC_BC(16,31,-8), /* Branch to Loop if --ctr != 0 */ -/* Label: */ - PPC_ADDZE(3,5), /* Add carry flag to r5 and move to r3 */ - PPC_BLR() -}; - -/* - * MulSub1 expects (*out, *in, len, k), count >= 1 - * r3 r4 r5 r6 - * - * Multiply and subtract is rather a pain. If the subtract of the - * low word of the product from out[i] generates a borrow, we want to - * increment the carry word (initially in the range 0..0xfffffffe). - * However, the PPC's carry bit CF is *clear* after a subtract, so - * we want to add (1-CF) to the carry word. This is done using two - * instructions: - * - * SUBFME, subtract from minus one extended. This computes - * rD = ~rS + 0xffffffff + CF. Since rS is from 0 to 0xfffffffe, - * ~rS is from 1 through 0xffffffff, and the sum with 0xffffffff+CF is - * from 0 through 0xfffffffff, setting the carry flag unconditionally, and - * NOR, which is used as a bitwise invert NOT instruction. - * - * The SUBFME performs the computation rD = ~rS + 0xffffffff + CF, - * = (-rS - 1) + (CF - 1) = -(rS - CF + 1) - 1 = ~(rS + 1-CF), - * which is the bitwise complement of the value we want. - * We want to add the complement of that result to the low word of the - * product, which is just what a subtract would do, if only we could get - * the carry flag clear. But it's always set, except for SUBFE, and the - * operation we just performed unconditionally *sets* the carry flag. Ugh. - * So find the complement in a separate instruction. - */ -static unsigned const mulSub1[] = { - PPC_LWZ(7,4,0), /* Load first word of in in r7 */ - PPC_LWZ(0,3,0), /* Load first word of out into r0 */ - PPC_MTCTR(5), /* Move len into CTR */ - PPC_MULLW(8,7,6), /* Low half of multiply in r8 */ - PPC_MULHWU(5,7,6), /* High half of multiply in r5 */ - PPC_SUBFC(8,8,0), /* r8 = r0 - r8, setting CF */ - PPC_STW(8,3,0), /* Store result to memory */ - PPC_SUBFME(5,5), /* First of two insns to add (1-CF) to r5 */ - PPC_BC(18,31,12), /* Branch to Label if --ctr == 0 */ -/* Loop: */ - PPC_LWZU(7,4,4), /* r7 = *++in */ - PPC_LWZU(0,3,4), /* r0 = *++out */ - PPC_NOR(5,5,5), /* Second of two insns to add (1-CF) to r5 */ - PPC_MULLW(8,7,6), /* r8 = low word of product */ - PPC_ADDC(8,8,5), /* Add carry word r5 to r8 */ - PPC_MULHWU(5,7,6), /* r5 is high word of product, for carry word */ - PPC_ADDZE(5,5), /* Add carry bit from low add to r5 */ - PPC_SUBFC(8,8,0), /* r8 = r0 - r8, setting CF */ - PPC_STW(8,3,0), /* *out = r8 */ - PPC_SUBFME(5,5), /* First of two insns to add (1-CF) to r5 */ - PPC_BC(16,31,-10), /* Branch to Loop if --ctr != 0 */ -/* Label: */ - PPC_NOR(3,5,5), /* Finish adding (1-CF) to r5, store in r3 */ - PPC_BLR() -}; - -#if 0 -/* - * Args: BNWORD32 *n, BNWORD32 const *mod, unsigned mlen, BNWORD32 inv) - * r3 r4 r5 r6 - * r7, r8 and r9 are the triple-width accumulator. - * r0 and r10 are temporary registers. - * r11 and r12 are temporary pointers into n and mod, respectively. - * r2 (!) is another temporary register. - */ -static unsigned const montReduce[] = { - PPC_MTCTR(5), /* ??? */ - PPC_LWZ(7,3,0), /* Load low word of n into r7 */ - PPC_LWZ(10,4,0), /* Fetch low word of mod */ - PPC_MULLW(0,7,6), /* Invert r7 into r0 */ - PPC_STW(0,3,0), /* Store back for future use */ - PPC_MULHWU(8,10,7), /* Get high word of whatnot */ - PPC_MULLW(10,10,7), /* Get low word of it */ - PPC_ADDC(7,7,10), /* Add low word of product to r7 */ - PPC_ADDZE(8,8), /* Add carry to high word */ - PPC_ - - - PPC_MULHW(8,7,6), - PPC_ADDC(7,7,0), /* Add inverse back to r7 */ - PPC_ADDZE(8,8), - PPC_ - - PPC_LWZU( -/* Loop: */ - PPC_LWZU(0,11,4), - PPC_LWZU(10,23,-4), - PPC_MULLW(2,0,10), - PPC_ADDC(7,7,2), - PPC_MULHWU(0,0,10), - PPC_ADDE(8,8,0), - PPC_ADDZE(9,9), - PPC_BC(16,31,-7), /* Branch to Loop if --ctr != 0 */ - - PPC_ADDIC_(count,-1), - PPC_LWZU(0,x,4), - PPC_ADDC(0,7,0), - PPC_STW(0,x,0), - PPC_ADDZE(7,8), - PPC_ADDZE(8,9), - PPC_LI(9,0), - PPC_BC(xx,2,yy), - -}; -#endif - -/* - * Three overlapped transition vectors for three functions. - * A PowerPC transition vector for a (potentially) inter-module - * jump or call consists of two words, an instruction address - * and a Table Of Contents (TOC) pointer, which is loaded into - * r1. Since none of the routines here have global variables, - * they don't need a TOC pointer, so the value is unimportant. - * This array places an unintersting 32-bit value after each address. - */ -unsigned const * const lbnPPC_tv[] = { - mulN1, - mulAdd1, - mulSub1, - 0 -}; - -#else /* __MWERKS >= 0x800 */ - -/* - * MulN1 expects (*out, *in, len, k), count >= 1 - * r3 r4 r5 r6 - */ -asm void -lbnMulN1_32(register unsigned *out, register unsigned const *in, - register unsigned len, register unsigned k) -{ - lwz r7,0(in) /* Load first word of in in r7 */ - mtctr len /* Move len into CTR */ - mullw r8,r7,k /* Low half of multiply in r8 */ - addic r0,r0,0 /* Clear carry bit for loop */ - mulhwu len,r7,k /* High half of multiply in len */ - stw r8,0(out) /* *out = r8 */ - mulhwu len,r7,k /* len is high word of product, for carry */ - bdz- label /* Branch to Label if --ctr == 0 */ -loop: - lwzu r7,4(in) /* r7 = *++in */ - mullw r8,r7,k /* Low half of multiply in r8 */ - adde r8,r8,len /* Add carry word len and bit CF to r8 */ - stwu r8,4(out) /* *++out = r8 */ - mulhwu len,r7,k /* len is high word of product, for carry */ - bdnz+ loop /* Branch to Loop if --ctr != 0 */ -label: - addze len,len /* Add carry flag to carry word */ - stw len,4(out) - blr -} - -/* - * MulAdd1 expects (*out, *in, len, k), count >= 1 - * r3 r4 r5 r6 - */ -asm unsigned -lbnMulAdd1_32(register unsigned *out, register unsigned const *in, - register unsigned len, register unsigned k) -{ - lwz r7,0(in) /* Load first word of in in r7 */ - lwz r0,0(out) /* Load first word of out into r0 */ - mullw r8,r7,k /* Low half of multiply in r8 */ - mtctr len /* Move len into CTR */ - mulhwu len,r7,k /* High half of multiply in len */ - addc r8,r8,r0 /* r8 = r8 + r0 */ - stw r8,0(out) /* Store result to memory */ - bdz- label /* Branch to Label if --ctr == 0 */ -loop: - lwzu r7,4(in) /* r7 = *++in */ - lwzu r0,4(out) /* r0 = *++out */ - mullw r8,r7,k /* r8 = low word of product */ - adde r8,r8,len /* Add carry word len and carry bit CF to r8 */ - mulhwu len,r7,k /* len is high word of product, for carry */ - addze len,len /* Add carry bit from low add to r5 */ - addc r8,r8,r0 /* r8 = r8 + r0 */ - stw r8,0(out) /* *out = r8 */ - bdnz+ loop /* Branch to Loop if --ctr != 0 */ -label: - addze r3,r5 /* Add carry flag to r5 and move to r3 */ - blr -} - -/* - * MulSub1 expects (*out, *in, len, k), count >= 1 - * r3 r4 r5 r6 - * - * Multiply and subtract is rather a pain. If the subtract of the - * low word of the product from out[i] generates a borrow, we want to - * increment the carry word (initially in the range 0..0xfffffffe). - * However, the PPC's carry bit CF is *clear* after a subtract, so - * we want to add (1-CF) to the carry word. This is done using two - * instructions: - * - * SUBFME, subtract from minus one extended. This computes - * rD = ~rS + 0xffffffff + CF. Since rS is from 0 to 0xfffffffe, - * ~rS is from 1 through 0xffffffff, and the sum with 0xffffffff+CF is - * from 0 through 0xfffffffff, setting the carry flag unconditionally, and - * NOR, which is used as a bitwise invert NOT instruction. - * - * The SUBFME performs the computation rD = ~rS + 0xffffffff + CF, - * = (-rS - 1) + (CF - 1) = -(rS - CF + 1) - 1 = ~(rS + 1-CF), - * which is the bitwise complement of the value we want. - * We want to add the complement of that result to the low word of the - * product, which is just what a subtract would do, if only we could get - * the carry flag clear. But it's always set, except for SUBFE, and the - * operation we just performed unconditionally *sets* the carry flag. Ugh. - * So find the complement in a separate instruction. - */ -asm unsigned -lbnMulSub1_32(register unsigned *out, register unsigned const *in, - register unsigned len, register unsigned k) -{ - lwz r7,0(in) /* Load first word of in in r7 */ - lwz r0,0(out) /* Load first word of out into r0 */ - mtctr len /* Move len into CTR */ - mullw r8,r7,k /* Low half of multiply in r8 */ - mulhwu len,r7,k /* High half of multiply in len */ - subfc r8,r8,r0 /* r8 = r0 - r8, setting CF */ - stw r8,0(out) /* Store result to memory */ - subfme len,len /* First of two insns to add (1-CF) to len */ - bdz- label /* Branch to Label if --ctr == 0 */ -loop: - lwzu r7,4(in) /* r7 = *++in */ - lwzu r0,4(out) /* r0 = *++out */ - nor len,len,len /* Second of two insns to add (1-CF) to len */ - mullw r8,r7,k /* r8 = low word of product */ - addc r8,r8,len /* Add carry word len to r8 */ - mulhwu len,r7,k /* len is high word of product, for carry */ - addze len,len /* Add carry bit from low add to len */ - subfc r8,r8,r0 /* r8 = r0 - r8 */ - stw r8,0(out) /* *out = r8 */ - subfme len,len /* First of two insns to add (1-CF) to len */ - bdnz+ loop /* Branch to Loop if --ctr != 0 */ -label: - nor r3,r5,r5 /* Finish adding (1-CF) to len, store in r3 */ - blr -} - -#endif /* __MWERKS >= 0x800 */ -/* 45678901234567890123456789012345678901234567890123456789012345678901234567 */ diff --git a/usr/src/lib/libresolv2/common/cylink/lbnppc.h b/usr/src/lib/libresolv2/common/cylink/lbnppc.h deleted file mode 100644 index 1d9d6e5418..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/lbnppc.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#ifndef LBNPPC_H -#define LBNPPC_H -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Assembly-language routines for the Power PC processor. - * Annoyingly, the Power PC does not have 64/32->32 bit divide, - * so the C code should be reasonably fast. But it does have - * 32x32->64-bit multiplies, and these routines provide access - * to that. - * - * In versions of CodeWarrior before 8.0, there was no PPC assembler, - * so a kludged-up one in CPP is used. This requires casting an - * array of unsigneds to function pointer type, and a function pointer - * is not a pointer to the code, but rather a pointer to a (code,TOC) - * pointer pair which we fake up. - * - * CodeWarrior 8.0 supports PCC assembly, which is used directly. - */ - -/* - * Bignums are stored in arrays of 32-bit words, and the least - * significant 32-bit word has the lowest address, thus "little-endian". - * The C code is slightly more efficient this way, so unless the - * processor cares (the PowerPC, like most RISCs, doesn't), it is - * best to use BN_LITTLE_ENDIAN. - * Note that this has NOTHING to do with the order of bytes within a 32-bit - * word; the math library is insensitive to that. - */ -#define BN_LITTLE_ENDIAN 1 - -typedef unsigned bnword32; -#define BNWORD32 bnword32 - -#if __MWERKS__ < 0x800 - -/* Shared transition vector array */ -extern unsigned const * const lbnPPC_tv[]; - -/* A function pointer on the PowerPC is a pointer to a transition vector */ -#define lbnMulN1_32 \ -((void (*)(bnword32 *, bnword32 const *, unsigned, bnword32))(lbnPPC_tv+0)) -#define lbnMulAdd1_32 \ -((bnword32 (*)(bnword32 *, bnword32 const *, unsigned, bnword32))(lbnPPC_tv+1)) -#define lbnMulSub1_32 \ -((bnword32 (*)(bnword32 *, bnword32 const *, unsigned, bnword32))(lbnPPC_tv+2)) - -#else /* __MWERKS__ >= 0x800 */ - -void lbnMulN1_32(bnword32 *, bnword32 const *, unsigned, bnword32); -#define lbnMulN1_32 lbnMulN1_32 -bnword32 lbnMulAdd1_32(bnword32 *, bnword32 const *, unsigned, bnword32); -#define lbnMulAdd1_32 lbnMulAdd1_32 -bnword32 lbnMulSub1_32(bnword32 *, bnword32 const *, unsigned, bnword32); -#define lbnMulSub1_32 lbnMulSub1_32 - -#endif /* __MWERKS__ >= 0x800 */ - -#endif /* LBNPPC_H */ diff --git a/usr/src/lib/libresolv2/common/cylink/legal.c b/usr/src/lib/libresolv2/common/cylink/legal.c deleted file mode 100644 index 09447c8d3c..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/legal.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Force inclusion of this... */ -#include "legal.h" -volatile const char bnCopyright[] = - "bnlib 1.0.1 Copyright (c) 1995,1996 Colin Plumb."; diff --git a/usr/src/lib/libresolv2/common/cylink/legal.h b/usr/src/lib/libresolv2/common/cylink/legal.h deleted file mode 100644 index 49c7c163bd..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/legal.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * ANSI C standard, section 3.5.3: "An object that has volatile-qualified - * type may be modified in ways unknown to the implementation or have - * other unknown side effects." Yes, we can't expect a compiler to - * understand law... - */ -extern volatile const char bnCopyright[]; diff --git a/usr/src/lib/libresolv2/common/cylink/math.c b/usr/src/lib/libresolv2/common/cylink/math.c deleted file mode 100644 index 4c7b0e6a5e..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/math.c +++ /dev/null @@ -1,1158 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/**************************************************************************** -* FILENAME: math.c PRODUCT NAME: CRYPTOGRAPHIC TOOLKIT -* -* FILE STATUS: -* -* DESCRIPTION: Math Routines for the ToolKit -* -* PUBLIC FUNCTIONS: -* -* int Sum_big (ord *X, -* ord *Y, -* ord *Z, -* u_int16_t len_X ) -* -* int Sub_big (ord *X, -* ord *Y, -* ord *Z, -* u_int16_t len_X ) -* -* void Mul_big( ord *X, ord *Y,ord *XY, -* u_int16_t lx, u_int16_t ly) -* -* -* PRIVATE FUNCTIONS: -* -* REVISION HISTORY: -* -* 14 Oct 94 GKL Initial release -* 26 Oct 94 GKL (alignment for big endian support ) -* -****************************************************************************/ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/**************************************************************************** -* INCLUDE FILES -****************************************************************************/ -/* bn files */ -#include "port_before.h" -#include "bn.h" -/* system files */ -#ifdef VXD -#include <vtoolsc.h> -#else -#include <stdlib.h> -#include <string.h> -#endif -/* program files */ -#include "cylink.h" -#include "ctk_endian.h" -#include "toolkit.h" -#include "port_after.h" - -/**************************************************************************** -* NAME: void BigNumInit( void ) -* -* -* DESCRIPTION: Initialize BigNum -* -* INPUTS: -* PARAMETERS: -* OUTPUT: -* PARAMETERS: -* -* RETURN: -* -* -* REVISION HISTORY: -* -* 29 Sep 96 Initial release -* -****************************************************************************/ - -void BigNumInit() -{ -static int bignuminit = 0; -if(!bignuminit){ - bnInit(); - bignuminit = 1; - } -} -/**************************************************************************** -* NAME: int Sum_big (ord *X, -* ord *Y, -* ord *Z, -* u_int16_t len_X ) -* -* DESCRIPTION: Compute addition. -* -* INPUTS: -* PARAMETERS: -* ord *X Pointer to first array -* ord *Y Pointer to second array -* int len_X Number of longs in X_l -* OUTPUT: -* PARAMETERS: -* ord *Z Pointer to result arrray -* -* RETURN: -* Carry bit -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - - int Sum_big (ord *X, - ord *Y, - ord *Z, - u_int16_t len_X ) -{ - -struct BigNum src2,temp_bn; -ord *temp; -BigNumInit(); - -/*bnInit(); -bnBegin(&src2); -bnBegin(&temp_bn); -*/ -temp = (ord *) malloc((len_X*sizeof(ord)) + sizeof(ord)); -temp_bn.size = len_X; -temp_bn.ptr = temp; -temp_bn.allocated = len_X + 1; - -src2.ptr = Y; -src2.size = len_X; -src2.allocated = len_X; - -memcpy(temp,X,len_X*sizeof(ord)); -bnAdd(&temp_bn,&src2); -memcpy(Z,temp_bn.ptr,len_X*sizeof(ord)); -/*bn package increments the size of dest by 1 if the carry bit is 1*/ -free(temp); -if (temp_bn.size > len_X) - return 1; -else - return 0; -} - - int Sum (ord *X, ord *Y, u_int16_t len_X ) -{ - -struct BigNum dest,src; -/*ord *temp;*/ -BigNumInit(); -#if 0 -bnInit(); -bnBegin(&src2); -bnBegin(&temp_bn); - -temp = (ord *) malloc((len_X*sizeof(ord)) + sizeof(ord)); -temp_bn.size = len_X; -temp_bn.ptr = temp; -temp_bn.allocated = len_X + 1; -#endif - -dest.ptr = X; -dest.size = len_X-1; -dest.allocated = len_X; - -src.ptr = Y; -src.size = len_X; -src.allocated = len_X; - -/*memcpy(temp,X,len_X*sizeof(ord));*/ -bnAdd(&dest,&src); -/*memcpy(Z,temp_bn.ptr,len_X*sizeof(ord));*/ -/*bn package increments the size of dest by 1 if the carry bit is 1*/ -/*free(temp);*/ -if (dest.size > (u_int16_t)(len_X -1)) - return 1; -else - return 0; -} - - -/**************************************************************************** -* NAME: int Sum_Q(ord *X, -* u_int16_t src, -* u_int16_t len_X ) -* DESCRIPTION: Compute addition X += src. -* -* INPUTS: -* PARAMETERS: -* ord *X Pointer to first array -* u_int16_t src Second operand must be <65535 -* int len_X Number of ords in X_l -* OUTPUT: -* PARAMETERS: -* ord *X Pointer to result arrray -* -* RETURN: -* SUCCESS or -1 -* -* REVISION HISTORY: -* -* 21 Sep 96 AAB Initial release -****************************************************************************/ - int Sum_Q(ord *X, u_int16_t src, u_int16_t len_X ) - { - int status = SUCCESS; - struct BigNum des; - BigNumInit(); - /*bnInit();*/ - des.ptr = X; - des.size = len_X; - des.allocated = len_X; - status = bnAddQ(&des, src); - return status; - } - - -/**************************************************************************** -* NAME: int Sub_big (ord *X, -* ord *Y, -* ord *Z, -* u_int16_t len_X ) -* -* -* DESCRIPTION: Compute subtraction. -* -* INPUTS: -* PARAMETERS: -* ord *X Pointer to first array -* ord *Y Pointer to second array -* u_int16_t len_X Number of longs in X_l -* OUTPUT: -* PARAMETERS: -* ord *Z Pointer to result arrray -* -* RETURN: -* Carry bit -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - -int Sub_big (ord *X, - ord *Y, - ord *Z, - u_int16_t len_X ) -{ -/* carry is not returned in bn version */ -struct BigNum dest, src; -int status; -ord *temp; -BigNumInit(); -/*bnInit(); -bnBegin(&dest); -bnBegin(&src); -*/ -src.ptr = Y; -src.size = len_X; -src.allocated = len_X; - -temp = (ord*)malloc(len_X*sizeof(ord)); -dest.ptr = temp; -dest.size = len_X; -dest.allocated = len_X; -memcpy(dest.ptr,X,len_X*sizeof(ord)); - -status = bnSub(&dest,&src); -memcpy(Z,dest.ptr,len_X*sizeof(ord)); -free(temp); -return status; -} - -#if 0 -/**************************************************************************** -* NAME: void Mul_big( ord *X, ord *Y, ord *XY, -* u_int16_t lx, u_int16_t ly) -* -* -* -* DESCRIPTION: Compute a product. -* -* INPUTS: -* PARAMETERS: -* ord *X Pointer to first long array -* ord *Y Pointer to second long array -* u_int16_t lx Leftmost non zero element of first array -* u_int16_t ly Leftmost non zero element of second array -* OUTPUT: -* PARAMETERS: -* ord *XY Pointer to result -* -* RETURN: -* -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* 08 Sep 95 AAB Comment out calloc and discard the elements_in_X, -* elements_in_Y -****************************************************************************/ -void Mul_big( ord *X, ord *Y, ord *XY, - u_int16_t lx, u_int16_t ly ) -{ -struct BigNum dest, src1, src2; -BigNumInit(); -/*bnInit();*/ -bnBegin(&dest); -/* -bnBegin(&src1); -bnBegin(&src2); -*/ -src1.size = lx + 1; -src1.ptr = X; -src1.allocated = lx + 1; - -src2.ptr = Y; -src2.size = ly + 1; -src2.allocated = ly + 1; - -dest.ptr = XY; -dest.size = lx + ly + 2; -dest.allocated = lx + ly + 2; - -/* Call bn routine */ -bnMul(&dest, &src1,&src2); -} - -#endif -/**************************************************************************** -* NAME: void Mul_big_1( ord X, ord *Y, ord *XY, -* u_int16_t lx, u_int16_t ly ) -* -* -* -* DESCRIPTION: Compute a product. -* -* INPUTS: -* PARAMETERS: -* ord X Number -* ord *Y Pointer to long array -* u_int16_t ly Leftmost non zero element of second array -* OUTPUT: -* PARAMETERS: -* ord *XY Pointer to result -* -* RETURN: -* -* -* REVISION HISTORY: -* -* 08 Oct 95 AAB Initial relaese -* -****************************************************************************/ -void Mul_big_1( ord X, ord *Y, ord *XY, - u_int16_t ly ) -{ -struct BigNum dest, src; -BigNumInit(); -/*bnInit(); -bnBegin(&dest); -bnBegin(&src); -*/ -src.ptr = Y; -src.size = ly + 1; -src.allocated = ly + 1; - -dest.ptr = XY; -dest.size = ly + 2; -dest.allocated = ly + 2; - -bnMulQ(&dest, &src, (unsigned)X); - -} - -/**************************************************************************** -* NAME: int Mul( u_int16_t X_bytes, -* ord *X, -* u_int16_t Y_bytes, -* ord *Y, -* u_int16_t P_bytes, -* ord *P, -* ord *Z ) -* -* DESCRIPTION: Compute a modulo product -* -* INPUTS: -* PARAMETERS: -* ord *X Pointer to first operand -* u_int16_t X_bytes Number of bytes in X -* ord *Y Pointer to second operand -* u_int16_t Y_bytes Number of bytes in Y -* ord *P Pointer to modulo -* u_int16_t P_bytes Number of bytes in P -* -* OUTPUT: -* PARAMETERS: -* ord *Z Pointer to result -* -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data (zero bytes) -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - -int Mul( u_int16_t X_bytes, - ord *X, - u_int16_t Y_bytes, - ord *Y, - u_int16_t P_bytes, - ord *P, - ord *Z ) - -{ - int status = SUCCESS; /*function return status*/ - u_int16_t X_longs; /*number of longs in X*/ - u_int16_t Y_longs; /*number of longs in Y*/ - ord *XY; /*pointer to product (temporary)*/ - - -struct BigNum dest, src1,src2, mod; -BigNumInit(); -/*bnInit(); -bnBegin(&dest); -bnBegin(&src1); -bnBegin(&src2); -bnBegin(&mod); -*/ - -src1.size = X_bytes/sizeof(ord); -src1.ptr = X; -src1.allocated = X_bytes/sizeof(ord); - -src2.size = Y_bytes/sizeof(ord); -src2.ptr = Y; -src2.allocated =Y_bytes/sizeof(ord); - -mod.size = P_bytes/sizeof(ord); -mod.ptr = P; -mod.allocated = P_bytes/sizeof(ord); - - if ( P_bytes == 0 || X_bytes == 0 || Y_bytes == 0 ) - { - status = ERR_INPUT_LEN; - return status; - } - if ( (X_bytes % sizeof(ord) != 0) || - (Y_bytes % sizeof(ord) != 0) || - (P_bytes % sizeof(ord) != 0) ) - { - status = ERR_INPUT_LEN; - return status; - } - X_longs = (u_int16_t) (X_bytes / sizeof(ord)); - Y_longs = (u_int16_t) (Y_bytes / sizeof(ord)); - XY = (ord *)calloc( X_longs + Y_longs, sizeof(ord) ); - if( !XY ) - { - return ERR_ALLOC; - } -dest.size = X_longs + Y_longs; -dest.ptr = XY; -dest.allocated = X_longs + Y_longs; - -bnMul (&dest,&src1,&src2); - -status = bnMod(&dest, &dest, &mod); -memcpy(Z, dest.ptr, P_bytes); -free( XY ); - return status; -} - -/**************************************************************************** -* NAME: int Square( u_int16_t X_bytes, -* ord *X, -* u_int16_t P_bytes, -* ord *P, -* ord *Z ) -* -* DESCRIPTION: Compute a modulo square -* -* INPUTS: -* PARAMETERS: -* ord *X Pointer to array to be squared -* u_int16_t X_bytes Number of bytes in X -* ord *P Pointer to modulo -* u_int16_t P_bytes Number of bytes in P -* -* OUTPUT: -* PARAMETERS: -* ord *Z Pointer to result -* -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data (zero bytes) -* -* REVISION HISTORY: -* -* 1 Sep 95 AAB Initial release -****************************************************************************/ - -int Square( u_int16_t X_bytes, - ord *X, - u_int16_t P_bytes, - ord *P, - ord *Z ) - -{ - int status = SUCCESS; /*function return status*/ - -ord *XY; -struct BigNum dest, src, mod; -BigNumInit(); -/*bnInit(); -bnBegin(&dest); -bnBegin(&src); -bnBegin(&mod); -*/ - if ( P_bytes == 0 || X_bytes == 0 ) - { - status = ERR_INPUT_LEN; - return status; - } - if ( (X_bytes % sizeof(ord) != 0) || - (P_bytes % sizeof(ord) != 0) ) - { - status = ERR_INPUT_LEN; - return status; - } - XY = (ord *)malloc( 2*X_bytes ); - if( !XY ) - { - return ERR_ALLOC; - } - -src.size = X_bytes/sizeof(ord); -src.ptr = X; -src.allocated = X_bytes/sizeof(ord); - -dest.size = 2*X_bytes/sizeof(ord); -dest.ptr = XY; -dest.allocated = 2*X_bytes/sizeof(ord); - -mod.size = P_bytes/sizeof(ord); -mod.ptr = P; -mod.allocated = P_bytes/sizeof(ord); - -status = bnSquare(&dest, &src); -status = bnMod(&dest, &dest, &mod); -memcpy(Z, dest.ptr, P_bytes); -free(XY); -return status; -} - - -/**************************************************************************** -* NAME: int PartReduct( u_int16_t X_bytes, -* ord *X, -* u_int16_t P_bytes, -* ord *P, -* ord *Z ) -* -* DESCRIPTION: Compute a modulo -* -* INPUTS: -* PARAMETERS: -* ord *X Pointer to array -* u_int16_t X_bytes Number of bytes in X -* ord *P Pointer to modulo -* u_int16_t P_bytes Number of bytes in P -* -* OUTPUT: -* PARAMETERS: -* ord *Z Pointer to result -* -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data (zero bytes) -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - -int PartReduct( u_int16_t X_bytes, - ord *X, - u_int16_t P_bytes, - ord *P, - ord *Z ) -{ - int status = SUCCESS; /*function return status */ - - -struct BigNum dest, /*src,*/ d; -ord *temp; -BigNumInit(); -/*bnInit(); -bnBegin(&dest); -bnBegin(&src); -bnBegin(&d); - -src.size = X_bytes/sizeof(ord); -src.ptr = X; -src.allocated = X_bytes/sizeof(ord); -*/ -d.size = P_bytes/sizeof(ord); -d.ptr = P; -d.allocated = P_bytes/sizeof(ord); - -temp = (ord*)malloc(X_bytes); -dest.size = X_bytes/sizeof(ord); -dest.ptr = temp; -dest.allocated = X_bytes/sizeof(ord); -memcpy(dest.ptr, X, X_bytes); - -status = bnMod(&dest, &dest, &d); - -memcpy(Z, dest.ptr, P_bytes); -free(temp); - -return status; - -} - -/**************************************************************************** -* NAME: int Expo( u_int16_t X_bytes, -* ord *X, -* u_int16_t Y_bytes, -* ord *Y, -* u_int16_t P_bytes, -* ord *P, -* ord *Z, -* YIELD_context *yield_cont ) -* -* DESCRIPTION: Compute a modulo exponent -* -* INPUTS: -* PARAMETERS: -* ord *X Pointer to base array -* u_int16_t X_bytes Number of bytes in base -* ord *Y Pointer to exponent array -* u_int16_t Y_bytes Number of bytes in exponent -* ord *P Pointer to modulo -* u_int16_t P_bytes Number of bytes in P -* YIELD_context *yield_cont Pointer to yield_cont structure (NULL if not used) -* -* OUTPUT: -* PARAMETERS: -* ord *Z Pointer to result -* -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data(zero bytes) -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* 08 Dec 94 GKL Added YIELD_context -* 01 Sep 95 Fast exponentation algorithm -****************************************************************************/ - -int Expo( u_int16_t X_bytes, ord *X, - u_int16_t Y_bytes, ord *Y, - u_int16_t P_bytes, ord *P, - ord *Z ) -{ - -int status = SUCCESS; /*function return status*/ - -struct BigNum dest, n, exp, mod; -BigNumInit(); -#if 0 -/*bnInit();*/ -bnBegin(&dest); -bnBegin(&n); -bnBegin(&exp); -bnBegin(&mod); -#endif - -n.size = X_bytes/sizeof(ord); -n.ptr = X; -n.allocated = X_bytes/sizeof(ord); - -exp.ptr = Y; -exp.size = Y_bytes/sizeof(ord); -exp.allocated = Y_bytes/sizeof(ord); - -mod.ptr = P; -mod.size = P_bytes/sizeof(ord); -mod.allocated = P_bytes/sizeof(ord); - -dest.ptr = Z; -dest.size = P_bytes/sizeof(ord); -dest.allocated = P_bytes/sizeof(ord); - -/* Call bn routine */ - -status = bnExpMod(&dest, &n, - &exp, &mod); - -return status; -} - - -/**************************************************************************** -* NAME: int DoubleExpo( u_int16_t X1_bytes, -* ord *X1, -* u_int16_t Y1_bytes, -* ord *Y1, -* u_int16_t X2_bytes, -* ord *X2, -* u_int16_t Y2_bytes, -* ord *Y2, -* u_int16_t P_bytes, -* ord *P, -* ord *Z) -* -* DESCRIPTION: Compute a modulo exponent -* -* INPUTS: -* PARAMETERS: -* ord *X1 Pointer to first base array -* u_int16_t X1_bytes Number of bytes in first base -* ord *Y1 Pointer to first exponent array -* u_int16_t Y1_bytes Number of bytes in first exponent -* ord *X2 Pointer to second base array -* u_int16_t X2_bytes Number of bytes in second base -* ord *Y2 Pointer to second exponent array -* u_int16_t Y2_bytes Number of bytes in second exponent ord *P Pointer to modulo -* ord *P Pointer to modulo -* u_int16_t P_bytes Number of bytes in -* -* OUTPUT: -* PARAMETERS: -* ord *Z Pointer to result -* -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data(zero bytes) -* -* REVISION HISTORY: -* -* 21 Aug 96 AAB Initial release -****************************************************************************/ - - -int DoubleExpo( u_int16_t X1_bytes,ord *X1, - u_int16_t Y1_bytes,ord *Y1, - u_int16_t X2_bytes,ord *X2, - u_int16_t Y2_bytes,ord *Y2, - u_int16_t P_bytes,ord *P, - ord *Z) -{ -int status = SUCCESS; /*function return status*/ -struct BigNum res, n1, e1, n2, e2, mod; -BigNumInit(); - -n1.size = X1_bytes/sizeof(ord); -n1.ptr = X1; -n1.allocated = X1_bytes/sizeof(ord); - -e1.size = Y1_bytes/sizeof(ord); -e1.ptr = Y1; -e1.allocated = Y1_bytes/sizeof(ord); - -n2.size = X2_bytes/sizeof(ord); -n2.ptr = X2; -n2.allocated = X2_bytes/sizeof(ord); - -e2.size = Y2_bytes/sizeof(ord); -e2.ptr = Y2; -e2.allocated = Y2_bytes/sizeof(ord); - -mod.ptr = P; -mod.size = P_bytes/sizeof(ord); -mod.allocated = P_bytes/sizeof(ord); - -res.ptr = Z; -res.size = P_bytes/sizeof(ord); -res.allocated = P_bytes/sizeof(ord); -status = bnDoubleExpMod(&res, &n1, &e1, &n2, &e2, &mod); -return status; -} - -/**************************************************************************** -* NAME: int Inverse( u_int16_t X_bytes, -* ord *X, -* u_int16_t P_bytes, -* ord *P, -* ord *Z ) -* -* -* -* -* DESCRIPTION: Compute a modulo inverse element -* -* INPUTS: -* PARAMETERS: -* ord *X Pointer to array -* u_int16_t X_bytes Number of bytes in array -* ord *P Pointer to modulo -* u_int16_t P_bytes Number of bytes in P -* -* OUTPUT: -* PARAMETERS: -* ord *Z Pointer to result -* -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data(zero bytes) -* ERR_INPUT_VALUE Invalid input value -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* 08 Nov 94 GKL Added input parameters check -* 01 Sep 95 Improve fuction -****************************************************************************/ - -int Inverse( u_int16_t X_bytes, - ord *X, - u_int16_t P_bytes, - ord *P, - ord *Z ) -{ -int status = SUCCESS; /* function return status */ - -struct BigNum dest, src, mod; -BigNumInit(); -/*bnInit(); -bnBegin(&dest); -bnBegin(&src); -bnBegin(&mod); -*/ -src.size = X_bytes/sizeof(ord); -src.ptr = X; -src.allocated = X_bytes/sizeof(ord); - -mod.ptr = P; -mod.size = P_bytes/sizeof(ord); -mod.allocated = P_bytes/sizeof(ord); - -dest.ptr = Z; -dest.size = (P_bytes/sizeof(ord)) ; -dest.allocated = (P_bytes/sizeof(ord)) + 1; -status = bnInv(&dest,&src,&mod); -return status; -} - - -/**************************************************************************** -* NAME: void Add( ord *X, -* ord *Y, -* u_int16_t P_len, -* ord *P, -* ord *Z ) - -* -* DESCRIPTION: Compute modulo addition -* -* INPUTS: -* PARAMETERS: -* ord *X Pointer to first operand -* ord *Y Pointer to second operand -* u_int16_t P_len Length of modulo -* ord *P Pointer to modulo -* OUTPUT: -* ord *Z Pointer to result -* RETURN: -* -* REVISION HISTORY: -* -* 24 sep 94 KPZ Initial release -* 10 Oct 94 KPZ Fixed bugs -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - /* - int Add( ord *X, - ord *Y, - u_int16_t P_len, - ord *P, - ord *Z ) -{ - int status = SUCCESS; - ord *temp; - struct BigNum dest, src, mod; - -bnInit(); -bnBegin(&dest); -bnBegin(&src); -bnBegin(&mod); - -temp = (ord*)malloc(P_len + sizeof(ord)); -memcpy(temp, X, P_len); - -dest.size = P_len/sizeof(ord); -dest.ptr = temp; -dest.allocated = P_len/sizeof(ord) + 1; - -src.ptr = Y; -src.size = P_len/sizeof(ord); -src.allocated = P_len/sizeof(ord); - -mod.ptr = P; -mod.size = P_len/sizeof(ord); -mod.allocated = P_len/sizeof(ord); - -status = bnAdd(&dest,&src); -status = bnMod(&dest,&dest,&mod); -memcpy(Z,temp,P_len); -free(temp); -return status; -} - */ - int Add( ord *X, - ord *Y, - u_int16_t P_len, - ord *P) -{ - int status = SUCCESS; -/* ord *temp;*/ - struct BigNum dest, src, mod; - -BigNumInit(); -/*bnInit(); -bnBegin(&dest); -bnBegin(&src); -bnBegin(&mod); -*/ -/* -temp = (ord*)malloc(P_len + sizeof(ord)); -memcpy(temp, X, P_len); -*/ -dest.size = P_len/sizeof(ord); -/*dest.ptr = temp;*/ -dest.ptr = X; -dest.allocated = P_len/sizeof(ord) + 1; - -src.ptr = Y; -src.size = P_len/sizeof(ord); -src.allocated = P_len/sizeof(ord); - -mod.ptr = P; -mod.size = P_len/sizeof(ord); -mod.allocated = P_len/sizeof(ord); - -status = bnAdd(&dest,&src); -status = bnMod(&dest,&dest,&mod); -/* -memcpy(Z,temp,P_len); -free(temp); -*/ -return status; -} - - - - -/**************************************************************************** -* NAME: int SteinGCD( ord *m, -* ord *b -* u_int16_t len ) -* -* DESCRIPTION: Compute great common divisor -* -* INPUTS: -* PARAMETERS: -* ord *m Pointer to first number -* ord *b Pointer to second number -* u_int16_t len Number of elements in number -* OUTPUT: -* -* RETURN: -* TRUE if gcd != 1 -* FALSE if gcd == 1 -* REVISION HISTORY: -* -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* 01 Sep 95 AAB Speed up -* -****************************************************************************/ - - -/* test if GCD equal 1 */ -int SteinGCD ( ord *m, - ord *n, - u_int16_t len ) -{ - -int status; -struct BigNum dest, a, b; -ord *temp; -BigNumInit(); -/*bnInit(); -bnBegin(&dest); -bnBegin(&a); -bnBegin(&b); -*/ -a.size = len; -a.ptr = m; -a.allocated = len; - -b.size = len; -b.ptr = n; -b.allocated = len; - -temp = (ord*)malloc((len+1)*sizeof(ord)); -dest.size = len; -dest.ptr = temp; -dest.allocated = len+1; - -status = bnGcd(&dest, &a, &b); - -if (*(ord *)(dest.ptr) == 0x01 && dest.size == 1) - status = 0; -else - status = 1; - -free(temp); - -return status; - -} - - -/**************************************************************************** -* NAME: int DivRem( u_int16_t X_bytes, -* ord *X, -* u_int16_t P_bytes, -* ord *P, -* ord *Z, -* ord *D) -* -* DESCRIPTION: Compute a modulo and quotient -* -* INPUTS: -* PARAMETERS: -* ord *X Pointer to array -* u_int16_t X_bytes Number of bytes in X -* ord *P Pointer to modulo -* u_int16_t P_bytes Number of bytes in P -* -* OUTPUT: -* PARAMETERS: -* ord *Z Pointer to result -* ord *D Pointer to quotient -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data (zero bytes) -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 10 Oct 94 KPZ Fixed bugs -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - -int DivRem( u_int16_t X_bytes, - ord *X, - u_int16_t P_bytes, - ord *P, - ord *Z, - ord *D) -{ - int status = SUCCESS; /* function return status */ - -struct BigNum q, r, /*n,*/ d; -ord *temp; -BigNumInit(); -/*bnInit(); -bnBegin(&q); -bnBegin(&r); -bnBegin(&n); -bnBegin(&d); - -n.size = X_bytes/sizeof(ord); -n.ptr = X; -n.allocated = X_bytes/sizeof(ord); -*/ -d.size = P_bytes/sizeof(ord); -d.ptr = P; -d.allocated = P_bytes/sizeof(ord); - -q.size = (X_bytes/sizeof(ord)) - (P_bytes/sizeof(ord)) + 1; -q.ptr = D; -q.allocated = (X_bytes/sizeof(ord)) - (P_bytes/sizeof(ord)) + 1; - -temp = (ord *)malloc(X_bytes); -r.size = X_bytes/sizeof(ord); -r.ptr = temp; -r.allocated = X_bytes/sizeof(ord); -memcpy(r.ptr, X, X_bytes); - -status = bnDivMod(&q, &r, &r, &d); - -memcpy(Z, r.ptr, P_bytes); -free(temp); - -return status; - -} diff --git a/usr/src/lib/libresolv2/common/cylink/ppcasm.h b/usr/src/lib/libresolv2/common/cylink/ppcasm.h deleted file mode 100644 index 23e1b28341..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/ppcasm.h +++ /dev/null @@ -1,582 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#ifndef PPCASM_H -#define PPCASM_H -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * A PowerPC assembler in the C preprocessor. - * This assumes that ints are 32 bits, and uses them for the values. - * - * An assembly-language routine is simply an array of unsigned ints, - * initialized with the macros defined here. - * - * In the PowerPC, a generic function pointer does *not* point to the - * first word of code, but to a two (or possibly more) word "transition - * vector." The first word of the TV points to the function's code. - * The second word is the function's TOC (Table Of Contents) pointer, - * which is loaded into r2. The function's global variables are - * accessed via the TOC pointed to by r2. TOC pointers are changed, - * for example, when a dynamically linked library is called, so the - * library can have private global variables. - * - * Saving r2 and reloading r2 each function call is a hassle that - * I'd really rather avoid, since a lot of useful assembly language routines - * can be written without global variables at all, so they don't need a TOC - * pointer. But I haven't figured out how to persuade CodeWarrior 7 to - * generate an intra-TOC call to an array. (CodeWarrior 8 supports - * PowerPC asm, which obviates the need to do the cast-to-function-pointer - * trick, which obviates the need for cross-TOC calls.) - * - * The basic PowerPC calling conventions for integers are: - * r0 - scratch. May be modified by function calls. - * r1 - stack pointer. Must be preserved across function calls. - * See IMPORTANT notes on stack frame format below. - * This must *ALWAYS*, at every instruction boundary, be 16-byte - * aligned and point to a valid stack frame. If a procedure - * needs to create a stack frame, the recommended way is to do: - * stwu r1,-frame_size(r1) - * and on exit, recover with one of: - * addi r1,r1,frame_size, OR - * lwz r1,0(r1) - * r2 - TOC pointer. Points to the current table of contents. - * Must be preserved across function calls. - * r3 - First argument register and return value register. - * Arguments are passed in r3 through r10, and values returned in - * r3 through r6, as needed. (Usually only r3 for single word.) - * r4-r10 - More argument registers - * r11 - Scratch, may be modified by function calls. - * On entry to indirect function calls, this points to the - * transition vector, and additional words may be loaded - * at offsets from it. Some conventions use r12 instead. - * r12 - Scratch, may be modified by function calls. - * r13-r31 - Callee-save registers, may not be modified by function - * calls. - * The LR, CTR and XER may be modified by function calls, as may the MQ - * register, on those processors for which it is implemented. - * CR fields 0, 1, 5, 6 and 7 are scratch and may be modified by function - * calls. CR fields 2, 3 and 4 must be preserved across function calls. - * - * Stack frame format - READ - * - * r1 points to a stack frame, which must *ALWAYS*, meaning after each and - * every instruction, without excpetion, point to a valid 16-byte-aligned - * stack frame, defined as follows: - * - The 296 bytes below r1 (from -296(r1) to -1(r1)) are the so-called Red - * Zone reserved for leaf procedures, which may use it without allocating - * a stack frame and without decrementing r1. The size comes from the room - * needed to store all the callee-save registers: 19 64-bit integer registers - * and 18 64-bit floating-point registers. (18+19)*8 = 296. So any - * procedure can save all the registers it needs to save before creating - * a stack frame and moving r1. - * The bytes at -297(r1) and below may be used by interrupt and exception - * handlers *at any time*. Anything placed there may disappear before - * the next instruction. - * The word at 0(r1) is the previous r1, and so on in a linked list. - * This is the minimum needed to be a valid stack frame, but some other - * offsets from r1 are preallocated by the calling procedure for the called - * procedure's use. These are: - * Offset 0: Link to previous stack frame - saved r1, if the called - * procedure alters it. - * Offset 4: Saved CR, if the called procedure alters the callee-save - * fields. There's no important reason to save it here, - * but the space is reserved and you might as well use it - * for its intended purpose unless you have good reason to - * do otherwise. (This may help some debuggers.) - * Offset 8: Saved LR, if the called procedure needs to save it for - * later function return. Saving the LR here helps a debugger - * track the chain of return addresses on the stack. - * Note that a called procedure does not need to preserve the - * LR for it's caller's sake, but it uually wants to preserve - * the value for its own sake until it finishes and it's - * time to return. At that point, this is usually loaded - * back into the LR and the branch accomplished with BLR. - * However, if you want to be preverse, you could load it - * into the CTR and use BCTR instead. - * Offset 12: Reserved to compiler. I can't find what this is for. - * Offset 16: Reserved to compiler. I can't find what this is for. - * Offset 20: Saved TOC pointer. In a cross-TOC call, the old TOC (r2) - * is saved here before r2 is loaded with the new TOC value. - * Again, it's not important to use this slot for this, but - * you might as well. - * Beginning at offset 24 is the argument area. This area is at least 8 words - * (32 bytes; I don't know what happens with 64 bits) long, and may be longer, - * up to the length of the longest argument list in a function called by - * the function which allocated this stack frame. Generally, arguments - * to functions are passed in registers, but if those functions notice - * the address of the arguments being taken, the registers are stored - * into the space reserved for them in this area and then used from memory. - * Additional arguments that will not fit into registers are also stored - * here. Variadic functions (like printf) generally start by saving - * all the integer argument registers from the "..." onwards to this space. - * For that reason, the space must be large enough to store all the argument - * registers, even if they're never used. - * (It could probably be safely shrunk if you're not calling any variadic - * functions, but be careful!) - * - * Offsets above that are private to the calling function and shouldn't - * be messed with. Generally, what appears there is locals, then saved - * registers. - * - * - * The floating-point instruction set isn't implemented yet (I'm too - * lazy, as I don't need it yet), but for when it is, the register - * usage convention is: - * FPSCR - Scratch, except for floating point exception enable fields, - * which should only be modified by functions defined to do so. - * fr0 - scratch - * fr1 - first floating point parameter and return value, scratch - * fr2 - second floating point parameter and return value (if needed), scratch - * fr3 - third floating point parameter and return value (if needed), scratch - * fr4 - fourth floating point parameter and return value (if needed), scratch - * fr5-fr13 - More floating point argument registers, scratch - * fr14-fr31 - Callee-save registers, may not be modified across a function call - * - * Complex values store the real part in the lower-numberd register of a pair. - * When mixing floating-point and integer arguments, reserve space (one register - * for single-precision, two for double-precision values) in the integer - * argument list for the floating-point values. Those integer registers - * generally have undefined values, UNLESS there is no prototype for the call, - * in which case they should contain a copy of the floating-point value's - * bit pattern to cope with wierd software. - * If the floating point arguments go past the end of the integer registers, - * they are stored in the argument area as well as being passed in here. - * - * After the argument area comes the calling function's private storage. - * Typically, there are locals, followed by saved GP rgisters, followed - * by saved FP registers. - * - * Suggested instruction for allocating a stack frame: - * stwu r1,-frame_size(r1) - * Suggested instructions for deallocating a stack frame: - * addi r1,r1,frame_size - * or - * lwz r1,0(r1) - * If frame_size is too big, you'll have to load the offset into a temp - * register, but be sure that r1 is updated atomically. - * - * - * Basic PowerPC instructions look like this: - * - * 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Opcode | | | | | | | | | | | | | | | | | | | | | | | | | | | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - * Branch instructions look like this: - * - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Opcode | Branch offset |A|L| - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - * The L, or LK, or Link bit indicates that the return address for the - * branch should be copied to the link register (LR). - * The A, or AA, or absolute address bit, indicates that the address - * of the current instruction (NOTE: not next instruction!) should NOT - * be added to the branch offset; it is relative to address 0. - * - * Conditional branches looks like this: - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Opcode | BO | BI | Branch offset |A|L| - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - * The BI field specifies the condition bit of interest (from the CR). - * The BO field specifies what's interesting. You can branch on a - * combination of a bit of the condition register and --ctr, the CTR - * register. Two bits encode the branch condition to use: - * BRANCH IF - * 00--- = Bit BI is 0 - * 01--- = Bit BI is 1 - * 1z--- = don't care about bit BI (always true) - * AND - * --00- = --ctr != 0 - * --01- = --ctr == 0 - * --1z- = don't decrement ctr (always true) - * The last bit us used as a branch prediction bit. If set, it reverses - * the usual backward-branch-taken heuristic. - * - * y = branch prediction bit. z = unused, must be 0 - * 0000y - branch if --ctr != 0 && BI == 0 - * don't branch if --ctr == 0 || BI != 0 - * 0001y - branch if --ctr == 0 && BI == 0 - * don't branch if --ctr != 0 || BI != 0 - * 001zy - branch if BI == 0 - * don't branch if BI != 0 - * 0100y - branch if --ctr != 0 && BI != 0 - * don't branch if --ctr == 0 || BI == 0 - * 0101y - branch if --ctr == 0 && BI != 0 - * don't branch if --ctr != 0 || BI == 0 - * 011zy - branch if BI != 0 - * don't branch if BI == 0 - * 1z00y - branch if --ctr != 0 - * don't branch if --ctr == 0 - * 1z01y - branch if --ctr == 0 - * don't branch if --ctr != 0 - * 1z1zz - branch always - * If y is 1, the usual branch prediction (usually not taken, taken for - * backwards branches with immediate offsets) is reversed. - * - * Instructions with 2 operands and a 16-bit immediate field look like this: - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Opcode | D | A | 16-bit immediate value | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - * Now, there are three variations of note. In some instructions, the 16-bit - * value is sign-extended. In others, it's zero-extended. These are noted - * below as "simm" (signed immediate) and "uimm", respectively. Also, which - * field is the destination and which is the source sometimes switches. - * Sometimes it's d = a OP imm, and sometimes it's a = s OP imm. In the - * latter cases, the "d" field is referred to as "s" ("source" instead of - * "destination". These are logical and shift instructions. (Store also - * refers to the s register, but that's the source of the value to be stored.) - * The assembly mnemonics, however, always lists the destination first, - * swapping the order in the instruction if necessary. - * Third, quite often, if r0 is specified for the source a, then the constant - * value 0 is used instead. Thus, r0 is of limited use - it can be used for - * some things, but not all. - * - * Instructions with three register operands look like this: - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Opcode | D | A | B | Subopcode |C| - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - * For most of the instructions of interest the Opcode is 31 and the subopcode - * determines what the instruction does. For a few instructions (mostly loads - * and stores), if the A field is 0, the constant 0 is used. The "C" - * bit (also known as the "RC" bit) controls whether or not the condition - * codes are updated. If it is set (indicated by a "." suffix on the official - * PowerPC opcodes, and a "_" suffix on these macros), condition code register - * field 0 (for integer instructions; field 1 for floating point) is updated - * to reflect the result of the operation. - * Some arithmetic instructions use the most significant bit of the subopcode - * field as an overflow enable bit (o suffix). - * - * Then there are the rotate and mask instructions, which have 5 operands, and - * fill the subopcode field with 2 more 5-bit fields. See below for them. - * - * NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE - * These macros fully parenthesize their arguments, but are not themselves - * fully parenthesized. They are intended to be used for initializer lists, - * and if you want to do tricks with their numeric values, wrap them in - * parentheses. - */ - -#define PPC_MAJOR(x) ((x)<<26) /* Major opcode (0..63) */ -#define PPC_MINOR(x) ((x)<<1) /* Minor opcode (0..1023) */ -#define PPC_RC 1 /* Record carry (. suffix, represented as _) */ -#define PPC_OE 1024 /* Overflow enable (o suffix) */ -#define PPC_DEST(reg) ((reg)<<21) /* Dest register field */ -#define PPC_SRCA(reg) ((reg)<<16) /* First source register field */ -#define PPC_SRCB(reg) ((reg)<<11) /* Second source register field */ -#define PPC_AA 2 /* Branch is absolute, relative to address 0 */ -#define PPC_LK 1 /* Branch with link (L suffix) */ - -/* Unconditional branch (dest is 26 bits, +/- 2^25 bytes) */ -#define PPC_B(dest) PPC_MAJOR(18)|(((dest)<<2) & 0x03fffffc) -#define PPC_BA(dest) PPC_B(dest)|PPC_AA -#define PPC_BL(dest) PPC_B(dest)|PPC_LK -#define PPC_BLA(dest) PPC_B(dest)|PPC_AA|PPC_LK - -/* Three-operand instructions */ -#define PPC_TYPE31(minor,d,a,b) \ - PPC_MAJOR(31)|PPC_DEST(d)|PPC_SRCA(a)|PPC_SRCB(b)|PPC_MINOR(minor) -#define PPC_ADD(d,a,b) PPC_TYPE31(266,d,a,b) -#define PPC_ADD_(d,a,b) PPC_TYPE31(266,d,a,b)|PPC_RC -#define PPC_ADDO(d,a,b) PPC_TYPE31(266,d,a,b)|PPC_OE -#define PPC_ADDO_(d,a,b) PPC_TYPE31(266,d,a,b)|PPC_OE|PPC_RC -#define PPC_ADDC(d,a,b) PPC_TYPE31(10,d,a,b) -#define PPC_ADDC_(d,a,b) PPC_TYPE31(10,d,a,b)|PPC_RC -#define PPC_ADDCO(d,a,b) PPC_TYPE31(10,d,a,b)|PPC_OE -#define PPC_ADDCO_(d,a,b) PPC_TYPE31(10,d,a,b)|PPC_OE|PPC_RC -#define PPC_ADDE(d,a,b) PPC_TYPE31(138,d,a,b) -#define PPC_ADDE_(d,a,b) PPC_TYPE31(138,d,a,b)|PPC_RC -#define PPC_ADDEO(d,a,b) PPC_TYPE31(138,d,a,b)|PPC_OE -#define PPC_ADDEO_(d,a,b) PPC_TYPE31(138,d,a,b)|PPC_OE|PPC_RC -#define PPC_ADDME(d,a) PPC_TYPE31(234,d,a,0) -#define PPC_ADDME_(d,a) PPC_TYPE31(234,d,a,0)|PPC_RC -#define PPC_ADDMEO(d,a) PPC_TYPE31(234,d,a,0)|PPC_OE -#define PPC_ADDMEO_(d,a) PPC_TYPE31(234,d,a,0)|PPC_OE|PPC_RC -#define PPC_ADDZE(d,a) PPC_TYPE31(202,d,a,0) -#define PPC_ADDZE_(d,a) PPC_TYPE31(202,d,a,0)|PPC_RC -#define PPC_ADDZEO(d,a) PPC_TYPE31(202,d,a,0)|PPC_OE -#define PPC_ADDZEO_(d,a) PPC_TYPE31(202,d,a,0)|PPC_OE|PPC_RC -#define PPC_AND(a,s,b) PPC_TYPE31(28,s,a,b) -#define PPC_AND_(a,s,b) PPC_TYPE31(28,s,a,b)|PPC_RC -#define PPC_ANDC(a,s,b) PPC_TYPE31(60,s,a,b) -#define PPC_ANDC_(a,s,b) PPC_TYPE31(60,s,a,b)|PPC_RC -#define PPC_CMP(cr,a,b) PPC_TYPE31(0,(cr)<<2,a,b) -#define PPC_CMPL(cr,a,b) PPC_TYPE31(32,(cr)<<2,a,b) -#define PPC_CNTLZW(a,s) PPC_TYPE31(26,s,a,0) -#define PPC_CNTLZW_(a,s) PPC_TYPE31(26,s,a,0)|PPC_RC -#define PPC_DCBF(a,b) PPC_TYPE31(86,0,a,b) -#define PPC_DCBI(a,b) PPC_TYPE31(470,0,a,b) -#define PPC_DCBST(a,b) PPC_TYPE31(54,0,a,b) -#define PPC_DCBT(a,b) PPC_TYPE31(278,0,a,b) -#define PPC_DCBTST(a,b) PPC_TYPE31(246,0,a,b) -#define PPC_DCBZ(a,b) PPC_TYPE31(1014,0,a,b) -#define PPC_DIVW(d,a,b) PPC_TYPE31(491,d,a,b) -#define PPC_DIVW_(d,a,b) PPC_TYPE31(491,d,a,b)|PPC_RC -#define PPC_DIVWO(d,a,b) PPC_TYPE31(491,d,a,b)|PPC_OE -#define PPC_DIVWO_(d,a,b) PPC_TYPE31(491,d,a,b)|PPC_OE|PPC_RC -#define PPC_DIVWU(d,a,b) PPC_TYPE31(459,d,a,b) -#define PPC_DIVWU_(d,a,b) PPC_TYPE31(459,d,a,b)|PPC_RC -#define PPC_DIVWUO(d,a,b) PPC_TYPE31(459,d,a,b)|PPC_OE -#define PPC_DIVWUO_(d,a,b) PPC_TYPE31(459,d,a,b)|PPC_OE|PPC_RC -#define PPC_EIEIO() PPC_TYPE31(854,0,0,0) -#define PPC_EQV(a,s,b) PPC_TYPE31(284,s,a,b) -#define PPC_EQV_(a,s,b) PPC_TYPE31(284,s,a,b)|PPC_RC -#define PPC_EXTSB(a,s,b) PPC_TYPE31(954,s,a,b) -#define PPC_EXTSB_(a,s,b) PPC_TYPE31(954,s,a,b)|PPC_RC -#define PPC_EXTSH(a,s,b) PPC_TYPE31(922,s,a,b) -#define PPC_EXTSH_(a,s,b) PPC_TYPE31(922,s,a,b)|PPC_RC -#define PPC_ICBI(a,b) PPC_TYPE31(982,0,a,b) -#define PPC_ISYNC() PPC_TYPE31(150,0,0,0) -#define PPC_LBZUX(d,a,b) PPC_TYPE31(119,d,a,b) -#define PPC_LBZX(d,a,b) PPC_TYPE31(87,d,a,b) -#define PPC_LHAUX(d,a,b) PPC_TYPE31(375,d,a,b) -#define PPC_LHAX(d,a,b) PPC_TYPE31(343,d,a,b) -#define PPC_LHBRX(d,a,b) PPC_TYPE31(790,d,a,b) -#define PPC_LHZUX(d,a,b) PPC_TYPE31(311,d,a,b) -#define PPC_LHZX(d,a,b) PPC_TYPE31(279,d,a,b) -#define PPC_LSWI(d,a,nb) PPC_TYPE31(597,d,a,nb) -#define PPC_LSWX(d,a,b) PPC_TYPE31(533,d,a,b) -#define PPC_LSARX(d,a,b) PPC_TYPE31(20,d,a,b) -#define PPC_LSBRX(d,a,b) PPC_TYPE31(534,d,a,b) -#define PPC_MCRXR(crd) PPC_TYPE31(512,(crd)<<2,0,0) -#define PPC_MFCR(d) PPC_TYPE31(19,d,0,0) -#define PPC_MFSPR(d,spr) PPC_TYPE31(339,d,(spr)&31,(spr)>>5) -#define PPC_MFTB(d) PPC_TYPE31(371,d,12,8) -#define PPC_MFTBU(d) PPC_TYPE31(371,d,13,8) -#define PPC_MTCRF(mask,s) PPC_TYPE31(144,s,0,(mask)&0xff) -#define PPC_MTSPR(s,spr) PPC_TYPE31(467,s,(spr)&31,(spr)>>5) -#define PPC_MULHW(d,a,b) PPC_TYPE31(75,d,a,b) -#define PPC_MULHW_(d,a,b) PPC_TYPE31(75,d,a,b)|PPC_RC -#define PPC_MULHWU(d,a,b) PPC_TYPE31(11,d,a,b) -#define PPC_MULHWU_(d,a,b) PPC_TYPE31(11,d,a,b)|PPC_RC -#define PPC_MULLW(d,a,b) PPC_TYPE31(235,d,a,b) -#define PPC_MULLW_(d,a,b) PPC_TYPE31(235,d,a,b)|PPC_RC -#define PPC_MULLWO(d,a,b) PPC_TYPE31(235,d,a,b)|PPC_OE -#define PPC_MULLWO_(d,a,b) PPC_TYPE31(235,d,a,b)|PPC_OE|PPC_RC -#define PPC_NAND(a,s,b) PPC_TYPE31(476,s,a,b) -#define PPC_NAND_(a,s,b) PPC_TYPE31(476,s,a,b)|PPC_RC -#define PPC_NEG(d,a) PPC_TYPE31(104,d,a,b) -#define PPC_NEG_(d,a) PPC_TYPE31(104,d,a,b)|PPC_RC -#define PPC_NEGO(d,a) PPC_TYPE31(104,d,a,b)|PPC_OE -#define PPC_NEGO_(d,a) PPC_TYPE31(104,d,a,b)|PPC_OE|PPC_RC -#define PPC_NOR(a,s,b) PPC_TYPE31(124,s,a,b) -#define PPC_NOR_(a,s,b) PPC_TYPE31(124,s,a,b)|PPC_RC -#define PPC_OR(a,s,b) PPC_TYPE31(444,s,a,b) -#define PPC_OR_(a,s,b) PPC_TYPE31(444,s,a,b)|PPC_RC -#define PPC_ORC(a,s,b) PPC_TYPE31(412,s,a,b) -#define PPC_ORC_(a,s,b) PPC_TYPE31(412,s,a,b)|PPC_RC -#define PPC_SLW(a,s,b) PPC_TYPE31(24,s,a,b) -#define PPC_SLW_(a,s,b) PPC_TYPE31(24,s,a,b)|PPC_RC -#define PPC_SRAW(a,s,b) PPC_TYPE31(792,s,a,b) -#define PPC_SRAW_(a,s,b) PPC_TYPE31(792,s,a,b)|PPC_RC -#define PPC_SRAWI(a,s,sh) PPC_TYPE31(824,s,a,sh) -#define PPC_SRAWI_(a,s,sh) PPC_TYPE31(824,s,a,sh)|PPC_RC -#define PPC_SRW(a,s,b) PPC_TYPE31(536,s,a,b) -#define PPC_SRW_(a,s,b) PPC_TYPE31(536,s,a,b)|PPC_RC -#define PPC_STBUX(s,a,b) PPC_TYPE31(247,s,a,b) -#define PPC_STBX(s,a,b) PPC_TYPE31(215,s,a,b) -#define PPC_STHBRX(s,a,b) PPC_TYPE31(918,s,a,b) -#define PPC_STHUX(s,a,b) PPC_TYPE31(439,s,a,b) -#define PPC_STHX(s,a,b) PPC_TYPE31(407,s,a,b) -#define PPC_STSWI(s,a,nb) PPC_TYPE31(725,s,a,nb) -#define PPC_STSWX(s,a,b) PPC_TYPE31(661,s,a,b) -#define PPC_STWBRX(s,a,b) PPC_TYPE31(662,s,a,b) -#define PPC_STWCX_(s,a,b) PPC_TYPE31(150,s,a,b)|PPC_RC -#define PPC_STWUX(s,a,b) PPC_TYPE31(183,s,a,b) -#define PPC_STWX(s,a,b) PPC_TYPE31(151,s,a,b) -#define PPC_SUBF(d,a,b) PPC_TYPE31(40,d,a,b) -#define PPC_SUBF_(d,a,b) PPC_TYPE31(40,d,a,b)|PPC_RC -#define PPC_SUBFO(d,a,b) PPC_TYPE31(40,d,a,b)|PPC_OE -#define PPC_SUBFO_(d,a,b) PPC_TYPE31(40,d,a,b)|PPC_OE|PPC_RC -#define PPC_SUB(d,b,a) PPC_SUBF(d,a,b) -#define PPC_SUB_(d,b,a) PPC_SUBF_(d,a,b) -#define PPC_SUBO(d,b,a) PPC_SUBFO(d,a,b) -#define PPC_SUBO_(d,b,a) PPC_SUBFO_(d,a,b) -#define PPC_SUBFC(d,a,b) PPC_TYPE31(8,d,a,b) -#define PPC_SUBFC_(d,a,b) PPC_TYPE31(8,d,a,b)|PPC_RC -#define PPC_SUBFCO(d,a,b) PPC_TYPE31(8,d,a,b)|PPC_OE -#define PPC_SUBFCO_(d,a,b) PPC_TYPE31(8,d,a,b)|PPC_OE|PPC_RC -#define PPC_SUBFE(d,a,b) PPC_TYPE31(136,d,a,b) -#define PPC_SUBFE_(d,a,b) PPC_TYPE31(136,d,a,b)|PPC_RC -#define PPC_SUBFEO(d,a,b) PPC_TYPE31(136,d,a,b)|PPC_OE -#define PPC_SUBFEO_(d,a,b) PPC_TYPE31(136,d,a,b)|PPC_OE|PPC_RC -#define PPC_SUBFME(d,a) PPC_TYPE31(232,d,a,0) -#define PPC_SUBFME_(d,a) PPC_TYPE31(232,d,a,0)|PPC_RC -#define PPC_SUBFMEO(d,a) PPC_TYPE31(232,d,a,0)|PPC_OE -#define PPC_SUBFMEO_(d,a) PPC_TYPE31(232,d,a,0)|PPC_OE|PPC_RC -#define PPC_SUBFZE(d,a) PPC_TYPE31(200,d,a,0) -#define PPC_SUBFZE_(d,a) PPC_TYPE31(200,d,a,0)|PPC_RC -#define PPC_SUBFZEO(d,a) PPC_TYPE31(200,d,a,0)|PPC_OE -#define PPC_SUBFZEO_(d,a) PPC_TYPE31(200,d,a,0)|PPC_OE|PPC_RC -#define PPC_SYNC() PPC_TYPE31(598,0,0,0) -#define PPC_TW(to,a,b) PPC_TYPE31(4,to,a,b) -#define PPC_XOR(a,s,b) PPC_TYPE31(316,s,a,b) - -/* Immediate-operand instructions. Take a 16-bit immediate operand */ -#define PPC_IMM(major,d,a,imm) \ - PPC_MAJOR(major)|PPC_DEST(d)|PPC_SRCA(a)|((imm)&0xffff) -/* Trap word immediate */ -#define PPV_TWI(to,a,simm) PPC_IMM(3,to,a,simm) -/* Integer arithmetic */ -#define PPC_MULLI(d,a,simm) PPC_IMM(7,d,a,simm) -#define PPC_SUBFIC(s,a,simm) PPC_IMM(8,s,a,simm) -#define PPC_CMPLI(cr,a,uimm) PPC_IMM(10,(cr)<<2,a,uimm) -#define PPC_CMPI(cr,a,simm) PPC_IMM(11,(cr)<<2,a,simm) -#define PPC_ADDIC(d,a,simm) PPC_IMM(12,d,a,simm) -#define PPC_ADDIC_(d,a,simm) PPC_IMM(13,d,a,simm) -#define PPC_ADDI(d,a,simm) PPC_IMM(14,d,a,simm) -#define PPC_ADDIS(d,a,simm) PPC_IMM(15,d,a,simm) - -/* Conditional branch (dest is 16 bits, +/- 2^15 bytes) */ -#define PPC_BC(bo,bi,dest) PPC_IMM(16,bo,bi,((dest)<<2)&0xfffc) -#define PPC_BCA(bo,bi,dest) PPC_BC(bo,bi,dest)|PPC_AA -#define PPC_BCL(bo,bi,dest) PPC_BC(bo,bi,dest)|PPC_LK -#define PPC_BCLA(bo,bi,dest) PPC_BC(bo,bi,dest)|PPC_AA|PPC_LK - -/* Logical operations */ -#define PPC_ORI(a,s,uimm) PPC_IMM(24,s,a,uimm) -#define PPC_ORIS(a,s,uimm) PPC_IMM(25,s,a,uimm) -#define PPC_XORI(a,s,uimm) PPC_IMM(26,s,a,uimm) -#define PPC_XORIS(a,s,uimm) PPC_IMM(27,s,a,uimm) -#define PPC_ANDI_(a,s,uimm) PPC_IMM(28,s,a,uimm) -#define PPC_ANDIS(a,s,uimm) PPC_IMM(29,s,a,uimm) - -/* Load/store */ -#define PPC_LWZ(d,a,simm) PPC_IMM(32,d,a,simm) -#define PPC_LWZU(d,a,simm) PPC_IMM(33,d,a,simm) -#define PPC_LBZ(d,a,simm) PPC_IMM(34,d,a,simm) -#define PPC_LBZU(d,a,simm) PPC_IMM(35,d,a,simm) -#define PPC_STW(s,a,simm) PPC_IMM(36,s,a,simm) -#define PPC_STWU(s,a,simm) PPC_IMM(37,s,a,simm) -#define PPC_STB(s,a,simm) PPC_IMM(38,s,a,simm) -#define PPC_STBU(s,a,simm) PPC_IMM(39,s,a,simm) -#define PPC_LHZ(d,a,simm) PPC_IMM(40,d,a,simm) -#define PPC_LHZU(d,a,simm) PPC_IMM(41,d,a,simm) -#define PPC_LHA(d,a,simm) PPC_IMM(42,d,a,simm) -#define PPC_STH(s,a,simm) PPC_IMM(44,s,a,simm) -#define PPC_STHU(s,a,simm) PPC_IMM(45,s,a,simm) -#define PPC_LHAU(d,a,simm) PPC_IMM(43,d,a,simm) -#define PPC_LMW(d,a,simm) PPC_IMM(46,d,a,simm) -#define PPC_STMW(s,a,simm) PPC_IMM(47,s,a,simm) - -/* Major number = 19 - condition register operations. d, a and b are CR bits */ -#define PPC_TYPE19(minor,d,a,b) \ - PPC_MAJOR(19)|PPC_DEST(d)|PPC_SRCA(a)|PPC_SRCB(b)|PPC_MINOR(minor) -#define PPC_MCRF(d,s) PPC_TYPE19(0,(d)<<2,(s)<<2,0) -#define PPC_CRNOR(d,a,b) PPC_TYPE19(33,d,a,b) -#define PPC_CRANDC(d,a,b) PPC_TYPE19(129,d,a,b) -#define PPC_CRXOR(d,a,b) PPC_TYPE19(193,d,a,b) -#define PPC_CRNAND(d,a,b) PPC_TYPE19(225,d,a,b) -#define PPC_CRAND(d,a,b) PPC_TYPE19(257,d,a,b) -#define PPC_CREQV(d,a,b) PPC_TYPE19(289,d,a,b) -#define PPC_CRORC(d,a,b) PPC_TYPE19(417,d,a,b) -#define PPC_CROR(d,a,b) PPC_TYPE19(449,d,a,b) - -/* Indirect conditional branch */ -#define PPC_BCLR(bo,bi) PPC_TYPE19(16,bo,bi,0) -#define PPC_BCLRL(bo,bi) PPC_TYPE19(16,bo,bi,0)|PPC_LK -#define PPC_BCCTR(bo,bi) PPC_TYPE19(528,bo,bi,0) -#define PPC_BCCTRL(bo,bi) PPC_TYPE19(528,bo,bi,0)|PPC_LK -#define PPC_BLR() PPC_BCLR(20,31) -#define PPC_BCTR() PPC_BCCTR(20,31) - -/* Other */ -#define PPC_RLWIMI(a,s,sh,mb,me) \ - PPC_MAJOR(20)|PPC_DEST(s)|PPC_SRCA(A)|PPC_SRCB(sh)|(mb)<<6|(me)<<1 -#define PPC_RLWIMI_(a,s,sh,mb,me) PPC_RLWIMI(a,s,sh,mb,me)|PPC_RC -#define PPC_RLWINM(a,s,sh,mb,me) \ - PPC_MAJOR(21)|PPC_DEST(s)|PPC_SRCA(A)|PPC_SRCB(sh)|(mb)<<6|(me)<<1 -#define PPC_RLWINM_(a,s,sh,mb,me) PPC_RLWINM(a,s,sh,mb,me)|PPC_RC -#define PPC_RLWNM(a,s,b,mb,me) \ - PPC_MAJOR(23)|PPC_DEST(s)|PPC_SRCA(A)|PPC_SRCB(b)|(mb)<<6|(me)<<1 -#define PPC_RLWNM_(a,s,b,mb,me) PPC_RLWNM(a,s,b,mb,me)|PPC_RC - -#define PPC_SC() PPC_MAJOR(17)|2 -/* Major number = 63 Floating-point operations (not implemented for now) */ - -/* Simplified Mnemonics */ -/* Fabricate immediate subtract out of add negative */ -#define PPC_SUBI(d,a,simm) PPC_ADDI(d,a,-(simm)) -#define PPC_SUBIS(d,a,simm) PPC_ADDIS(d,a,-(simm)) -#define PPC_SUBIC(d,a,simm) PPC_ADDIC(d,a,-(simm)) -#define PPC_SUBIC_(d,a,simm) PPC_ADDIC_(d,a,-(simm)) -/* Fabricate subtract out of subtract from */ -#define PPC_SUBC(d,b,a) PPC_SUBFC(d,a,b) -#define PPC_SUBC_(d,b,a) PPC_SUBFC_(d,a,b) -#define PPC_SUBCO(d,b,a) PPC_SUBFCO(d,a,b) -#define PPC_SUBCO_(d,b,a) PPC_SUBFCO_(d,a,b) -/* Messy compare bits omitted */ -/* Shift and rotate omitted */ -/* Branch coding omitted */ -#define PPC_CRSET(d) PPC_CREQV(d,d,d) -#define PPC_CRCLR(d) PPC_CRXOR(d,d,d) -#define PPC_CRMOVE(d,s) PPC_CROR(d,s,s) -#define PPC_CRNOT(d,s) PPC_CRNOR(d,s,s) -/* Trap menmonics omitted */ -/* Menmonics for user-accessible SPRs */ -#define PPC_MFXER(d) PPC_MFSPR(d,1) -#define PPC_MFLR(d) PPC_MFSPR(d,8) -#define PPC_MFCTR(d) PPC_MFSPR(d,9) -#define PPC_MTXER(s) PPC_MTSPR(s,1) -#define PPC_MTLR(s) PPC_MTSPR(s,8) -#define PPC_MTCTR(s) PPC_MTSPR(s,9) -/* Recommended mnemonics */ -#define PPC_NOP() PPC_ORI(0,0,0) -#define PPC_LI(d,simm) PPC_ADDI(d,0,simm) -#define PPC_LIS(d,simm) PPC_ADDIS(d,0,simm) -#define PPC_LA(d,a,simm) PPC_ADDI(d,a,simm) -#define PPC_MR(d,s) PPC_OR(d,s,s) -#define PPC_NOT(d,s) PPC_NOR(d,s,s) -#define PPC_MTCR(s) PPC_MTCRF(0xff,s) - -#endif /* PPCASM_H */ - -/* 45678901234567890123456789012345678901234567890123456789012345678901234567 */ diff --git a/usr/src/lib/libresolv2/common/cylink/rand.c b/usr/src/lib/libresolv2/common/cylink/rand.c deleted file mode 100644 index b2b6d6f85b..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/rand.c +++ /dev/null @@ -1,340 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/**************************************************************************** -* FILENAME: rand.c PRODUCT NAME: CRYPTOGRAPHIC TOOLKIT -* -* FILE STATUS: -* -* DESCRIPTION: Cryptographic Toolkit Functions File -* Random Number Generation Files -* PUBLIC FUNCTIONS: -* int InitRand( u_int16_t SEED_bytes, uchar *SEED, -* uchar *RVAL ) -* int GenRand( u_int16_t A_bytes, uchar *A, -* uchar *RVAL ) -* int MyGenRand( u_int16_t A_bytes, -* ord *A, -* ord *RVAL ) - -* Copyright (c) Cylink Corporation 1994. All rights reserved. -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 10 Oct 94 KPZ Added Shamir Key Sharing functions -* 10 Oct 94 KPZ Modified SHA functions for arbitrary message length -* 12 Oct 94 KPZ Modified SHA functions (new standard) -* 14 Oct 94 GKL Second version (big endian support) -* 26 Oct 94 GKL (alignment for big endian support & ERR_ALLOC) -* -****************************************************************************/ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/**************************************************************************** -* INCLUDE FILES -****************************************************************************/ - -#include "port_before.h" - -/* system files */ -#ifdef VXD -#include <vtoolsc.h> -#else -#include <stdlib.h> -#include <string.h> -#endif - -/* program files */ -#ifdef VXD -#include "tkvxd.h" -#endif -#include "cylink.h" -#include "ctk_endian.h" -#include "toolkit.h" -#include "cencrint.h" -#include "sha.h" - -#include "port_after.h" -extern u_int16_t DataOrder; -/**************************************************************************** -* PUBLIC FUNCTIONS DEFINITIONS -****************************************************************************/ - -/**************************************************************************** -* NAME: int InitRand( u_int16_t SEED_bytes, -* uchar *SEED, -* uchar *RVAL) -* -* DESCRIPTION: Initialize Random number Generator -* -* INPUTS: -* PARAMETERS: -* u_int16_t SEED_bytes Length of SEED -* uchar *SEED Pointer to SEED value -* -* OUTPUT: -* PARAMETERS: -* uchar *RVAL Pointer to RVAL -* -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data -* ERR_DATA Generic data error -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* -****************************************************************************/ - -int InitRand( u_int16_t SEED_bytes, - uchar *SEED, - uchar *RVAL ) -{ - int status = SUCCESS; /* function return status */ - if ( SEED_bytes == 0 ) - { - status = ERR_INPUT_LEN; - return status; - } - if ( SEED_bytes < SHA_LENGTH ) - { - status = ERR_DATA; - return status; - } - memcpy( RVAL, SEED, SHA_LENGTH); - return status; -} - - -/**************************************************************************** -* NAME: int GenRand( u_int16_t A_bytes, -* uchar *A, -* uchar *RVAL) -* -* DESCRIPTION: Generate random number. -* -* INPUTS: -* PARAMETERS: -* u_int16_t A_bytes Length of A -* uchar *A Pointer to A value -* -* OUTPUT: -* PARAMETERS: -* uchar *RVAL Pointer to RVAL -* -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data -* ERR_DATA Generic data error -* ERR_ALLOC Insufficient memory -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* 26 Oct 94 GKL (alignment for big endian support & ERR_ALLOC) -* -****************************************************************************/ -int GenRand( u_int16_t A_bytes, - uchar *A, - uchar *RVAL ) -{ - int status = SUCCESS; /* function return status */ - ord *RVAL_a; - SHA_context hash_context; /* SHA context structure */ - uchar M[DSS_LENGTH_MIN]; /* message block */ - uchar hash_result[SHA_LENGTH]; - u_int16_t i; - u_int16_t sha_block; /* number of sha blocks */ - u_int16_t sha_rem; /* size of last block */ - if ( A_bytes == 0 ) - { - status = ERR_INPUT_LEN; - return status; - } - sha_block = (u_int16_t) (A_bytes / SHA_LENGTH); /* number of sha blocks */ - sha_rem = (u_int16_t) (A_bytes % SHA_LENGTH); /* size of last block */ - if ( sha_rem == 0 ) /* last block = SHA_LENGTH */ - { - sha_block--; - } - for ( i = 0; i <= sha_block; i++) - { - SHAInit ( &hash_context ); - memcpy( M, RVAL, SHA_LENGTH); - memset( M + SHA_LENGTH, 0, DSS_LENGTH_MIN - SHA_LENGTH ); - if ( (status = SHAUpdate( &hash_context, M, DSS_LENGTH_MIN )) - != SUCCESS ) - { - return status; /* error */ - } - if ( (status=MySHAFinal (&hash_context, hash_result )) != SUCCESS ) - { - return status; /* error */ - } - - BigSwap(RVAL, SHA_LENGTH); - ALIGN_CALLOC_COPY(RVAL, RVAL_a, SHA_LENGTH); - if ( status != SUCCESS ) - { - ALIGN_COPY_FREE(RVAL_a,RVAL,SHA_LENGTH); - BigSwap(RVAL, SHA_LENGTH); - return status; /* ERR_ALLOC insufficient memory */ - } - Sum_Q( RVAL_a, 1, SHA_LENGTH / sizeof(ord) ); - Sum_big( RVAL_a, /* RVAL=RVAL+hash_result*/ - (ord *)hash_result, - RVAL_a, SHA_LENGTH / sizeof(ord) ); - ALIGN_COPY_FREE(RVAL_a,RVAL,SHA_LENGTH); - BigSwap(RVAL, SHA_LENGTH); -#ifdef CTK_BIG_ENDIAN - ByteSwap(hash_result,SHA_LENGTH); -#endif - BigSwap(hash_result, SHA_LENGTH); - if ( i == sha_block && sha_rem != 0 ) /* last block < SHA_LENGTH*/ - { - memcpy( A + i * SHA_LENGTH, hash_result, - sha_rem * sizeof (uchar)); - } - else /* last block = SHA_LENGTH*/ - { - memcpy( A + i * SHA_LENGTH, hash_result, - SHA_LENGTH * sizeof (uchar)); - } - } - return status; -} - - - -/**************************************************************************** -* NAME: int MyGenRand( u_int16_t A_bytes, -* ord *A, -* ord *RVAL) -* -* DESCRIPTION: Generate random number. -* -* INPUTS: -* PARAMETERS: -* u_int16_t A_bytes Length of A -* ord *A Pointer to A value -* -* OUTPUT: -* PARAMETERS: -* ord *RVAL Pointer to RVAL -* -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data -* ERR_DATA Generic data error -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ -int MyGenRand( u_int16_t A_bytes, - ord *A, - ord *RVAL ) -{ - int status = SUCCESS; /* function return status */ - SHA_context hash_context; /* SHA context structure */ - uchar M[DSS_LENGTH_MIN]; /* message block */ - uchar hash_result[SHA_LENGTH]; - u_int16_t i; - u_int16_t sha_block; /* number of sha blocks */ - u_int16_t sha_rem; /* size of last block */ - if ( A_bytes == 0 ) - { - status = ERR_INPUT_LEN; - return status; - } - sha_block = (u_int16_t) (A_bytes / SHA_LENGTH); /* number of sha blocks */ - sha_rem = (u_int16_t) (A_bytes % SHA_LENGTH); /* size of last block */ - if ( sha_rem == 0 ) /* last block = SHA_LENGTH */ - { - sha_block--; - } - for ( i = 0; i <= sha_block; i++) - { - SHAInit ( &hash_context ); - memcpy( M, RVAL, SHA_LENGTH); - memset( M + SHA_LENGTH, 0, DSS_LENGTH_MIN - SHA_LENGTH ); - if ( (status = SHAUpdate( &hash_context, M, DSS_LENGTH_MIN )) - != SUCCESS ) - { - return status; /* error */ - } - if ( (status=MySHAFinal (&hash_context, hash_result )) != SUCCESS ) - { - return status; /* error */ - } -#ifdef CTK_BIG_ENDIAN - ByteSwap((uchar*)RVAL,SHA_LENGTH); -#endif - BigSwap((uchar*)RVAL, SHA_LENGTH); - Sum_Q(RVAL, 1,SHA_LENGTH / sizeof(ord)); - Sum_big( RVAL, /* RVAL=RVAL+hash_result*/ - (ord*)hash_result, - RVAL, SHA_LENGTH / sizeof(ord) ); - BigSwap((uchar*)RVAL, SHA_LENGTH); -#ifdef CTK_BIG_ENDIAN - ByteSwap((uchar*)RVAL,SHA_LENGTH); -#endif - if ( i == sha_block && sha_rem != 0 ) /* last block < SHA_LENGTH*/ - { - memcpy( &A[ i*SHA_LENGTH / sizeof(ord)], hash_result, - sha_rem * sizeof (uchar)); - } - else /* last block = SHA_LENGTH*/ - { - memcpy( &A[ i*SHA_LENGTH / sizeof(ord)], hash_result, - SHA_LENGTH * sizeof (uchar)); - } - } - return status; -} - diff --git a/usr/src/lib/libresolv2/common/cylink/sha.c b/usr/src/lib/libresolv2/common/cylink/sha.c deleted file mode 100644 index bc67fcac79..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/sha.c +++ /dev/null @@ -1,706 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/**************************************************************************** -* FILENAME: cencrint.c PRODUCT NAME: CRYPTOGRAPHIC TOOLKIT -* -* FILE STATUS: -* -* DESCRIPTION: Cryptographic Toolkit Internal Functions File -* -* PRIVATE FUNCTIONS: -* -* -* void shaTransform( u_int32_t *state, uchar *block ) -* void SHAInitK( SHA_context *hash_context ) -* int MySHA( uchar *message, u_int16_t message_bytes, -* uchar *hash_result ) -* int MySHAFinal( SHA_context *hash_context, uchar *hash_result ) -* -* -* Copyright (c) Cylink Corporation 1994. All rights reserved. -* -* REVISION HISTORY: -* -* -* 24 Sep 94 KPZ Initial release -* 10 Oct 94 KPZ Fixed bugs in Add(), DivRem() -* 12 Oct 94 KPZ Modified shaTransform() -* 14 Oct 94 GKL Second version (big endian support) -* 26 Oct 94 GKL (alignment for big endian support & ERR_ALLOC) -* 08 Nov 94 GKL Added input parameters check to Inverse -* 08 Dec 94 GKL Added YIELD_context to Expo, VerPrime and GenPrime -* -****************************************************************************/ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/**************************************************************************** -* INCLUDE FILES -****************************************************************************/ - -#include "port_before.h" -#include <sys/types.h> - -/* system files */ -#ifdef VXD -#include <vtoolsc.h> -#else -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#endif - -/* program files */ -#include "cylink.h" -#include "ctk_endian.h" -#include "toolkit.h" -#include "cencrint.h" -#include "sha.h" -#include "port_after.h" -extern u_int16_t DataOrder; - -/**************************************************************************** -* NAME: int SHA( uchar *message, -* u_int16_t message_bytes, -* uchar *hash_result ) -* -* DESCRIPTION: Compute a Secure Hash Function. -* -* INPUTS: -* PARAMETERS: -* uchar *message Pointer to message -* u_int16_t message_bytes Number of bytes in message -* uchar *hash_result Pointer to message digest -* -* OUTPUT: -* PARAMETERS: -* uchar *hash_result Message digest -* -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data(zero bytes) -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* -****************************************************************************/ - -int SHA( uchar *message, - u_int16_t message_bytes, - uchar *hash_result ) -{ - SHA_context hash_context; /* SHA context structure */ - int status = SUCCESS; /* function return status */ - if (message_bytes == 0 ) - { - status = ERR_INPUT_LEN; - return status; /* invalid length for input data */ - } - SHAInit ( &hash_context ); /* initialize SHA */ - if ( (status = SHAUpdate( &hash_context, message, message_bytes )) - != SUCCESS ) - { - return status; /* error */ - } - if ((status=SHAFinal (&hash_context, hash_result)) != SUCCESS ) - { - return status; /* error */ - } - - return status; -} - -/**************************************************************************** -* PRIVATE FUNCTIONS DEFINITIONS -****************************************************************************/ - - -/**************************************************************************** -* NAME: void shaTransform( u_int32_t *state, -* uchar *block ) -* -* DESCRIPTION: Perform SHS transformation. -* -* INPUTS: -* PARAMETERS: -* SHA_context *hash_context Pointer to SHA_context structure -* OUTPUT: -* -* SHA_context *hash_context Pointer to SHA_context structure -* (updated) -* REVISION HISTORY: -* -* 24 sep 94 KPZ Initial release -* 12 Oct 94 KPZ Modified buffers copy -* 14 Oct 94 GKL Second version (big endian support) -* 1 Sep 95 AAB Speedup the function -****************************************************************************/ - - void shaTransform( u_int32_t *state, - const uchar *block ) -{ - u_int32_t W[80]; - u_int32_t A,B,C,D,E; /*,temp;*/ - memcpy( W, block, 64); /*TKL00201*/ -#ifdef CTK_LITTLE_ENDIAN /*TKL00201*/ - ByteSwap32( (uchar *)W, 64); /*TKL00201*/ -#endif /*TKL00201*/ - /* Expand the 16 words into 80 words */ - expand(16);expand(17);expand(18);expand(19);expand(20);expand(21); - expand(22);expand(23);expand(24);expand(25);expand(26);expand(27); - expand(28);expand(29);expand(30);expand(31);expand(32);expand(33); - expand(34);expand(35);expand(36);expand(37);expand(38);expand(39); - expand(40);expand(41);expand(42);expand(43);expand(44);expand(45); - expand(46);expand(47);expand(48);expand(49);expand(50);expand(51); - expand(52);expand(53);expand(54);expand(55);expand(56);expand(57); - expand(58);expand(59);expand(60);expand(61);expand(62);expand(63); - expand(64);expand(65);expand(66);expand(67);expand(68);expand(69); - expand(70);expand(71);expand(72);expand(73);expand(74);expand(75); - expand(76);expand(77);expand(78);expand(79); - /*Set up first buffer*/ - A = state[0]; - B = state[1]; - C = state[2]; - D = state[3]; - E = state[4]; - - /* Heavy mangling, in 4 sub-rounds of 20 iterations each. */ - subRound( A, B, C, D, E, f1, k1SHA, W[ 0] ); - subRound( E, A, B, C, D, f1, k1SHA, W[ 1] ); - subRound( D, E, A, B, C, f1, k1SHA, W[ 2] ); - subRound( C, D, E, A, B, f1, k1SHA, W[ 3] ); - subRound( B, C, D, E, A, f1, k1SHA, W[ 4] ); - subRound( A, B, C, D, E, f1, k1SHA, W[ 5] ); - subRound( E, A, B, C, D, f1, k1SHA, W[ 6] ); - subRound( D, E, A, B, C, f1, k1SHA, W[ 7] ); - subRound( C, D, E, A, B, f1, k1SHA, W[ 8] ); - subRound( B, C, D, E, A, f1, k1SHA, W[ 9] ); - subRound( A, B, C, D, E, f1, k1SHA, W[10] ); - subRound( E, A, B, C, D, f1, k1SHA, W[11] ); - subRound( D, E, A, B, C, f1, k1SHA, W[12] ); - subRound( C, D, E, A, B, f1, k1SHA, W[13] ); - subRound( B, C, D, E, A, f1, k1SHA, W[14] ); - subRound( A, B, C, D, E, f1, k1SHA, W[15] ); - subRound( E, A, B, C, D, f1, k1SHA, W[16] ); - subRound( D, E, A, B, C, f1, k1SHA, W[17] ); - subRound( C, D, E, A, B, f1, k1SHA, W[18] ); - subRound( B, C, D, E, A, f1, k1SHA, W[19] ); - - subRound( A, B, C, D, E, f2, k2SHA, W[20]); - subRound( E, A, B, C, D, f2, k2SHA, W[21]); - subRound( D, E, A, B, C, f2, k2SHA, W[22]); - subRound( C, D, E, A, B, f2, k2SHA, W[23]); - subRound( B, C, D, E, A, f2, k2SHA, W[24]); - subRound( A, B, C, D, E, f2, k2SHA, W[25]); - subRound( E, A, B, C, D, f2, k2SHA, W[26]); - subRound( D, E, A, B, C, f2, k2SHA, W[27]); - subRound( C, D, E, A, B, f2, k2SHA, W[28]); - subRound( B, C, D, E, A, f2, k2SHA, W[29]); - subRound( A, B, C, D, E, f2, k2SHA, W[30]); - subRound( E, A, B, C, D, f2, k2SHA, W[31]); - subRound( D, E, A, B, C, f2, k2SHA, W[32]); - subRound( C, D, E, A, B, f2, k2SHA, W[33]); - subRound( B, C, D, E, A, f2, k2SHA, W[34]); - subRound( A, B, C, D, E, f2, k2SHA, W[35]); - subRound( E, A, B, C, D, f2, k2SHA, W[36]); - subRound( D, E, A, B, C, f2, k2SHA, W[37]); - subRound( C, D, E, A, B, f2, k2SHA, W[38]); - subRound( B, C, D, E, A, f2, k2SHA, W[39]); - - subRound( A, B, C, D, E, f3, k3SHA, W[40]); - subRound( E, A, B, C, D, f3, k3SHA, W[41]); - subRound( D, E, A, B, C, f3, k3SHA, W[42]); - subRound( C, D, E, A, B, f3, k3SHA, W[43]); - subRound( B, C, D, E, A, f3, k3SHA, W[44]); - subRound( A, B, C, D, E, f3, k3SHA, W[45]); - subRound( E, A, B, C, D, f3, k3SHA, W[46]); - subRound( D, E, A, B, C, f3, k3SHA, W[47]); - subRound( C, D, E, A, B, f3, k3SHA, W[48]); - subRound( B, C, D, E, A, f3, k3SHA, W[49]); - subRound( A, B, C, D, E, f3, k3SHA, W[50]); - subRound( E, A, B, C, D, f3, k3SHA, W[51]); - subRound( D, E, A, B, C, f3, k3SHA, W[52]); - subRound( C, D, E, A, B, f3, k3SHA, W[53]); - subRound( B, C, D, E, A, f3, k3SHA, W[54]); - subRound( A, B, C, D, E, f3, k3SHA, W[55]); - subRound( E, A, B, C, D, f3, k3SHA, W[56]); - subRound( D, E, A, B, C, f3, k3SHA, W[57]); - subRound( C, D, E, A, B, f3, k3SHA, W[58]); - subRound( B, C, D, E, A, f3, k3SHA, W[59]); - - subRound( A, B, C, D, E, f4, k4SHA, W[60]); - subRound( E, A, B, C, D, f4, k4SHA, W[61]); - subRound( D, E, A, B, C, f4, k4SHA, W[62]); - subRound( C, D, E, A, B, f4, k4SHA, W[63]); - subRound( B, C, D, E, A, f4, k4SHA, W[64]); - subRound( A, B, C, D, E, f4, k4SHA, W[65]); - subRound( E, A, B, C, D, f4, k4SHA, W[66]); - subRound( D, E, A, B, C, f4, k4SHA, W[67]); - subRound( C, D, E, A, B, f4, k4SHA, W[68]); - subRound( B, C, D, E, A, f4, k4SHA, W[69]); - subRound( A, B, C, D, E, f4, k4SHA, W[70]); - subRound( E, A, B, C, D, f4, k4SHA, W[71]); - subRound( D, E, A, B, C, f4, k4SHA, W[72]); - subRound( C, D, E, A, B, f4, k4SHA, W[73]); - subRound( B, C, D, E, A, f4, k4SHA, W[74]); - subRound( A, B, C, D, E, f4, k4SHA, W[75]); - subRound( E, A, B, C, D, f4, k4SHA, W[76]); - subRound( D, E, A, B, C, f4, k4SHA, W[77]); - subRound( C, D, E, A, B, f4, k4SHA, W[78]); - subRound( B, C, D, E, A, f4, k4SHA, W[79]); - - state[0] += A; - state[1] += B; - state[2] += C; - state[3] += D; - state[4] += E; - -} - - - - -/**************************************************************************** -* NAME: void SHAInitK( SHA_context *hash_context ) -* -* DESCRIPTION: Initialize Secure Hash Function for generate -* random number for DSS. -* -* INPUTS: -* PARAMETERS: -* SHA_context *hash_context SHA context structure -* OUTPUT: -* PARAMETERS: -* SHA_context *hash_context Initialized SHA context structure -* -* RETURN: -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - -void SHAInitK( SHA_context *hash_context ) -{ -/*Set up first buffer*/ - /* on28 port: silence compiler warnings by changing 0x...L to 0x...U */ - hash_context->state[0] = 0xEFCDAB89U; - hash_context->state[1] = 0x98BADCFEU; - hash_context->state[2] = 0x10325476U; - hash_context->state[3] = 0xC3D2E1F0U; - hash_context->state[4] = 0x67452301U; -/*Initialise buffer */ - memset( hash_context->buffer, 0, sizeof(hash_context->buffer)); - memset( hash_context->count, 0, sizeof(hash_context->count)); -} - - -/**************************************************************************** -* NAME: int MySHA( uchar *message, -* u_int16_t message_bytes, -* uchar *hash_result ) -* -* DESCRIPTION: Compute a Secure Hash Function. -* -* INPUTS: -* PARAMETERS: -* uchar *message Pointer to message -* u_int16_t message_bytes Number of bytes in message -* uchar *hash_result Pointer to message digest -* -* OUTPUT: -* PARAMETERS: -* uchar *hash_result Message digest -* -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data(zero bytes) -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* -****************************************************************************/ -int MySHA( uchar *message, - u_int16_t message_bytes, - uchar *hash_result ) -{ - SHA_context hash_context; /* SHA context structure */ - int status = SUCCESS; /* function return status */ - if (message_bytes == 0 ) - { - status = ERR_INPUT_LEN; - return status; /* invalid length for input data */ - } - SHAInit ( &hash_context ); /* initialize SHA */ -#ifdef CTK_BIG_ENDIAN - ByteSwap(message,message_bytes); -#endif - status = SHAUpdate( &hash_context, message, message_bytes ); -#ifdef CTK_BIG_ENDIAN - ByteSwap(message,message_bytes); -#endif - if ( status != SUCCESS ) - { - return status; /* error */ - } - if ((status=MySHAFinal (&hash_context, hash_result)) != SUCCESS ) - { - return status; /* error */ - } - return status; -} - -/**************************************************************************** -* NAME: int MySHAFinal( SHA_context *hash_context, -* uchar *hash_result ) -* DESCRIPTION: Finalize Secure Hash Function -* -* INPUTS: -* PARAMETERS: -* SHA_context *hash_context SHA context structure -* uchar *hash_result Pointer to hash -* OUTPUT: -* PARAMETERS: -* uchar *hash_result Final value -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data (zero bytes) -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 10 Oct 94 KPZ Modified for arbitrary message length -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - int MySHAFinal( SHA_context *hash_context, - uchar *hash_result ) -{ - int status = SUCCESS; /* function return status */ - uchar bits[8]; - u_int16_t index, padLen; - u_int32_t ex; - uchar PADDING[64] = { /* padding string */ - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - - if ( hash_context->count[0] == 0 && hash_context->count[1] == 0 ) - { - status= ERR_INPUT_LEN; - return status; - } - /* Save number of bits */ - LongByte( &hash_context->count[1] , 4, bits ); - LongByte( &hash_context->count[0] , 4, bits + 4 ); - ByteSwap32( bits, 8 ); - /* Pad out to 56 mod 64.*/ - index = (u_int16_t )((hash_context->count[0] >> 3) & 0x3f); - padLen = (u_int16_t) ((index < 56) ? (56 - index) : (120 - index)); - SHAUpdate( hash_context, PADDING, padLen ); - - /* Append length (before padding) */ - SHAUpdate (hash_context, bits, 8); - - /* Set order of hash_context */ - ex = hash_context->state[0]; - hash_context->state[0] = hash_context->state[4]; - hash_context->state[4] = ex; - ex = hash_context->state[1]; - hash_context->state[1] = hash_context->state[3]; - hash_context->state[3] = ex; - /* Store state in digest */ - memcpy(hash_result,hash_context->state,SHA_LENGTH); - /* Zeroize sensitive information.*/ - memset( hash_context, 0, sizeof(hash_context) ); -#if defined ( ORD_16 ) && defined( CTK_BIG_ENDIAN ) - WordSwap(hash_result,SHA_LENGTH); -#endif - return status; -} - - -/**************************************************************************** -* NAME: int SHAUpdate( SHA_context *hash_context, -* uchar *message, -* u_int16_t message_bytes ) -* DESCRIPTION: Update Secure Hash Function -* -* INPUTS: -* PARAMETERS: -* SHA_context *hash_context SHA context structure -* uchar *message Pointer to message -* u_int16_t message_bytes Number of bytes -* OUTPUT: -* PARAMETERS: -* SHA_context *hash_context Updated SHA context structure -* -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data (zero bytes) -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 10 Oct 94 KPZ Modified for arbitrary message length -* -****************************************************************************/ - -int SHAUpdate( SHA_context *hash_context, - const uchar *message, - u_int16_t message_bytes ) - -{ - int status = SUCCESS; /* function return status */ - u_int16_t i, index, partLen; - if ( message_bytes == 0 ) - { - status = ERR_INPUT_LEN; /*invalid length for input data (zero bytes)*/ - return status; - } - - /* Compute number of bytes mod 64 */ - index = (u_int16_t)((hash_context->count[0] >> 3) & 0x3F); - - /* Update number of bits */ - if ( (hash_context->count[0] += ((u_int32_t )message_bytes << 3)) - < ((u_int32_t )message_bytes << 3) ) - { - hash_context->count[1]++; - } - hash_context->count[1] += ((u_int32_t )message_bytes >> 29); - - partLen = (u_int16_t) (64 - index); - /* Transform as many times as possible.*/ - if ( message_bytes >= partLen ) - { - memcpy( &hash_context->buffer[index], message, partLen ); - shaTransform( hash_context->state, hash_context->buffer ); - - for ( i = partLen; (u_int16_t)(i + 63) < message_bytes; i += 64 ) - { - shaTransform ( hash_context->state, &message[i] ); - } - index = 0; - } - else - { - i = 0; - } - /* Buffer remaining input */ - memcpy( &hash_context->buffer[index], &message[i], - message_bytes - i ); - return status; -} - - -/**************************************************************************** -* NAME: void SHAInit( SHA_context *hash_context ) -* -* DESCRIPTION: Initialize Secure Hash Function -* -* INPUTS: -* PARAMETERS: -* SHA_context *hash_context SHA context structure -* OUTPUT: -* PARAMETERS: -* SHA_context *hash_context Initialized SHA context structure -* -* RETURN: -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* -****************************************************************************/ - -void SHAInit( SHA_context *hash_context ) -{ -/*Set up first buffer*/ - hash_context->state[0] = h0SHA; - hash_context->state[1] = h1SHA; - hash_context->state[2] = h2SHA; - hash_context->state[3] = h3SHA; - hash_context->state[4] = h4SHA; - -/* Initialise buffer */ - memset( hash_context->buffer, 0, sizeof(hash_context->buffer)); - /*Initialize bit count*/ - hash_context->count[0] = hash_context->count[1] = 0; -} - -/**************************************************************************** -* NAME: int SHAFinal( SHA_context *hash_context, -* uchar *hash_result ) -* DESCRIPTION: Finalize Secure Hash Function -* -* INPUTS: -* PARAMETERS: -* SHA_context *hash_context SHA context structure -* uchar *hash_result Pointer to hash -* OUTPUT: -* PARAMETERS: -* uchar *hash_result Final value -* RETURN: -* SUCCESS No errors -* ERR_INPUT_LEN Invalid length for input data (zero bytes) -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 10 Oct 94 KPZ Modified for arbitrary message length -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - - -int SHAFinal( SHA_context *hash_context, - uchar *hash_result ) -{ - int status = SUCCESS; /* function return status */ - status = MySHAFinal( hash_context, hash_result ); -#ifdef CTK_BIG_ENDIAN - if (status == SUCCESS) - { - ByteSwap(hash_result, SHA_LENGTH); - } -#endif - if (DataOrder) - { - BigSwap(hash_result, SHA_LENGTH); - } - return status; -} - -/**************************************************************************** -* NAME: int GetPasswordKeySHA( u_int16_t Password_bytes, -* uchar *Password, -* uchar *salt, -* u_int16_t Count, -* uchar *K, -* uchar *IV ) -* -* DESCRIPTION: Get Password-Based DES/KAPPA Key by SHA -* -* INPUTS: -* PARAMETERS: -* u_int16_t Password_bytes Number of bytes in password -* uchar *Password Pointer to password -* uchar *salt Pointer to salt(8-byte) -* u_int16_t Count Number of iteration -* OUTPUT: -* PARAMETERS: -* uchar *K Pointer to DES/KAPPA key -* uchar *IV Pointer to initialization vector -* RETURN: -* SUCCESS No errors -* ERR_COUNT Invalid iteration count (zero) -* ERR_INPUT_LEN Invalid length for input data(zero bytes) -* ERR_ALLOC Insufficient memory -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 26 Oct 94 GKL (ERR_ALLOC) -* -****************************************************************************/ - int GetPasswordKeySHA( u_int16_t Password_bytes, - uchar *Password, - uchar *salt, - u_int16_t Count, - uchar *K, - uchar *IV ) - -{ - int status = SUCCESS; /* function return status */ - uchar digest[SHA_LENGTH]; - uchar *buf; - if ( Count == 0 ) /* invalid iteration count (zero) */ - { - status = ERR_COUNT; - return status; - } - CALLOC(buf,uchar,Password_bytes + 8); - if ( status != SUCCESS ) - { - return status; /* ERR_ALLOC insufficient memory */ - } - if ( Password_bytes != 0 ) /* if number of bytes password non equals zero */ - { - memcpy( buf, Password, Password_bytes ); - } - memcpy( buf + Password_bytes, salt, 8); -/* Compute message digest */ - status = SHA( buf, (u_int16_t)(Password_bytes + 8), digest); - if (!DataOrder) - { - BigSwap(digest, SHA_LENGTH); - } - - if ( status != SUCCESS ) - { - free ( buf ); - return status; - } - Count --; /* decrement Count */ -/* Count times compute message digest */ - while ( Count != 0 ) - { - if ( (status = SHA( digest, SHA_LENGTH, digest)) != SUCCESS ) - { - free ( buf ); - return status; - } - if (!DataOrder) - { - BigSwap(digest, SHA_LENGTH); - } - Count --; - } - memcpy( K, digest, 8 ); - memcpy( IV, digest + SHA_LENGTH -8, 8 ); - free ( buf ); - return status; -} diff --git a/usr/src/lib/libresolv2/common/cylink/sha.h b/usr/src/lib/libresolv2/common/cylink/sha.h deleted file mode 100644 index 8442b3bfab..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/sha.h +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/**************************************************************************** -* FILENAME: sha.h PRODUCT NAME: CRYPTOGRAPHIC TOOLKIT -* -* FILE STATUS: -* -* DESCRIPTION: Cryptographic Toolkit Internal Functions Header File -* -* USAGE: File should be included in Toolkit functions files -* -* -* Copyright (c) Cylink Corporation 1994. All rights reserved. -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* -****************************************************************************/ -#ifndef SHA_H -#define SHA_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "cylink.h" - -#define SHS_BLOCKSIZE 64 -/* -#define FSHA(x,y,z) ( ( x & y ) | ( ~x & z ) ) -#define GSHA(x,y,z) ( x ^ y ^ z ) -#define HSHA(x,y,z) ( ( x & y ) | ( x & z ) | ( y & z ) ) -#define ISHA(x,y,z) (x ^ y ^ z) -*/ -/*#define f1(x,y,z) ( (x & y) | (~x & z) ) // Rounds 0-19 */ -#define f1(x,y,z) ( z ^ (x & (y ^ z) ) ) /* Rounds 0-19 */ -#define f2(x,y,z) ( x ^ y ^ z ) /* Rounds 20-39 */ -/*#define f3(x,y,z) ( (x & y) | (x & z) | (y & z) ) // Rounds 40-59 */ -#define f3(x,y,z) ( (x & y) | (z & (x | y) ) ) /* Rounds 40-59 */ -#define f4(x,y,z) ( x ^ y ^ z ) /* Rounds 60-79 */ - - -#define RotateLeft(x,n) (( x << n )|( x >> (32-n) ) ) /*Circular left shift operation*/ - -/* - * Note: for on28 port, and to silence compiler warnings when the value is - * larger than or equal to 0x80000000, change constants to be U rather - * than L. - */ - -/*SHS Constants */ -#define k1SHA 0x5a827999U -#define k2SHA 0x6ed9eba1U -#define k3SHA 0x8f1bbcdcU -#define k4SHA 0xca62c1d6U - -/*SHS initial value */ -#define h0SHA 0x67452301U -#define h1SHA 0xefcdab89U -#define h2SHA 0x98badcfeU -#define h3SHA 0x10325476U -#define h4SHA 0xc3d2e1f0U - -/*The initial expanding function*/ -#define expand(count) \ - {\ - W[count] = W[count-3] ^ W[count-8] ^ W[count-14] ^ W[count-16];\ - W[count] = RotateLeft( W[count], 1 );\ - } - -/*New variant */ -#define subRound(a, b, c, d, e, f, k, data) \ - ( e += RotateLeft(a,5) + f(b, c, d) + k + data, b = RotateLeft( b,30) ) - - - -/*The four sub_rounds*/ -/* -#define subR1(count) \ - {\ - temp=RotateLeft(A,5) + FSHA(B,C,D) + E +W[count] +k1SHA;\ - E = D; \ - D = C; \ - C = RotateLeft(B,30); \ - B = A; \ - A = temp; \ - } - -#define subR2(count) \ - {\ - temp=RotateLeft(A,5) + GSHA(B,C,D) + E +W[count] +k2SHA;\ - E = D; \ - D = C; \ - C = RotateLeft(B,30);\ - B = A; \ - A = temp; \ - } - -#define subR3(count) \ - {\ - temp=RotateLeft(A,5) + HSHA(B,C,D) + E +W[count] +k3SHA;\ - E = D; \ - D = C; \ - C = RotateLeft(B,30);\ - B = A; \ - A = temp; \ - } - -#define subR4(count) \ - {\ - temp=RotateLeft(A,5) + ISHA(B,C,D) + E + W[count] +k4SHA;\ - E = D; \ - D = C; \ - C = RotateLeft(B,30);\ - B = A; \ - A = temp; \ - } -*/ -#endif /* SHA_H */ - diff --git a/usr/src/lib/libresolv2/common/cylink/sizetest.c b/usr/src/lib/libresolv2/common/cylink/sizetest.c deleted file mode 100644 index 6fc9a9ee89..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/sizetest.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include "bnsize00.h" - -#if BNSIZE16 -#error Using 16-bit math library -#elif BNSIZE32 -#error Using 32-bit math library -#elif BNSIZE64 -#error Using 64-bit math library -#else -#error No math library size defined -#endif diff --git a/usr/src/lib/libresolv2/common/cylink/swap.c b/usr/src/lib/libresolv2/common/cylink/swap.c deleted file mode 100644 index 6e4f33b967..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/swap.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - - -/**************************************************************************** -* FILENAME: swap.c PRODUCT NAME: CRYPTOGRAPHIC TOOLKIT -* -* FILE STATUS: -* -* DESCRIPTION: Byte and Word Swap functions -* -* PUBLIC FUNCTIONS: -* -* -* PRIVATE FUNCTIONS: -* -* REVISION HISTORY: -* -* 14 Oct 94 GKL Initial release -* 26 Oct 94 GKL (alignment for big endian support ) -* -****************************************************************************/ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/**************************************************************************** -* INCLUDE FILES -****************************************************************************/ -/* system files */ - -#include "port_before.h" -#ifdef VXD -#include <vtoolsc.h> -#else -#include <stdlib.h> -#include <string.h> -#endif -/* program files */ -#include "cylink.h" -#include "ctk_endian.h" -#include "toolkit.h" -#include "port_after.h" - -u_int16_t DataOrder = 0; - -/*Reset bytes in long*/ -/*extern void ByteSwap32_asm( uchar *X, u_int16_t X_len );*/ /*kz*/ - -/**************************************************************************** -* NAME: void ByteSwap32 (uchar *array, -* u_int16_t X_len ) -* -* DESCRIPTION: Perform byte reversal on an array of longword. -* -* INPUTS: -* PARAMETERS: -* uchar *X Pointer to array -* u_int16_t X_len Number of bytes -* OUTPUT: -* uchar *X Pointer to array -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - - -void ByteSwap32( uchar *X, u_int16_t X_len ) -{ - u_int16_t i; /*counter*/ - uchar a; /*temporary char*/ - for ( i = 0; i < X_len; i += 4) - { - a = X[i]; - X[i] = X[i+3]; - X[i+3] = a; - a = X[i+1]; - X[i+1] = X[i+2]; - X[i+2] = a; - } -/*#endif*/ /*kz*/ -} - - -/**************************************************************************** -* NAME: void ByteSwap (uchar *array, -* u_int16_t X_len ) -* -* DESCRIPTION: Perform byte reversal on an array of longword or shortword. -* -* INPUTS: -* PARAMETERS: -* uchar *X Pointer to array -* u_int16_t X_len Number of bytes -* OUTPUT: -* uchar *X Pointer to array -* -* REVISION HISTORY: -* -* 24 Sep 94 KPZ Initial release -* 14 Oct 94 GKL Second version (big endian support) -* -****************************************************************************/ - -void ByteSwap( uchar *X, - u_int16_t X_len ) -{ -#ifdef ORD_16 - u_int16_t i; /*counter*/ - uchar a; /*tempriory char for revers*/ - for ( i = 0; i < X_len; i += 2) - { - a = X[i]; - X[i] = X[i+1]; - X[i+1] = a; - } -#endif -#ifdef ORD_32 - ByteSwap32(X,X_len); -#endif -} - -/*kz longbyte deleted */ - -/**************************************************************************** -* NAME: void WordSwap (uchar *array, -* u_int16_t X_len ) -* -* DESCRIPTION: Perform short reversal on an array of longword. -* -* INPUTS: -* PARAMETERS: -* uchar *X Pointer to array -* u_int16_t X_len Number of bytes -* OUTPUT: -* uchar *X Pointer to array -* -* REVISION HISTORY: -* -* 14 Oct 94 GKL Initial release -* -****************************************************************************/ -void WordSwap( uchar *X, - u_int16_t X_len ) -{ - u_int16_t i; /*counter*/ - u_int16_t a; /*tempriory u_int16_t*/ - - for ( i = 0; i < X_len; i += 4) - { - a = *(u_int16_t*)(&X[i]); - *(u_int16_t*)(&X[i])=*(u_int16_t*)(&X[i+2]); - *(u_int16_t*)(&X[i+2])=a; - } -} - -void BigSwap( uchar *buffer, - u_int16_t bufferLength) -{ - uchar temp; - u_int16_t i; - - for (i = 0; i < (u_int16_t)(bufferLength/2); i++) - { - temp = buffer[i]; - buffer[i] = buffer[bufferLength - 1 - i]; - buffer[bufferLength - 1 - i] = temp; - } -} - -void SetDataOrder ( u_int16_t dataOrder) -{ - DataOrder = dataOrder; -} diff --git a/usr/src/lib/libresolv2/common/cylink/toolkit.h b/usr/src/lib/libresolv2/common/cylink/toolkit.h deleted file mode 100644 index b9ba25ad57..0000000000 --- a/usr/src/lib/libresolv2/common/cylink/toolkit.h +++ /dev/null @@ -1,399 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Cylink Corporation © 1998 - * - * This software is licensed by Cylink to the Internet Software Consortium to - * promote implementation of royalty free public key cryptography within IETF - * standards. Cylink wishes to expressly thank the contributions of Dr. - * Martin Hellman, Whitfield Diffie, Ralph Merkle and Stanford University for - * their contributions to Internet Security. In accordance with the terms of - * this license, ISC is authorized to distribute and sublicense this software - * for the practice of IETF standards. - * - * The software includes BigNum, written by Colin Plumb and licensed by Philip - * R. Zimmermann for royalty free use and distribution with Cylink's - * software. Use of BigNum as a stand alone product or component is - * specifically prohibited. - * - * Disclaimer of All Warranties. THIS SOFTWARE IS BEING PROVIDED "AS IS", - * WITHOUT ANY EXPRESSED OR IMPLIED WARRANTY OF ANY KIND WHATSOEVER. IN - * PARTICULAR, WITHOUT LIMITATION ON THE GENERALITY OF THE FOREGOING, CYLINK - * MAKES NO REPRESENTATION OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR - * PURPOSE. - * - * Cylink or its representatives shall not be liable for tort, indirect, - * special or consequential damages such as loss of profits or loss of - * goodwill from the use or inability to use the software for any purpose or - * for any reason whatsoever. - * - * EXPORT LAW: Export of the Foundations Suite may be subject to compliance - * with the rules and regulations promulgated from time to time by the Bureau - * of Export Administration, United States Department of Commerce, which - * restrict the export and re-export of certain products and technical data. - * If the export of the Foundations Suite is controlled under such rules and - * regulations, then the Foundations Suite shall not be exported or - * re-exported, directly or indirectly, (a) without all export or re-export - * licenses and governmental approvals required by any applicable laws, or (b) - * in violation of any applicable prohibition against the export or re-export - * of any part of the Foundations Suite. All export licenses for software - * containing the Foundations Suite are the sole responsibility of the licensee. - */ - -/**************************************************************************** -* FILENAME: toolkit.h PRODUCT NAME: CRYPTOGRAPHIC TOOLKIT -* -* FILE STATUS: -* -* DESCRIPTION: Cryptographic Toolkit Functions Header File -* -* USAGE: File should be included to use Toolkit Functions -* -* -* Copyright (c) Cylink Corporation 1994. All rights reserved. -* -* REVISION HISTORY: -* -* 23 Aug 94 KPZ Initial release -* 24 Sep 94 KPZ Added prototypes of Toolkit functions -* 14 Oct 94 GKL Second version (big endian support) -* 08 Dec 94 GKL Added YIELD_context to GenDSSParameters -* -****************************************************************************/ - -#ifndef TOOLKIT_H /* Prevent multiple inclusions of same header file */ -#define TOOLKIT_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Error types */ - -#define SUCCESS 0 /* no errors */ -#define ERR_DATA -1 /* generic data error */ -#define ERR_ALLOC -2 /* insufficient memory */ -#define ERR_INPUT_LEN -3 /* invalid length for input data (zero bytes) */ -#define ERR_DSS_LEN -4 /* invalid length for dss_p */ -#define ERR_DH_LEN -5 /* invalid length for DH_modulus */ -#define ERR_BLOCK_LEN -7 /* invalid length for input block for ECB/CBC */ -#define ERR_HASH_LEN -8 /* invalid length for hash_result */ -#define ERR_MODE -9 /* invalid value of encryption mode */ -#define ERR_NUMBER -10 /* invalid number of testings (zero) */ -#define ERR_POSITION -11 /* invalid value of triplet_position */ -#define ERR_COUNT -12 /* invalid iteration count (zero) */ -#define ERR_SIGNATURE -21 /* signature is not valid */ -#define ERR_PRIME -22 /* number is not prime */ -#define ERR_WEAK -23 /* weak key */ -#define ERR_INPUT_VALUE -24 /* invalid input value */ -/* additional error types for CEPA */ -#define ERR_KEY_LENGTH -25 /* invalid value of key length */ -#define ERR_ROUNDS -26 /* invalid value of rounds number */ -#define ERR_CANCEL -30 /* canceled by user */ -#define ERR_MODULUS_ZERO -31 /* invalid modulo */ -#define ERR_UNSUPPORTED -40 /* unsupported crypto method */ -#define ERR_OP_CODE -41 /*invalid operation code*/ - - - -/* Lengths of variables */ -#define DH_LENGTH_MIN 64 /* 512-bit minimal length for DH functions */ -#define DSS_LENGTH_MIN 64 /* 512-bit minimal length for DSS functions */ -#define DSS_LENGTH_MAX 128 /* 1024-bit maximal length for DSS functions */ -#define SHA_LENGTH 20 /* 160-bit length for SHA hash result */ - -/* Number of random bases for Miller test */ -#define TEST_COUNT 40 - -#define LITTLE_ORDER 0 -#define BIG_ORDER 1 - -/* Key lengths */ /* add to toolkit.h */ -#define KEY_40BIT 40 /* 40-bit key */ -#define KEY_64BIT 64 /* 64-bit key */ -#define KEY_128BIT 128 /* 128-bit key */ -#define CEPA_MAX_ROUNDS 12 - -/* Operation codes for MultiPrecArithm() */ -#define EXPO 0x21 -#define MUL 0x22 -/*#define ADD 0x23*/ - -/**************************************************************************** -* INCLUDE FILES -****************************************************************************/ - -/* system files */ -#include "cylink.h" -#include "ctk_endian.h" -/* callback function */ -#ifdef VXD -typedef int (* YIELD_PROC)( void ); -#else -typedef int (* YIELD_PROC)(int ); /*TKL00601*/ -#endif - -typedef struct { /*TKL00601*/ - YIELD_PROC yield_proc; - void * handle; /* Application specific information */ -}YIELD_context; - - -/* Secure Hash Algorithm structure */ -typedef struct -{ - u_int32_t state[ 5 ]; /* state */ - u_int32_t count[ 2 ]; /* number of bits */ - uchar buffer[ 64 ]; /* input buffer */ -} SHA_context; - - -#ifdef __cplusplus -extern "C" { -#endif -/* Copy Cylink DSS Common Parameters */ /*TKL01201*/ - int GetDSSPQG(u_int16_t dss_p_bytes, - uchar *dss_p, - uchar *dss_q, - uchar *dss_g); - -/* Compute a Secure Hash Function */ - int SHA( uchar *message, u_int16_t message_bytes, - uchar *hash_result ); -/* Initialize Secure Hash Function */ - void SHAInit( SHA_context *hash_context ); - -/* Update Secure Hash Function */ - int SHAUpdate( SHA_context *hash_context, - const uchar *message, - u_int16_t message_bytes ); -/* Finalize Secure Hash Function */ - int SHAFinal( SHA_context *hash_context, - uchar *hash_result ); -/* Compute a DSS Signature */ - int GenDSSSignature( u_int16_t dss_p_bytes, uchar *dss_p, - uchar *dss_q, uchar *dss_g, - uchar *dss_x, uchar *dss_k, - uchar *r, uchar *s, - uchar *hash_result ); -/* Verify a DSS Signature */ - int VerDSSSignature( u_int16_t dss_p_bytes, uchar *dss_p, - uchar *dss_q, uchar *dss_g, - uchar *dss_y, uchar *r, - uchar *s, uchar *hash_result); -/* Initialize Random number Generator */ - int InitRand( u_int16_t SEED_bytes, uchar *SEED, - uchar *RVAL ); -/* Generate random number */ - int GenRand( u_int16_t A_bytes, uchar *A, - uchar *RVAL ); -/* Compute DSS public/secret number pair */ - int GenDSSKey( u_int16_t dss_p_bytes, uchar *dss_p, - uchar *dss_q, uchar *dss_g, - uchar *dss_x, uchar *dss_y, - uchar *XKEY ); -/* Generate secret number */ - int GenDSSNumber( uchar *dss_k, uchar *dss_q, - uchar *KKEY ); - -/* Compute a Diffie-Hellman Shared number */ - int GetDHSharedNumber( u_int16_t DH_modulus_bytes, uchar *DH_secret, - uchar *DH_public, uchar *DH_shared, - uchar *DH_modulus ); -/* Set Key by Diffie_Hellman shared number */ - int SetDESKAPPAKey( u_int16_t DH_modulus_bytes, uchar *DH_shared, - uchar *K ); -/* Expand DES key */ - void DESKeyExpand( uchar *key, uchar *K1 ); - -/* Encrypt a block of data with single DES */ - int DESEncrypt( uchar *des_iv, uchar *des_key, - u_int16_t des_mode, uchar *input_array, - uchar *output_array, u_int16_t input_array_bytes ); - -/* Decrypt a block of data with single DES */ - int DESDecrypt( uchar *des_iv, uchar *des_key, - u_int16_t des_mode, uchar *data_array, - u_int16_t data_array_bytes ); - -/* One-Time-Pad Signature with a Diffie-Hellman shared number */ - int DHOneTimePad( u_int16_t DH_modulus_bytes, uchar *DH_shared, - uchar *X, uchar *Y ); - -/* Compute a Diffie-Hellman pair */ - int GenDHPair( u_int16_t DH_modulus_bytes, uchar *DH_secret, - uchar *DH_public, uchar *DH_base, - uchar *DH_modulus, uchar *RVAL ); - - int GetPasswordKeySHA( u_int16_t Password_bytes, uchar *Password, - uchar *salt, u_int16_t Count, - uchar *K, uchar *IV ); - -/* Generate DSS Common Parameters */ - int GenDSSParameters( u_int16_t dss_p_bytes, uchar *dss_p, - uchar *dss_q, uchar *dss_g, - uchar *RVAL, YIELD_context *yield_cont ); /*TKL00701*/ - -/* Produce a Shamir Key-Sharing Triplet for Secret Number */ -int GenShamirTriplet( u_int16_t SecretNumber_bytes, uchar *SecretNumber, - uchar *first_value, uchar *second_value, - uchar *third_value, uchar *RVAL ); - -/* Reconstract a Secret Number from Shamir Key-Sharing Duplex */ -int GetNumberShamirDuplex( u_int16_t SecretNumber_bytes, - uchar *value_A, - u_int16_t A_position, uchar *value_B, - u_int16_t B_position, - uchar *SecretNumber ); -int SFDHEncrypt( u_int16_t DH_modulus_bytes, - uchar *DH_modulus, - uchar *DH_base, - uchar *DH_public, - uchar *DH_random_public, - uchar *DH_shared, - uchar *RVAL ); -int SFDHDecrypt( u_int16_t DH_modulus_bytes, - uchar *DH_modulus, - uchar *DH_secret, - uchar *DH_random_public, - uchar *DH_shared ); -/* Check DES key weakness */ -int CheckDESKeyWeakness( uchar *key ); - -int SetCipherKey( u_int16_t DH_shared_bytes, - uchar *DH_shared, - uchar *Key, - u_int16_t cryptoMethod ); -/* Non-Pipelined Triple DES encrypt*/ -int TDESEncrypt( uchar *des_iv, - uchar *des_key1,uchar *des_key2, uchar *des_key3, - u_int16_t des_mode, - uchar *input_array, - uchar *output_array, - u_int16_t input_array_bytes ); -/* Non-Pipelined Triple DES decrypt*/ -int TDESDecrypt( uchar *des_iv, - uchar *des_key1,uchar *des_key2, uchar *des_key3, - u_int16_t des_mode, - uchar *data_array, - u_int16_t data_array_bytes ); -/*Pipeline Triple DES encrypt*/ -int PTDESEncrypt( uchar *iv1, uchar *iv2, uchar *iv3, - uchar *des_key1,uchar *des_key2, uchar *des_key3, - u_int16_t des_mode, - uchar *input_array, - uchar *output_array, - u_int16_t input_array_bytes ); -/*Pipeline Triple DES decrypt*/ -int PTDESDecrypt( uchar *iv1, uchar *iv2, uchar *iv3, - uchar *des_key1,uchar *des_key2, uchar *des_key3, - u_int16_t des_mode, - uchar *data_array, - u_int16_t input_array_bytes ); - int PCBC1Encrypt( uchar *iv1, uchar *iv2, uchar *iv3, - uchar *des_key1,uchar *des_key2, uchar *des_key3, - uchar *msg1,uchar *msg2, uchar *msg3, - uchar *out1,uchar *out2, uchar *out3, - u_int16_t input_array_bytes ); - int PCBC1Decrypt( uchar *iv1, uchar *iv2, uchar *iv3, - uchar *des_key1,uchar *des_key2, uchar *des_key3, - uchar *out1,uchar *out2, uchar *out3, - u_int16_t input_array_bytes ); - -/*CEPA enc/dec */ -int CepaKeyExpand( uchar *key, - u_int16_t key_length, - u_int16_t number_of_rounds, - uchar *expanded_key ); - -int CepaCsp( u_int16_t key_length, - uchar *csp); - -int CepaEncrypt( uchar *iv, - uchar *key, - u_int16_t mode, - uchar *csp, - u_int16_t r, - uchar *input_array, - uchar *output_array, - u_int16_t input_array_bytes ); - -int CepaDecrypt( uchar *iv, - uchar *key, - u_int16_t mode, - uchar *csp, - u_int16_t r, - uchar *data_array, - u_int16_t data_array_bytes ); -void BigNumInit(void); -void SetDataOrder ( u_int16_t dataOrder); - -int GetDHSecretShared( u_int16_t DH_modulus_bytes, u_int16_t DH_secret_bytes, uchar *DH_secret, - uchar *DH_public, uchar *DH_shared, - uchar *DH_modulus); -int GenDHKey( u_int16_t DH_modulus_bytes, u_int16_t DH_secret_bytes, uchar *DH_secret, - uchar *DH_public, uchar *DH_base, - uchar *DH_modulus, uchar *RVAL ); -int SFDHInitiate( u_int16_t DH_modulus_bytes, u_int16_t DH_secret_bytes, - uchar *DH_modulus, uchar *DH_base, - uchar *DH_public, uchar *DH_random_public, - uchar *DH_shared, uchar *RVAL ); -int SFDHComplete( u_int16_t DH_modulus_bytes, u_int16_t DH_secret_bytes, - uchar *DH_modulus, - uchar *DH_secret, uchar *DH_random_public, - uchar *DH_shared ); - -int SplitKey( u_int16_t Secretnumber_bytes, uchar *SecretNumber, - uchar *first_value, uchar *second_value, - uchar *third_value, uchar *RVAL ); -int UnsplitKey( u_int16_t Secretnumber_bytes, uchar *value_A, - u_int16_t A_position, uchar *value_B, - u_int16_t B_position, uchar *SecretNumber ); -int SAFERKeyExpand( uchar *key, u_int16_t key_length, - uchar *expanded_key ); -int SAFEREncrypt( uchar *iv, uchar *key, u_int16_t mode, u_int16_t key_length, - uchar *input_array, uchar *output_array, u_int16_t input_array_bytes ); -int SAFERDecrypt( uchar *iv, uchar *key, u_int16_t mode, u_int16_t r_length, - uchar *data_array, u_int16_t data_array_bytes ); - - - void ByteSwap( uchar *X, u_int16_t X_len); - void ByteSwap32( uchar *X, u_int16_t X_len); - void WordSwap( uchar *X, u_int16_t X_len); - void BigSwap( uchar *buffer, u_int16_t bufferLength); - int Sum_big (ord *X, ord *Y, ord *Z, u_int16_t len_X); - int Sum_Q(ord *X, u_int16_t src, u_int16_t len_X); - void LShiftL_big( ord *X, u_int32_t len_X, u_int32_t n_bit ); - int Sub_big (ord *X, ord *Y, ord *Z, u_int16_t len_X); - int DivRem( u_int16_t X_bytes, ord *X, u_int16_t P_bytes, ord *P, - ord *Z, ord *D); - int SteinGCD (ord *m, ord *n, u_int16_t len); - int Add( ord *X, ord *Y, u_int16_t P_len, ord *P); - int Inverse(u_int16_t X_bytes, ord *X, u_int16_t P_bytes, ord *P, - ord *Z); - int DoubleExpo(u_int16_t X1_bytes, ord *X1, u_int16_t Y1_bytes, - ord *Y1, u_int16_t X2_bytes, ord *X2, - u_int16_t Y2_bytes, ord *Y2, u_int16_t P_bytes, - ord *P, ord *Z); - int Sum (ord *X, ord *Y, u_int16_t len_X); - void Mul_big_1( ord X, ord *Y, ord *XY, u_int16_t ly); - int Mul( u_int16_t X_bytes, ord *X, u_int16_t Y_bytes, ord *Y, - u_int16_t P_bytes, ord *P, ord *Z ); - - int Square(u_int16_t X_bytes, ord *X, u_int16_t P_bytes, ord *P, - ord *Z); - - int PartReduct(u_int16_t X_bytes, ord *X, u_int16_t P_bytes, ord *P, - ord *Z); - int Expo(u_int16_t X_bytes, ord *X, u_int16_t Y_bytes, ord *Y, - u_int16_t P_bytes, ord *P, ord *Z); - - -#ifdef __cplusplus -} -#endif - - -#endif /* TOOLKIT_H */ - diff --git a/usr/src/lib/libresolv2/common/dnssafe/README.copyright b/usr/src/lib/libresolv2/common/dnssafe/README.copyright deleted file mode 100644 index bfbd0a4d3b..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/README.copyright +++ /dev/null @@ -1,51 +0,0 @@ -#pragma ident "%Z%%M% %I% %E% SMI" - -[The copyright in this file amends the "RSA Data Security, Inc." copyrights -in the source files in this directory, according to an email from David R. -Conrad, executive director at ISC, on 02/07/2000.] - - - - DNSSAFE LICENSE TERMS - -This BIND software includes the DNSsafe software from RSA Data -Security, Inc., which is copyrighted software that can only be -distributed under the terms of this license agreement. - -The DNSsafe software cannot be used or distributed separately from the -BIND software. You only have the right to use it or distribute it as -a bundled, integrated product. - -The DNSsafe software can ONLY be used to provide authentication for -resource records in the Domain Name System, as specified in RFC 2065 -and successors. You cannot modify the BIND software to use the -DNSsafe software for other purposes, or to make its cryptographic -functions available to end-users for other uses. - -If you modify the DNSsafe software itself, you cannot modify its -documented API, and you must grant RSA Data Security the right to use, -modify, and distribute your modifications, including the right to use -any patents or other intellectual property that your modifications -depend upon. - -You must not remove, alter, or destroy any of RSA's copyright notices -or license information. When distributing the software to the Federal -Government, it must be licensed to them as "commercial computer -software" protected under 48 CFR 12.212 of the FAR, or 48 CFR -227.7202.1 of the DFARS. - -You must not violate United States export control laws by distributing -the DNSsafe software or information about it, when such distribution -is prohibited by law. - -THE DNSSAFE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY -WHATSOEVER. RSA HAS NO OBLIGATION TO SUPPORT, CORRECT, UPDATE OR -MAINTAIN THE RSA SOFTWARE. RSA DISCLAIMS ALL WARRANTIES, EXPRESS, -IMPLIED OR STATUTORY, AS TO ANY MATTER WHATSOEVER, INCLUDING ALL -IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY RIGHTS. - -If you desire to use DNSsafe in ways that these terms do not permit, -please contact RSA Data Security, Inc., 100 Marine Parkway, Redwood -City, California 94065, USA, to discuss alternate licensing -arrangements. diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahcbcpad.c b/usr/src/lib/libresolv2/common/dnssafe/ahcbcpad.c deleted file mode 100644 index bfdfd048aa..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahcbcpad.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -/* Define this so that the type of the 'this' pointer in the - virtual functions will be correct for this derived class. - */ -struct AHSecretCBCPad; -#define THIS_ENCRYPT_DECRYPT struct AHSecretCBCPad - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ahcbcpad.h" -#include "port_after.h" - -#define GENERATE_BREAK(type) { \ - status = type; \ - break; \ - } - -/* Inherit the base class destructor, block size, - and decrypt init and update routines. - */ -static AHEncryptDecryptVTable V_TABLE = { - AHChooseEncryptDestructor, AHChooseEncryptGetBlockLen, - AHSecretCBCPadEncryptInit, AHChooseEncryptDecryptInit, - AHSecretCBCPadEncryptUpdate, AHChooseEncryptDecryptUpdate, - AHSecretCBCPadEncryptFinal, AHSecretCBCPadDecryptFinal -}; - -AHSecretCBCPad *AHSecretCBCPadConstructor2 (handler, infoType, info) -AHSecretCBCPad *handler; -struct B_AlgorithmInfoType *infoType; -POINTER info; -{ - if (handler == (AHSecretCBCPad *)NULL_PTR) { - /* This constructor is being used to do a new */ - if ((handler = (AHSecretCBCPad *)T_malloc (sizeof (*handler))) - == (AHSecretCBCPad *)NULL_PTR) - return (handler); - } - - /* Construct base class with the infoType and info. */ - AHChooseEncryptConstructor2 - (&handler->chooseEncryptDecrypt, infoType, info); - - handler->chooseEncryptDecrypt.encryptDecrypt.vTable = &V_TABLE; - return (handler); -} - -int AHSecretCBCPadEncryptInit (handler, key, chooser, surrenderContext) -AHSecretCBCPad *handler; -B_Key *key; -B_ALGORITHM_CHOOSER chooser; -A_SURRENDER_CTX *surrenderContext; -{ - /* For encryption, we need to track the input length */ - handler->_inputRemainder = 0; - - return (AHChooseEncryptEncryptInit - (handler, key, chooser, surrenderContext)); -} - -int AHSecretCBCPadEncryptUpdate - (handler, partOut, partOutLen, maxPartOutLen, partIn, partInLen, - randomAlgorithm, surrenderContext) -AHSecretCBCPad *handler; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -const unsigned char *partIn; -unsigned int partInLen; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - /* For encryption, we need to track the input length */ - handler->_inputRemainder = (handler->_inputRemainder + partInLen) % 8; - - return (AHChooseEncryptEncryptUpdate - (handler, partOut, partOutLen, maxPartOutLen, partIn, partInLen, - randomAlgorithm, surrenderContext)); -} - -int AHSecretCBCPadEncryptFinal - (handler, partOut, partOutLen, maxPartOutLen, randomAlgorithm, - surrenderContext) -AHSecretCBCPad *handler; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - unsigned char finalBuffer[8]; - unsigned int padLen, dummyPartOutLen; - - padLen = 8 - handler->_inputRemainder; - T_memset ((POINTER)finalBuffer, padLen, padLen); - - /* Add the pad bytes. This should force the output of the final block. - */ - if ((status = AHChooseEncryptEncryptUpdate - (handler, partOut, partOutLen, maxPartOutLen, finalBuffer, padLen, - randomAlgorithm, surrenderContext)) != 0) - return (status); - - /* The encrypt final operation should have no output. */ - if ((status = AHChooseEncryptEncryptFinal - (handler, (unsigned char *)NULL_PTR, &dummyPartOutLen, 0, - (B_Algorithm *)NULL_PTR, (A_SURRENDER_CTX *)NULL_PTR)) != 0) - return (status); - - /* Restart the context. */ - handler->_inputRemainder = 0; - - /* No need to zeroize the finalBuffer since it only contains pad bytes. */ - return (0); -} - -int AHSecretCBCPadDecryptFinal - (handler, partOut, partOutLen, maxPartOutLen, randomAlgorithm, - surrenderContext) -AHSecretCBCPad *handler; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - unsigned char finalBuffer[16], *padBuffer; - unsigned int padLen, localPartOutLen, i; - - do { - /* For now, the DecrypyFinal operations is set to output 16 bytes. - */ - if ((status = AHChooseEncryptDecryptFinal - (handler, finalBuffer, &localPartOutLen, sizeof (finalBuffer), - randomAlgorithm, surrenderContext)) != 0) - break; - - if (localPartOutLen == 8) - padBuffer = finalBuffer; - else if (localPartOutLen == 16) - padBuffer = finalBuffer + 8; - else - GENERATE_BREAK (BE_INPUT_LEN); - - /* Check that padding is one 1 to eight 8's. - */ - if ((padLen = (unsigned int)padBuffer[7]) == 0 || padLen > 8) - GENERATE_BREAK (BE_INPUT_DATA); - for (i = 8 - padLen; i < 8; i++) { - if ((unsigned int)padBuffer[i] != padLen) - GENERATE_BREAK (BE_INPUT_DATA); - } - - if ((*partOutLen = localPartOutLen - padLen) > maxPartOutLen) - GENERATE_BREAK (BE_OUTPUT_LEN); - - T_memcpy - ((POINTER)partOut, (POINTER)finalBuffer, *partOutLen); - } while (0); - - T_memset ((POINTER)finalBuffer, 0, sizeof (finalBuffer)); - return (status); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahcbcpad.h b/usr/src/lib/libresolv2/common/dnssafe/ahcbcpad.h deleted file mode 100644 index e72a5d770c..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahcbcpad.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AHCBCPAD_H_ -#define _AHCBCPAD_H_ - -#include "ahchencr.h" - -typedef struct AHSecretCBCPad { - AHChooseEncryptDecrypt chooseEncryptDecrypt; /* base class */ - - unsigned int _inputRemainder; /* Used for encrypt to compute pad length */ -} AHSecretCBCPad; - -AHSecretCBCPad *AHSecretCBCPadConstructor2 PROTO_LIST - ((AHSecretCBCPad *, struct B_AlgorithmInfoType *, POINTER)); - -int AHSecretCBCPadEncryptInit PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, B_Key *, B_ALGORITHM_CHOOSER, - A_SURRENDER_CTX *)); -int AHSecretCBCPadEncryptUpdate PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned char *, unsigned int *, - unsigned int, const unsigned char *, unsigned int, B_Algorithm *, - A_SURRENDER_CTX *)); -int AHSecretCBCPadEncryptFinal PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned char *, unsigned int *, - unsigned int, B_Algorithm *, A_SURRENDER_CTX *)); -int AHSecretCBCPadDecryptFinal PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned char *, unsigned int *, - unsigned int, B_Algorithm *, A_SURRENDER_CTX *)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahchdig.c b/usr/src/lib/libresolv2/common/dnssafe/ahchdig.c deleted file mode 100644 index 574bdb8154..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahchdig.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -/* Define this so that the type of the 'this' pointer in the - virtual functions will be correct for this derived class. - */ -struct AHChooseDigest; -#define THIS_DIGEST struct AHChooseDigest - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "balgmeth.h" -#include "ahchdig.h" -#include "amdigest.h" -#include "port_after.h" - -static int InitDigestAlga PROTO_LIST - ((AlgaChoice *, POINTER, B_ALGORITHM_METHOD *, A_SURRENDER_CTX *)); - -static AHDigestVTable V_TABLE = { - AHChooseDigestDestructor, AHChooseDigestInit, AHChooseDigestUpdate, - AHChooseDigestFinal -}; - -AHChooseDigest *AHChooseDigestConstructor2 (handler, infoType, info) -AHChooseDigest *handler; -struct B_AlgorithmInfoType *infoType; -POINTER info; -{ - if (handler == (AHChooseDigest *)NULL_PTR) { - /* This constructor is being used to do a new */ - if ((handler = (AHChooseDigest *)T_malloc (sizeof (*handler))) - == (AHChooseDigest *)NULL_PTR) - return (handler); - } - - /* Construct base class */ - AHDigestConstructor (&handler->digest); - - ALGA_CHOICE_Constructor (&handler->algaChoice, InitDigestAlga); - handler->algaChoice._algorithmInfoType = infoType; - handler->algaChoice._algorithmInfo = info; - - handler->digest.vTable = &V_TABLE; - - return (handler); -} - -void AHChooseDigestDestructor (handler) -AHChooseDigest *handler; -{ - ALGA_CHOICE_Destructor (&handler->algaChoice); - /* There is no desructor to call for the base class. */ -} - -int AHChooseDigestInit (handler, key, chooser, surrenderContext) -AHChooseDigest *handler; -B_Key *key; -B_ALGORITHM_CHOOSER chooser; -A_SURRENDER_CTX *surrenderContext; -{ - return (AlgaChoiceChoose - (&handler->algaChoice, 0, key, chooser, surrenderContext)); -} - -int AHChooseDigestUpdate (handler, partIn, partInLen, surrenderContext) -AHChooseDigest *handler; -const unsigned char *partIn; -unsigned int partInLen; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = (*((A_DIGEST_ALGA *)handler->algaChoice._alga)->Update) - (handler->algaChoice.context.z.context, partIn, partInLen, - surrenderContext)) != 0) - return (ConvertAlgaeError (status)); - return (0); -} - -int AHChooseDigestFinal - (handler, partOut, partOutLen, maxPartOutLen, surrenderContext) -AHChooseDigest *handler; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = (*((A_DIGEST_ALGA *)handler->algaChoice._alga)->Final) - (handler->algaChoice.context.z.context, partOut, partOutLen, - maxPartOutLen, surrenderContext)) != 0) - return (ConvertAlgaeError (status)); - return (0); -} - -static int InitDigestAlga - (algaChoice, keyInfo, algorithmMethod, surrenderContext) -AlgaChoice *algaChoice; -POINTER keyInfo; -B_ALGORITHM_METHOD *algorithmMethod; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - unsigned int contextSize; - -UNUSED_ARG (keyInfo) - if ((status = (*((A_DIGEST_ALGA *)algorithmMethod->alga)->Query) - (&contextSize, algaChoice->_algorithmInfo)) != 0) - return (ConvertAlgaeError (status)); - - if ((status = ResizeContextMakeNewContext - (&algaChoice->context, contextSize)) != 0) - return (status); - - if ((status = (*((A_DIGEST_ALGA *)algorithmMethod->alga)->Init) - (algaChoice->context.z.context, algaChoice->_algorithmInfo, - surrenderContext)) != 0) - return (ConvertAlgaeError (status)); - - return (0); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahchdig.h b/usr/src/lib/libresolv2/common/dnssafe/ahchdig.h deleted file mode 100644 index a80c3d208e..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahchdig.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AHCHDIG_H_ -#define _AHCHDIG_H_ 1 - -#include "ahdigest.h" -#include "algchoic.h" - -typedef struct AHChooseDigest { - AHDigest digest; /* base class */ - AlgaChoice algaChoice; -} AHChooseDigest; - -AHChooseDigest *AHChooseDigestConstructor2 PROTO_LIST - ((AHChooseDigest *, struct B_AlgorithmInfoType *, POINTER)); -void AHChooseDigestDestructor PROTO_LIST ((THIS_DIGEST *)); - -int AHChooseDigestInit PROTO_LIST - ((THIS_DIGEST *, B_Key *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int AHChooseDigestUpdate PROTO_LIST - ((THIS_DIGEST *, const unsigned char *, unsigned int, A_SURRENDER_CTX *)); -int AHChooseDigestFinal PROTO_LIST - ((THIS_DIGEST *, unsigned char *, unsigned int *, unsigned int, - A_SURRENDER_CTX *)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahchencr.c b/usr/src/lib/libresolv2/common/dnssafe/ahchencr.c deleted file mode 100644 index 6d339824fc..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahchencr.c +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -/* Define this so that the type of the 'this' pointer in the - virtual functions will be correct for this derived class. - */ -struct AHChooseEncryptDecrypt; -#define THIS_ENCRYPT_DECRYPT struct AHChooseEncryptDecrypt - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "balgmeth.h" -#include "ahchencr.h" -#include "amencdec.h" -#include "port_after.h" - -static int InitEncryptDecryptAlga PROTO_LIST - ((AlgaChoice *, POINTER, B_ALGORITHM_METHOD *, A_SURRENDER_CTX *)); - -static AHEncryptDecryptVTable V_TABLE = { - AHChooseEncryptDestructor, AHChooseEncryptGetBlockLen, - AHChooseEncryptEncryptInit, AHChooseEncryptDecryptInit, - AHChooseEncryptEncryptUpdate, AHChooseEncryptDecryptUpdate, - AHChooseEncryptEncryptFinal, AHChooseEncryptDecryptFinal -}; - -/* In C++: -AHChooseEncryptDecrypt::AHChooseEncryptDecrypt - (B_AlgorithmInfoType *infoType, POINTER info) - : algaChoice (InitEncryptDecryptAlga) -{ - algaChoice.setAlgorithmInfoType (infoType); - algaChoice.setAlgorithmInfo (info); -} - */ -AHChooseEncryptDecrypt *AHChooseEncryptConstructor2 (handler, infoType, info) -AHChooseEncryptDecrypt *handler; -struct B_AlgorithmInfoType *infoType; -POINTER info; -{ - if (handler == (AHChooseEncryptDecrypt *)NULL_PTR) { - /* This constructor is being used to do a new */ - if ((handler = (AHChooseEncryptDecrypt *)T_malloc (sizeof (*handler))) - == (AHChooseEncryptDecrypt *)NULL_PTR) - return (handler); - } - - /* Construct base class */ - AHEncryptDecryptConstructor (&handler->encryptDecrypt); - - ALGA_CHOICE_Constructor (&handler->algaChoice, InitEncryptDecryptAlga); - handler->algaChoice._algorithmInfoType = infoType; - handler->algaChoice._algorithmInfo = info; - - handler->encryptDecrypt.vTable = &V_TABLE; - - return (handler); -} - -void AHChooseEncryptDestructor (handler) -AHChooseEncryptDecrypt *handler; -{ - ALGA_CHOICE_Destructor (&handler->algaChoice); - /* There is no desructor to call for the base class. */ -} - -int AHChooseEncryptGetBlockLen (handler, blockLen) -AHChooseEncryptDecrypt *handler; -unsigned int *blockLen; -{ - int status; - - if ((status = (*((A_ENCRYPT_DECRYPT_ALGA *)handler->algaChoice._alga)-> - GetBlockLen) - (handler->algaChoice.context.z.context, blockLen)) != 0) - return (ConvertAlgaeError (status)); - return (0); -} - -/* In C++: -int AHChooseEncryptDecrypt::encryptInit - (B_Key *key, B_ALGORITHM_CHOOSER chooser, A_SURRENDER_CTX *surrenderContext) -{ - return (algaChoice.choose (1, key, chooser, surrenderContext)); -} - */ -int AHChooseEncryptEncryptInit (handler, key, chooser, surrenderContext) -AHChooseEncryptDecrypt *handler; -B_Key *key; -B_ALGORITHM_CHOOSER chooser; -A_SURRENDER_CTX *surrenderContext; -{ - return (AlgaChoiceChoose - (&handler->algaChoice, 1, key, chooser, surrenderContext)); -} - -int AHChooseEncryptDecryptInit (handler, key, chooser, surrenderContext) -AHChooseEncryptDecrypt *handler; -B_Key *key; -B_ALGORITHM_CHOOSER chooser; -A_SURRENDER_CTX *surrenderContext; -{ - return (AlgaChoiceChoose - (&handler->algaChoice, 0, key, chooser, surrenderContext)); -} - -/* In C++: -int AHChooseEncryptDecrypt::encryptUpdate - (unsigned char *partOut, unsigned int *partOutLen, - unsigned int maxPartOutLen, unsigned char *partIn, unsigned int partInLen, - B_Algorithm *randomAlgorithm, A_SURRENDER_CTX *surrenderContext) -{ - int status; - - if ((status = (*((A_ENCRYPT_DECRYPT_ALGA *)algaChoice.alga ()) ->Update) - (algaChoice.context (), partOut, partOutLen, maxPartOutLen, - partIn, partInLen, surrenderContext)) != 0) - return (ConvertAlgaeError (status)); - return (0); -} - */ -int AHChooseEncryptEncryptUpdate - (handler, partOut, partOutLen, maxPartOutLen, partIn, partInLen, - randomAlgorithm, surrenderContext) -AHChooseEncryptDecrypt *handler; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -const unsigned char *partIn; -unsigned int partInLen; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - -UNUSED_ARG (randomAlgorithm) - - if ((status = (*((A_ENCRYPT_DECRYPT_ALGA *)handler->algaChoice._alga)-> - Update) - (handler->algaChoice.context.z.context, partOut, partOutLen, - maxPartOutLen, partIn, partInLen, surrenderContext)) != 0) - return (ConvertAlgaeError (status)); - return (0); -} - -int AHChooseEncryptDecryptUpdate - (handler, partOut, partOutLen, maxPartOutLen, partIn, partInLen, - randomAlgorithm, surrenderContext) -AHChooseEncryptDecrypt *handler; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -const unsigned char *partIn; -unsigned int partInLen; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - -UNUSED_ARG (randomAlgorithm) - - if ((status = (*((A_ENCRYPT_DECRYPT_ALGA *)handler->algaChoice._alga)-> - Update) - (handler->algaChoice.context.z.context, partOut, partOutLen, - maxPartOutLen, partIn, partInLen, surrenderContext)) != 0) - return (ConvertAlgaeError (status)); - return (0); -} - -int AHChooseEncryptEncryptFinal - (handler, partOut, partOutLen, maxPartOutLen, randomAlgorithm, - surrenderContext) -AHChooseEncryptDecrypt *handler; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - -UNUSED_ARG (randomAlgorithm) - - if ((status = (*((A_ENCRYPT_DECRYPT_ALGA *)handler->algaChoice._alga)->Final) - (handler->algaChoice.context.z.context, partOut, partOutLen, - maxPartOutLen, surrenderContext)) != 0) - return (ConvertAlgaeError (status)); - return (0); -} - -int AHChooseEncryptDecryptFinal - (handler, partOut, partOutLen, maxPartOutLen, randomAlgorithm, - surrenderContext) -AHChooseEncryptDecrypt *handler; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - -UNUSED_ARG (randomAlgorithm) - - if ((status = (*((A_ENCRYPT_DECRYPT_ALGA *)handler->algaChoice._alga)->Final) - (handler->algaChoice.context.z.context, partOut, partOutLen, - maxPartOutLen, surrenderContext)) != 0) - return (ConvertAlgaeError (status)); - return (0); -} - -/* In C++: -static int InitEncryptDecryptAlga - (AlgaChoice *algaChoice, POINTER keyInfo, POINTER alga, - A_SURRENDER_CTX *surrenderContext) -{ - int status; - unsigned int contextSize; - - if ((status = (*((A_ENCRYPT_DECRYPT_ALGA *)alga)->Query) - (&contextSize, keyInfo, algaChoice->algorithmInfo ())) != 0) - return (ConvertAlgaeError (status)); - - if ((status = algaChoice->makeNewContext (contextSize)) != 0) - return (status); - - if ((status = (*((A_ENCRYPT_DECRYPT_ALGA *)alga)->Init) - (algaChoice->context (), keyInfo, algaChoice->algorithmInfo (), - surrenderContext)) != 0) - return (ConvertAlgaeError (status)); - - return (0); -} - */ -static int InitEncryptDecryptAlga - (algaChoice, keyInfo, algorithmMethod, surrenderContext) -AlgaChoice *algaChoice; -POINTER keyInfo; -B_ALGORITHM_METHOD *algorithmMethod; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - unsigned int contextSize; - - if ((status = (*((A_ENCRYPT_DECRYPT_ALGA *)algorithmMethod->alga)->Query) - (&contextSize, keyInfo, algaChoice->_algorithmInfo)) != 0) - return (ConvertAlgaeError (status)); - - if ((status = ResizeContextMakeNewContext - (&algaChoice->context, contextSize)) != 0) - return (status); - - if ((status = (*((A_ENCRYPT_DECRYPT_ALGA *)algorithmMethod->alga)->Init) - (algaChoice->context.z.context, keyInfo, algaChoice->_algorithmInfo, - surrenderContext)) != 0) - return (ConvertAlgaeError (status)); - - return (0); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahchencr.h b/usr/src/lib/libresolv2/common/dnssafe/ahchencr.h deleted file mode 100644 index 82e1a59244..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahchencr.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AHCHENCR_H_ -#define _AHCHENCR_H_ 1 - -#include "ahencryp.h" -#include "algchoic.h" - -/* In C++: -class AHChooseEncryptDecrypt : public AHEncryptDecrypt { -public: - AHChooseEncryptDecrypt (B_AlgorithmInfoType *, POINTER); - virtual ~AHChooseEncryptDecrypt () {}; - - virtual int getBlockLen (unsigned int *); - virtual int encryptInit (B_Key *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *); - virtual int decryptInit (B_Key *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *); - virtual int encryptUpdate - (unsigned char *, unsigned int *, unsigned int, unsigned char *, - unsigned int, B_Algorithm *, A_SURRENDER_CTX *); - virtual int decryptUpdate - (unsigned char *, unsigned int *, unsigned int, unsigned char *, - unsigned int, B_Algorithm *, A_SURRENDER_CTX *); - virtual int encryptFinal - (unsigned char *, unsigned int *, unsigned int, B_Algorithm *, - A_SURRENDER_CTX *); - virtual int decryptFinal - (unsigned char *, unsigned int *, unsigned int, B_Algorithm *, - A_SURRENDER_CTX *); - -private: - AlgaChoice algaChoice; -}; - */ - -typedef struct AHChooseEncryptDecrypt { - AHEncryptDecrypt encryptDecrypt; /* base class */ - AlgaChoice algaChoice; -} AHChooseEncryptDecrypt; - -AHChooseEncryptDecrypt *AHChooseEncryptConstructor2 PROTO_LIST - ((AHChooseEncryptDecrypt *, struct B_AlgorithmInfoType *, POINTER)); -void AHChooseEncryptDestructor PROTO_LIST ((THIS_ENCRYPT_DECRYPT *)); - -int AHChooseEncryptGetBlockLen PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned int *)); -int AHChooseEncryptEncryptInit PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, B_Key *, B_ALGORITHM_CHOOSER, - A_SURRENDER_CTX *)); -int AHChooseEncryptDecryptInit PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, B_Key *, B_ALGORITHM_CHOOSER, - A_SURRENDER_CTX *)); -int AHChooseEncryptEncryptUpdate PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned char *, unsigned int *, - unsigned int, const unsigned char *, unsigned int, B_Algorithm *, - A_SURRENDER_CTX *)); -int AHChooseEncryptDecryptUpdate PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned char *, unsigned int *, - unsigned int, const unsigned char *, unsigned int, B_Algorithm *, - A_SURRENDER_CTX *)); -int AHChooseEncryptEncryptFinal PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned char *, unsigned int *, - unsigned int, B_Algorithm *, A_SURRENDER_CTX *)); -int AHChooseEncryptDecryptFinal PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned char *, unsigned int *, - unsigned int, B_Algorithm *, A_SURRENDER_CTX *)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahchgen.c b/usr/src/lib/libresolv2/common/dnssafe/ahchgen.c deleted file mode 100644 index c0e94a7c15..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahchgen.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -/* Define this so that the type of the 'this' pointer in the - virtual functions will be correct for this derived class. - */ -struct AHChooseGenerate; -#define THIS_GENERATE struct AHChooseGenerate - -/* Define this so that the type of the AlgaChoice pointer in the - INIT_ALGA functions will be correct for this derived class. - */ -struct GenerateAlgaChoice; -#define THIS_ALGA_CHOICE struct GenerateAlgaChoice - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "balgmeth.h" -#include "ahchgen.h" -#include "amgen.h" -#include "port_after.h" - -static int InitGenerateAlga PROTO_LIST - ((GenerateAlgaChoice *, POINTER, B_ALGORITHM_METHOD *, A_SURRENDER_CTX *)); -static int GenerateResult PROTO_LIST - ((GenerateAlgaChoice *, POINTER *, B_Algorithm *, A_SURRENDER_CTX *)); - -static AHGenerateVTable V_TABLE = { - AHChooseGenerateDestructor, AHChooseGenerateInit, AHChooseGenerateKeypair, - AHChooseGenerateParameters -}; - -AHChooseGenerate *AHChooseGenerateConstructor2 (handler, infoType, info) -AHChooseGenerate *handler; -struct B_AlgorithmInfoType *infoType; -POINTER info; -{ - if (handler == (AHChooseGenerate *)NULL_PTR) { - /* This constructor is being used to do a new */ - if ((handler = (AHChooseGenerate *)T_malloc (sizeof (*handler))) - == (AHChooseGenerate *)NULL_PTR) - return (handler); - } - - /* Construct base class */ - AHGenerateConstructor (&handler->generate); - - ALGA_CHOICE_Constructor - (&handler->generateAlgaChoice.algaChoice, InitGenerateAlga); - ResizeContextConstructor (&handler->generateAlgaChoice.secondContext); - ResizeContextConstructor (&handler->generateAlgaChoice.randomBlock); - - /* Set algaChoice. - */ - handler->generateAlgaChoice.algaChoice._algorithmInfoType = infoType; - handler->generateAlgaChoice.algaChoice._algorithmInfo = info; - - handler->generate.vTable = &V_TABLE; - - return (handler); -} - -void AHChooseGenerateDestructor (handler) -AHChooseGenerate *handler; -{ - ResizeContextDestructor (&handler->generateAlgaChoice.secondContext); - ResizeContextDestructor (&handler->generateAlgaChoice.randomBlock); - ALGA_CHOICE_Destructor (&handler->generateAlgaChoice.algaChoice); - /* There is no desructor to call for the base class. */ -} - -int AHChooseGenerateInit (handler, chooser, surrenderContext) -AHChooseGenerate *handler; -B_ALGORITHM_CHOOSER chooser; -A_SURRENDER_CTX *surrenderContext; -{ - return (AlgaChoiceChoose - (&handler->generateAlgaChoice.algaChoice, 0, (B_Key *)NULL_PTR, - chooser, surrenderContext)); -} - -int AHChooseGenerateKeypair - (handler, publicKey, privateKey, randomAlgorithm, surrenderContext) -AHChooseGenerate *handler; -B_Key *publicKey; -B_Key *privateKey; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - POINTER result; - int status; - - if ((status = GenerateResult - (&handler->generateAlgaChoice, &result, randomAlgorithm, - surrenderContext)) != 0) - return (status); - if ((status = B_KeySetInfo - (publicKey, handler->generateAlgaChoice._resultInfoType, result)) != 0) - return (status); - return (B_KeySetInfo - (privateKey, handler->generateAlgaChoice._resultInfoType, result)); -} - -int AHChooseGenerateParameters - (handler, resultAlgorithm, randomAlgorithm, surrenderContext) -AHChooseGenerate *handler; -B_Algorithm *resultAlgorithm; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - POINTER result; - int status; - - if ((status = GenerateResult - (&handler->generateAlgaChoice, &result, randomAlgorithm, - surrenderContext)) != 0) - return (status); - - /* Force the resultInfoType into a B_AlgorithmInfoType since it is - supplied in the chooser as a B_KeyInfoType. */ - return (B_AlgorithmSetInfo - (resultAlgorithm, (struct B_AlgorithmInfoType *) - handler->generateAlgaChoice._resultInfoType, result)); -} - -static int InitGenerateAlga - (generateAlgaChoice, keyInfo, algorithmMethod, surrenderContext) -GenerateAlgaChoice *generateAlgaChoice; -POINTER keyInfo; -B_ALGORITHM_METHOD *algorithmMethod; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - unsigned int contextSize, secondContextSize; - -UNUSED_ARG (keyInfo) - /* Note that this also gets the resultInfoType which will be used later - by GenerateResult. */ - if ((status = (*((A_GENERATE_ALGA *)algorithmMethod->alga)->Query) - (&contextSize, &secondContextSize, &generateAlgaChoice->_randomBlockLen, - &generateAlgaChoice->_resultInfoType, - generateAlgaChoice->algaChoice._algorithmInfo)) != 0) - return (ConvertAlgaeError (status)); - - /* Create the context. - */ - if ((status = ResizeContextMakeNewContext - (&generateAlgaChoice->algaChoice.context, contextSize)) != 0) - return (status); - - /* Create the second context which is only passed during Init, but - must persist for all operations. */ - if ((status = ResizeContextMakeNewContext - (&generateAlgaChoice->secondContext, secondContextSize)) != 0) - return (status); - - /* Create randomBlock which will be filled in during GenerateResult. */ - if ((status = ResizeContextMakeNewContext - (&generateAlgaChoice->randomBlock, generateAlgaChoice->_randomBlockLen)) - != 0) - return (status); - - if ((status = (*((A_GENERATE_ALGA *)algorithmMethod->alga)->Init) - (generateAlgaChoice->algaChoice.context.z.context, - generateAlgaChoice->secondContext.z.context, - generateAlgaChoice->algaChoice._algorithmInfo, surrenderContext)) != 0) - return (ConvertAlgaeError (status)); - - return (0); -} - -/* Call the generate procedure repeatedly with a new random block - until it succeeds. - */ -static int GenerateResult - (generateAlgaChoice, result, randomAlgorithm, surrenderContext) -GenerateAlgaChoice *generateAlgaChoice; -POINTER *result; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - /* Fill in the random block and try generating as long as the - the generate operation returns BE_NEED_RANDOM. - */ - while (1) { - if ((status = B_AlgorithmGenerateRandomBytes - (randomAlgorithm, - (unsigned char *)generateAlgaChoice->randomBlock.z.context, - generateAlgaChoice->_randomBlockLen, surrenderContext)) != 0) - return (status); - - if ((status = (*((A_GENERATE_ALGA *) - generateAlgaChoice->algaChoice._alga)->Generate) - (generateAlgaChoice->algaChoice.context.z.context, result, - (unsigned char *)generateAlgaChoice->randomBlock.z.context, - surrenderContext)) != 0) { - if (status != AE_NEED_RANDOM) - return (ConvertAlgaeError (status)); - - /* Else continue and try again */ - } - else - /* Success, so return */ - return (0); - } -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahchgen.h b/usr/src/lib/libresolv2/common/dnssafe/ahchgen.h deleted file mode 100644 index ec38f97714..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahchgen.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AHCHGEN_H_ -#define _AHCHGEN_H_ 1 - -#include "ahgen.h" -#include "algchoic.h" - -/* Make a new class derived from an AlgaChoice which records the - result algorithm info type and needed randomBlockLen. - */ -typedef struct GenerateAlgaChoice { - AlgaChoice algaChoice; /* base class */ - - struct B_KeyInfoType *_resultInfoType; - ResizeContext secondContext; /* used for scratch */ - ResizeContext randomBlock; - unsigned int _randomBlockLen; -} GenerateAlgaChoice; - -typedef struct AHChooseGenerate { - AHGenerate generate; /* base class */ - - GenerateAlgaChoice generateAlgaChoice; -} AHChooseGenerate; - -AHChooseGenerate *AHChooseGenerateConstructor2 PROTO_LIST - ((AHChooseGenerate *, struct B_AlgorithmInfoType *, POINTER)); -void AHChooseGenerateDestructor PROTO_LIST ((THIS_GENERATE *)); - -int AHChooseGenerateInit PROTO_LIST - ((THIS_GENERATE *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int AHChooseGenerateKeypair PROTO_LIST - ((THIS_GENERATE *, B_Key *, B_Key *, B_Algorithm *, A_SURRENDER_CTX *)); -int AHChooseGenerateParameters PROTO_LIST - ((THIS_GENERATE *, B_Algorithm *, B_Algorithm *, A_SURRENDER_CTX *)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahchrand.c b/usr/src/lib/libresolv2/common/dnssafe/ahchrand.c deleted file mode 100644 index caecaf5dd2..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahchrand.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -/* Define this so that the type of the 'this' pointer in the - virtual functions will be correct for this derived class. - */ -struct AHChooseRandom; -#define THIS_RANDOM struct AHChooseRandom - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "balgmeth.h" -#include "ahchrand.h" -#include "amrandom.h" -#include "port_after.h" - -static int InitRandomAlga PROTO_LIST - ((AlgaChoice *, POINTER, B_ALGORITHM_METHOD *, A_SURRENDER_CTX *)); - -static AHRandomVTable V_TABLE = { - AHChooseRandomDestructor, AHChooseRandomInit, AHChooseRandomUpdate, - AHChooseRandomGenerateBytes -}; - -AHChooseRandom *AHChooseRandomConstructor2 (handler, infoType, info) -AHChooseRandom *handler; -struct B_AlgorithmInfoType *infoType; -POINTER info; -{ - if (handler == (AHChooseRandom *)NULL_PTR) { - /* This constructor is being used to do a new */ - if ((handler = (AHChooseRandom *)T_malloc (sizeof (*handler))) - == (AHChooseRandom *)NULL_PTR) - return (handler); - } - - /* Construct base class */ - AHRandomConstructor (&handler->random); - - ALGA_CHOICE_Constructor (&handler->algaChoice, InitRandomAlga); - handler->algaChoice._algorithmInfoType = infoType; - handler->algaChoice._algorithmInfo = info; - - handler->random.vTable = &V_TABLE; - - return (handler); -} - -void AHChooseRandomDestructor (handler) -AHChooseRandom *handler; -{ - ALGA_CHOICE_Destructor (&handler->algaChoice); - /* There is no desructor to call for the base class. */ -} - -int AHChooseRandomInit (handler, chooser, surrenderContext) -AHChooseRandom *handler; -B_ALGORITHM_CHOOSER chooser; -A_SURRENDER_CTX *surrenderContext; -{ - return (AlgaChoiceChoose - (&handler->algaChoice, 0, (B_Key *)NULL_PTR, chooser, - surrenderContext)); -} - -int AHChooseRandomUpdate (handler, input, inputLen, surrenderContext) -AHChooseRandom *handler; -unsigned char *input; -unsigned int inputLen; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = (*((A_RANDOM_ALGA *)handler->algaChoice._alga)->Update) - (handler->algaChoice.context.z.context, input, inputLen, - surrenderContext)) != 0) - return (ConvertAlgaeError (status)); - return (0); -} - -int AHChooseRandomGenerateBytes (handler, output, outputLen, surrenderContext) -AHChooseRandom *handler; -unsigned char *output; -unsigned int outputLen; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = (*((A_RANDOM_ALGA *)handler->algaChoice._alga)->Generate) - (handler->algaChoice.context.z.context, output, outputLen, - surrenderContext)) != 0) - return (ConvertAlgaeError (status)); - return (0); -} - -static int InitRandomAlga - (algaChoice, keyInfo, algorithmMethod, surrenderContext) -AlgaChoice *algaChoice; -POINTER keyInfo; -B_ALGORITHM_METHOD *algorithmMethod; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - unsigned int contextSize; - -UNUSED_ARG (keyInfo) - if ((status = (*((A_RANDOM_ALGA *)algorithmMethod->alga)->Query) - (&contextSize, algaChoice->_algorithmInfo)) != 0) - return (ConvertAlgaeError (status)); - - if ((status = ResizeContextMakeNewContext - (&algaChoice->context, contextSize)) != 0) - return (status); - - if ((status = (*((A_RANDOM_ALGA *)algorithmMethod->alga)->Init) - (algaChoice->context.z.context, algaChoice->_algorithmInfo, - surrenderContext)) != 0) - return (ConvertAlgaeError (status)); - - return (0); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahchrand.h b/usr/src/lib/libresolv2/common/dnssafe/ahchrand.h deleted file mode 100644 index 349a97fe25..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahchrand.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AHCHRAND_H_ -#define _AHCHRAND_H_ 1 - -#include "ahrandom.h" -#include "algchoic.h" - -typedef struct AHChooseRandom { - AHRandom random; /* base class */ - AlgaChoice algaChoice; -} AHChooseRandom; - -AHChooseRandom *AHChooseRandomConstructor2 PROTO_LIST - ((AHChooseRandom *, struct B_AlgorithmInfoType *, POINTER)); -void AHChooseRandomDestructor PROTO_LIST ((THIS_RANDOM *)); - -int AHChooseRandomInit PROTO_LIST - ((THIS_RANDOM *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int AHChooseRandomUpdate PROTO_LIST - ((THIS_RANDOM *, unsigned char *, unsigned int, A_SURRENDER_CTX *)); -int AHChooseRandomGenerateBytes PROTO_LIST - ((THIS_RANDOM *, unsigned char *, unsigned int, A_SURRENDER_CTX *)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahdigest.c b/usr/src/lib/libresolv2/common/dnssafe/ahdigest.c deleted file mode 100644 index a0fa71355f..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahdigest.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ahdigest.h" -#include "port_after.h" - -static void TypedAHDigestDestructor PROTO_LIST ((B_TypeCheck *)); - -void AHDigestConstructor (handler) -AHDigest *handler; -{ - /* Construct base class, setting type tag. */ - B_TYPE_CHECK_Constructor - (&handler->typeCheck, TypedAHDigestDestructor); - - /* Don't set vTable since this is a pure virtual base class. */ -} - -int B_AlgorithmDigestInit - (algorithm, key, algorithmChooser, surrenderContext) -B_Algorithm *algorithm; -B_Key *key; -B_ALGORITHM_CHOOSER algorithmChooser; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = B_AlgorithmCheckType - (algorithm, TypedAHDigestDestructor)) != 0) - return (status); - - if ((status = - (*((AHDigest *)algorithm->z.handler)->vTable->DigestInit) - ((AHDigest *)algorithm->z.handler, key, algorithmChooser, - surrenderContext)) != 0) - return (status); - - algorithm->z.initFlag = 1; - return (0); -} - -int B_AlgorithmDigestUpdate (algorithm, partIn, partInLen, surrenderContext) -B_Algorithm *algorithm; -const unsigned char *partIn; -unsigned int partInLen; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = B_AlgorithmCheckTypeAndInitFlag - (algorithm, TypedAHDigestDestructor)) != 0) - return (status); - - return ((*((AHDigest *)algorithm->z.handler)->vTable->DigestUpdate) - ((AHDigest *)algorithm->z.handler, partIn, partInLen, - surrenderContext)); -} - -int B_AlgorithmDigestFinal - (algorithm, partOut, partOutLen, maxPartOutLen, surrenderContext) -B_Algorithm *algorithm; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = B_AlgorithmCheckTypeAndInitFlag - (algorithm, TypedAHDigestDestructor)) != 0) - return (status); - - return ((*((AHDigest *)algorithm->z.handler)->vTable->DigestFinal) - ((AHDigest *)algorithm->z.handler, partOut, partOutLen, - maxPartOutLen, surrenderContext)); -} - -static void TypedAHDigestDestructor (typeCheck) -B_TypeCheck *typeCheck; -{ - (*((AHDigest *)typeCheck)->vTable->Destructor) ((AHDigest *)typeCheck); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahdigest.h b/usr/src/lib/libresolv2/common/dnssafe/ahdigest.h deleted file mode 100644 index 2abe53d76b..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahdigest.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AHDIGEST_H_ -#define _AHDIGEST_H_ 1 - -#include "btypechk.h" - -/* Use the THIS_DIGEST macro to define the type of object in the - virtual function prototype. It defaults to the most base class, but - derived modules may define the macro to a more derived class before - including this header file. - */ -#ifndef THIS_DIGEST -#define THIS_DIGEST struct AHDigest -#endif - -struct AHDigest; - -typedef struct { - void (*Destructor) PROTO_LIST ((THIS_DIGEST *)); - int (*DigestInit) PROTO_LIST - ((THIS_DIGEST *, B_Key *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); - int (*DigestUpdate) PROTO_LIST - ((THIS_DIGEST *, const unsigned char *, unsigned int, A_SURRENDER_CTX *)); - int (*DigestFinal) PROTO_LIST - ((THIS_DIGEST *, unsigned char *, unsigned int *, unsigned int, - A_SURRENDER_CTX *)); -} AHDigestVTable; - -typedef struct AHDigest { - B_TypeCheck typeCheck; /* inherited */ - AHDigestVTable *vTable; /* pure virtual */ -} AHDigest; - -/* The constructor does not set the vTable since this is a pure base class. - */ -void AHDigestConstructor PROTO_LIST ((AHDigest *)); -/* No destructor because it is pure virtual. Also, do not call destructor - for B_TypeCheck, since this will just re-invoke this virtual - destructor. */ - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahencryp.c b/usr/src/lib/libresolv2/common/dnssafe/ahencryp.c deleted file mode 100644 index a8874dccd6..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahencryp.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ahencryp.h" -#include "port_after.h" - -static void TypedAHEncryptDecryptDestructor PROTO_LIST ((B_TypeCheck *)); - -void AHEncryptDecryptConstructor (handler) -AHEncryptDecrypt *handler; -{ - /* Construct base class, setting type tag. */ - B_TYPE_CHECK_Constructor - (&handler->typeCheck, TypedAHEncryptDecryptDestructor); - - /* Don't set vTable since this is a pure virtual base class. */ -} - -int B_AlgorithmEncryptInit - (algorithm, key, algorithmChooser, surrenderContext) -B_Algorithm *algorithm; -B_Key *key; -B_ALGORITHM_CHOOSER algorithmChooser; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = B_AlgorithmCheckType - (algorithm, TypedAHEncryptDecryptDestructor)) != 0) - return (status); - - if ((status = - (*((AHEncryptDecrypt *)algorithm->z.handler)->vTable->EncryptInit) - ((AHEncryptDecrypt *)algorithm->z.handler, key, algorithmChooser, - surrenderContext)) != 0) - return (status); - - algorithm->z.initFlag = 1; - return (0); -} - -int B_AlgorithmDecryptInit - (algorithm, key, algorithmChooser, surrenderContext) -B_Algorithm *algorithm; -B_Key *key; -B_ALGORITHM_CHOOSER algorithmChooser; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = B_AlgorithmCheckType - (algorithm, TypedAHEncryptDecryptDestructor)) != 0) - return (status); - - if ((status = - (*((AHEncryptDecrypt *)algorithm->z.handler)->vTable->DecryptInit) - ((AHEncryptDecrypt *)algorithm->z.handler, key, algorithmChooser, - surrenderContext)) != 0) - return (status); - - algorithm->z.initFlag = 1; - return (0); -} - -int B_AlgorithmEncryptUpdate - (algorithm, partOut, partOutLen, maxPartOutLen, partIn, partInLen, - randomAlgorithm, surrenderContext) -B_Algorithm *algorithm; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -unsigned char *partIn; -unsigned int partInLen; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = B_AlgorithmCheckTypeAndInitFlag - (algorithm, TypedAHEncryptDecryptDestructor)) != 0) - return (status); - - return ((*((AHEncryptDecrypt *)algorithm->z.handler)->vTable->EncryptUpdate) - ((AHEncryptDecrypt *)algorithm->z.handler, partOut, partOutLen, - maxPartOutLen, partIn, partInLen, randomAlgorithm, - surrenderContext)); -} - -int B_AlgorithmDecryptUpdate - (algorithm, partOut, partOutLen, maxPartOutLen, partIn, partInLen, - randomAlgorithm, surrenderContext) -B_Algorithm *algorithm; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -const unsigned char *partIn; -unsigned int partInLen; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = B_AlgorithmCheckTypeAndInitFlag - (algorithm, TypedAHEncryptDecryptDestructor)) != 0) - return (status); - - return ((*((AHEncryptDecrypt *)algorithm->z.handler)->vTable->DecryptUpdate) - ((AHEncryptDecrypt *)algorithm->z.handler, partOut, partOutLen, - maxPartOutLen, partIn, partInLen, randomAlgorithm, - surrenderContext)); -} - -int B_AlgorithmEncryptFinal - (algorithm, partOut, partOutLen, maxPartOutLen, randomAlgorithm, - surrenderContext) -B_Algorithm *algorithm; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = B_AlgorithmCheckTypeAndInitFlag - (algorithm, TypedAHEncryptDecryptDestructor)) != 0) - return (status); - - return ((*((AHEncryptDecrypt *)algorithm->z.handler)->vTable->EncryptFinal) - ((AHEncryptDecrypt *)algorithm->z.handler, partOut, partOutLen, - maxPartOutLen, randomAlgorithm, surrenderContext)); -} - -int B_AlgorithmDecryptFinal - (algorithm, partOut, partOutLen, maxPartOutLen, randomAlgorithm, - surrenderContext) -B_Algorithm *algorithm; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = B_AlgorithmCheckTypeAndInitFlag - (algorithm, TypedAHEncryptDecryptDestructor)) != 0) - return (status); - - return ((*((AHEncryptDecrypt *)algorithm->z.handler)->vTable->DecryptFinal) - ((AHEncryptDecrypt *)algorithm->z.handler, partOut, partOutLen, - maxPartOutLen, randomAlgorithm, surrenderContext)); -} - -static void TypedAHEncryptDecryptDestructor (typeCheck) -B_TypeCheck *typeCheck; -{ - (*((AHEncryptDecrypt *)typeCheck)->vTable->Destructor) - ((AHEncryptDecrypt *)typeCheck); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahencryp.h b/usr/src/lib/libresolv2/common/dnssafe/ahencryp.h deleted file mode 100644 index d57b7ca9b7..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahencryp.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AHENCRYP_H_ -#define _AHENCRYP_H_ 1 - -#include "btypechk.h" - -/* In C++: -class AHEncryptDecrypt : public B_TypeCheck { - AHEncryptDecrypt (); - virtual ~AHEncryptDecrypt () = 0; - - virtual int getBlockLen (unsigned int *) = 0; - virtual int encryptInit - (B_Key *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *) = 0; - virtual int decryptInit - (B_Key *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *) = 0; - virtual int encryptUpdate - (unsigned char *, unsigned int *, unsigned int, unsigned char *, - unsigned int, B_Algorithm *, A_SURRENDER_CTX *) = 0; - virtual int decryptUpdate - (unsigned char *, unsigned int *, unsigned int, unsigned char *, - unsigned int, B_Algorithm *, A_SURRENDER_CTX *) = 0; - virtual int encryptFinal - (unsigned char *, unsigned int *, unsigned int, B_Algorithm *, - A_SURRENDER_CTX *) = 0; - virtual int decryptFinal - (unsigned char *, unsigned int *, unsigned int, B_Algorithm *, - A_SURRENDER_CTX *) = 0; -}; - */ - -/* Use the THIS_ENCRYPT_DECRYPT macro to define the type of object in the - virtual function prototype. It defaults to the most base class, but - derived modules may define the macro to a more derived class before - including this header file. - */ -#ifndef THIS_ENCRYPT_DECRYPT -#define THIS_ENCRYPT_DECRYPT struct AHEncryptDecrypt -#endif - -struct AHEncryptDecrypt; - -typedef struct { - void (*Destructor) PROTO_LIST ((THIS_ENCRYPT_DECRYPT *)); - int (*GetBlockLen) PROTO_LIST ((THIS_ENCRYPT_DECRYPT *, unsigned int *)); - int (*EncryptInit) PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, B_Key *, B_ALGORITHM_CHOOSER, - A_SURRENDER_CTX *)); - int (*DecryptInit) PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, B_Key *, B_ALGORITHM_CHOOSER, - A_SURRENDER_CTX *)); - int (*EncryptUpdate) PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned char *, unsigned int *, unsigned int, - const unsigned char *, unsigned int, B_Algorithm *, A_SURRENDER_CTX *)); - int (*DecryptUpdate) PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned char *, unsigned int *, unsigned int, - const unsigned char *, unsigned int, B_Algorithm *, A_SURRENDER_CTX *)); - int (*EncryptFinal) PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned char *, unsigned int *, unsigned int, - B_Algorithm *, A_SURRENDER_CTX *)); - int (*DecryptFinal) PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned char *, unsigned int *, unsigned int, - B_Algorithm *, A_SURRENDER_CTX *)); -} AHEncryptDecryptVTable; - -typedef struct AHEncryptDecrypt { - B_TypeCheck typeCheck; /* inherited */ - AHEncryptDecryptVTable *vTable; /* pure virtual */ -} AHEncryptDecrypt; - -/* The constructor does not set the vTable since this is a pure base class. - */ -void AHEncryptDecryptConstructor PROTO_LIST ((AHEncryptDecrypt *)); -/* No destructor because it is pure virtual. Also, do not call destructor - for B_TypeCheck, since this will just re-invoke this virtual - destructor. */ - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahgen.c b/usr/src/lib/libresolv2/common/dnssafe/ahgen.c deleted file mode 100644 index a65763429b..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahgen.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ahgen.h" -#include "port_after.h" - -static void TypedAHGenerateDestructor PROTO_LIST ((B_TypeCheck *)); - -void AHGenerateConstructor (handler) -AHGenerate *handler; -{ - /* Construct base class, setting type tag. */ - B_TYPE_CHECK_Constructor - (&handler->typeCheck, TypedAHGenerateDestructor); - - /* Don't set vTable since this is a pure virtual base class. */ -} - -int B_AlgorithmGenerateInit (algorithm, algorithmChooser, surrenderContext) -B_Algorithm *algorithm; -B_ALGORITHM_CHOOSER algorithmChooser; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = B_AlgorithmCheckType - (algorithm, TypedAHGenerateDestructor)) != 0) - return (status); - - if ((status = - (*((AHGenerate *)algorithm->z.handler)->vTable->GenerateInit) - ((AHGenerate *)algorithm->z.handler, algorithmChooser, - surrenderContext)) != 0) - return (status); - - algorithm->z.initFlag = 1; - return (0); -} - -int B_AlgorithmGenerateKeypair - (algorithm, publicKey, privateKey, randomAlgorithm, surrenderContext) -B_Algorithm *algorithm; -B_Key *publicKey; -B_Key *privateKey; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = B_AlgorithmCheckTypeAndInitFlag - (algorithm, TypedAHGenerateDestructor)) != 0) - return (status); - - return ((*((AHGenerate *)algorithm->z.handler)->vTable->GenerateKeypair) - ((AHGenerate *)algorithm->z.handler, publicKey, privateKey, - randomAlgorithm, surrenderContext)); -} - -int B_AlgorithmGenerateParameters - (algorithm, resultAlgorithm, randomAlgorithm, surrenderContext) -B_Algorithm *algorithm; -B_Algorithm *resultAlgorithm; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = B_AlgorithmCheckTypeAndInitFlag - (algorithm, TypedAHGenerateDestructor)) != 0) - return (status); - - return ((*((AHGenerate *)algorithm->z.handler)->vTable->GenerateParameters) - ((AHGenerate *)algorithm->z.handler, resultAlgorithm, - randomAlgorithm, surrenderContext)); -} - -static void TypedAHGenerateDestructor (typeCheck) -B_TypeCheck *typeCheck; -{ - (*((AHGenerate *)typeCheck)->vTable->Destructor) ((AHGenerate *)typeCheck); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahgen.h b/usr/src/lib/libresolv2/common/dnssafe/ahgen.h deleted file mode 100644 index afe0ef3bf9..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahgen.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AHGEN_H_ -#define _AHGEN_H_ 1 - -#include "btypechk.h" - -/* Use the THIS_GENERATE macro to define the type of object in the - virtual function prototype. It defaults to the most base class, but - derived modules may define the macro to a more derived class before - including this header file. - */ -#ifndef THIS_GENERATE -#define THIS_GENERATE struct AHGenerate -#endif - -struct AHGenerate; - -typedef struct { - void (*Destructor) PROTO_LIST ((THIS_GENERATE *)); - int (*GenerateInit) PROTO_LIST - ((THIS_GENERATE *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); - int (*GenerateKeypair) PROTO_LIST - ((THIS_GENERATE *, B_Key *, B_Key *, B_Algorithm *, A_SURRENDER_CTX *)); - int (*GenerateParameters) PROTO_LIST - ((THIS_GENERATE *, B_Algorithm *, B_Algorithm *, A_SURRENDER_CTX *)); -} AHGenerateVTable; - -typedef struct AHGenerate { - B_TypeCheck typeCheck; /* inherited */ - AHGenerateVTable *vTable; /* pure virtual */ -} AHGenerate; - -/* The constructor does not set the vTable since this is a pure base class. - */ -void AHGenerateConstructor PROTO_LIST ((AHGenerate *)); -/* No destructor because it is pure virtual. Also, do not call destructor - for B_TypeCheck, since this will just re-invoke this virtual - destructor. */ - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahrandom.c b/usr/src/lib/libresolv2/common/dnssafe/ahrandom.c deleted file mode 100644 index 9a31e9b817..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahrandom.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ahrandom.h" -#include "port_after.h" - -static void TypedAHRandomDestructor PROTO_LIST ((B_TypeCheck *)); - -void AHRandomConstructor (handler) -AHRandom *handler; -{ - /* Construct base class, setting type tag. */ - B_TYPE_CHECK_Constructor - (&handler->typeCheck, TypedAHRandomDestructor); - - /* Don't set vTable since this is a pure virtual base class. */ -} - -int B_AlgorithmRandomInit (algorithm, algorithmChooser, surrenderContext) -B_Algorithm *algorithm; -B_ALGORITHM_CHOOSER algorithmChooser; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = B_AlgorithmCheckType (algorithm, TypedAHRandomDestructor)) - != 0) - return (status); - - if ((status = - (*((AHRandom *)algorithm->z.handler)->vTable->RandomInit) - ((AHRandom *)algorithm->z.handler, algorithmChooser, surrenderContext)) - != 0) - return (status); - - algorithm->z.initFlag = 1; - return (0); -} - -int B_AlgorithmRandomUpdate (algorithm, input, inputLen, surrenderContext) -B_Algorithm *algorithm; -unsigned char *input; -unsigned int inputLen; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = B_AlgorithmCheckTypeAndInitFlag - (algorithm, TypedAHRandomDestructor)) != 0) - return (status == BE_ALGORITHM_NOT_INITIALIZED ? - BE_RANDOM_NOT_INITIALIZED : status); - - return ((*((AHRandom *)algorithm->z.handler)->vTable->RandomUpdate) - ((AHRandom *)algorithm->z.handler, input, inputLen, - surrenderContext)); -} - -int B_AlgorithmGenerateRandomBytes - (algorithm, output, outputLen, surrenderContext) -B_Algorithm *algorithm; -unsigned char *output; -unsigned int outputLen; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - /* As a special case, check here for a null this pointer when the object - is actually being used since many routines take a "dummy" null - random algorithm. - */ - if (algorithm == (B_Algorithm *)NULL_PTR) - return (BE_RANDOM_OBJ); - - if ((status = B_AlgorithmCheckTypeAndInitFlag - (algorithm, TypedAHRandomDestructor)) != 0) - return (status == BE_ALGORITHM_NOT_INITIALIZED ? - BE_RANDOM_NOT_INITIALIZED : status); - - return ((*((AHRandom *)algorithm->z.handler)->vTable->GenerateBytes) - ((AHRandom *)algorithm->z.handler, output, outputLen, - surrenderContext)); -} - -static void TypedAHRandomDestructor (typeCheck) -B_TypeCheck *typeCheck; -{ - (*((AHRandom *)typeCheck)->vTable->Destructor) ((AHRandom *)typeCheck); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahrandom.h b/usr/src/lib/libresolv2/common/dnssafe/ahrandom.h deleted file mode 100644 index fd566879e6..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahrandom.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AHRANDOM_H_ -#define _AHRANDOM_H_ 1 - -#include "btypechk.h" - -/* Use the THIS_RANDOM macro to define the type of object in the - virtual function prototype. It defaults to the most base class, but - derived modules may define the macro to a more derived class before - including this header file. - */ -#ifndef THIS_RANDOM -#define THIS_RANDOM struct AHRandom -#endif - -struct AHRandom; - -typedef struct { - void (*Destructor) PROTO_LIST ((THIS_RANDOM *)); - int (*RandomInit) PROTO_LIST - ((THIS_RANDOM *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); - int (*RandomUpdate) PROTO_LIST - ((THIS_RANDOM *, unsigned char *, unsigned int, A_SURRENDER_CTX *)); - int (*GenerateBytes) PROTO_LIST - ((THIS_RANDOM *, unsigned char *, unsigned int, A_SURRENDER_CTX *)); -} AHRandomVTable; - -typedef struct AHRandom { - B_TypeCheck typeCheck; /* inherited */ - AHRandomVTable *vTable; /* pure virtual */ -} AHRandom; - -/* The constructor does not set the vTable since this is a pure base class. - */ -void AHRandomConstructor PROTO_LIST ((AHRandom *)); -/* No destructor because it is pure virtual. Also, do not call destructor - for B_TypeCheck, since this will just re-invoke this virtual - destructor. */ - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahrsaenc.c b/usr/src/lib/libresolv2/common/dnssafe/ahrsaenc.c deleted file mode 100644 index 3a8894d2d4..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahrsaenc.c +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -/* Define this so that the type of the 'this' pointer in the - virtual functions will be correct for this derived class. - */ -struct AH_RSAEncryption; -#define THIS_ENCRYPT_DECRYPT struct AH_RSAEncryption - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ahrsaenc.h" -#include "port_after.h" - -static int AH_RSAEncryptionInitHelper PROTO_LIST ((AH_RSAEncryption *, int)); - -static AHEncryptDecryptVTable V_TABLE = { - AH_RSAEncryptionDestructor, AH_RSAEncryptionGetBlockLen, - AH_RSAEncryptionEncryptInit, AH_RSAEncryptionDecryptInit, - AH_RSAEncryptionUpdate, - AH_RSAEncryptionUpdate, - AH_RSAEncryptionEncryptFinal, AH_RSAEncryptionDecryptFinal -}; - -void AH_RSAEncryptionConstructor1 (handler, infoType) -AH_RSAEncryption *handler; -struct B_AlgorithmInfoType *infoType; -{ - /* Construct base class with the infoType. Assume info is NULL_PTR. */ - AHChooseEncryptConstructor2 - (&handler->chooseEncryptDecrypt, infoType, NULL_PTR); - - T_memset ((POINTER)&handler->z, 0, sizeof (handler->z)); - /* Set the AHEncryptDecrypt vTable, but don't set the RSAEncryption vTable - since it is pure virtual. */ - handler->chooseEncryptDecrypt.encryptDecrypt.vTable = &V_TABLE; -} - -void AH_RSAEncryptionDestructor (handler) -AH_RSAEncryption *handler; -{ - T_memset ((POINTER)handler->z.block, 0, handler->z.blockLen); - T_free ((POINTER)handler->z.block); - - /* Call base class destructor */ - AHChooseEncryptDestructor (handler); -} - -int AH_RSAEncryptionGetBlockLen (handler, blockLen) -AH_RSAEncryption *handler; -unsigned int *blockLen; -{ -UNUSED_ARG (handler) -UNUSED_ARG (blockLen) - return (BE_NOT_SUPPORTED); -} - -int AH_RSAEncryptionEncryptInit (handler, key, chooser, surrenderContext) -AH_RSAEncryption *handler; -B_Key *key; -B_ALGORITHM_CHOOSER chooser; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = AHChooseEncryptEncryptInit - (handler, key, chooser, surrenderContext)) != 0) - return (status); - - return (AH_RSAEncryptionInitHelper (handler, 1)); -} - -int AH_RSAEncryptionDecryptInit (handler, key, chooser, surrenderContext) -AH_RSAEncryption *handler; -B_Key *key; -B_ALGORITHM_CHOOSER chooser; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = AHChooseEncryptDecryptInit - (handler, key, chooser, surrenderContext)) != 0) - return (status); - - return (AH_RSAEncryptionInitHelper (handler, 0)); -} - -/* Accumulate into the z.block. - */ -int AH_RSAEncryptionUpdate - (handler, partOut, partOutLen, maxPartOutLen, partIn, partInLen, - randomAlgorithm, surrenderContext) -AH_RSAEncryption *handler; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -const unsigned char *partIn; -unsigned int partInLen; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ -UNUSED_ARG (partOut) -UNUSED_ARG (maxPartOutLen) -UNUSED_ARG (randomAlgorithm) -UNUSED_ARG (surrenderContext) - *partOutLen = 0; - - if (handler->_inputLen + partInLen > handler->_maxInputLen) - return (BE_INPUT_LEN); - T_memcpy - ((POINTER)(handler->z.block + handler->_inputLen), (CPOINTER)partIn, - partInLen); - handler->_inputLen += partInLen; - return (0); -} - -int AH_RSAEncryptionEncryptFinal - (handler, partOut, partOutLen, maxPartOutLen, randomAlgorithm, - surrenderContext) -AH_RSAEncryption *handler; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - unsigned int dummyPartOutLen; - - /* Encode methodContext in place. */ - if ((status = (*handler->vTable->EncodeBlock) - (handler, randomAlgorithm, surrenderContext)) != 0) - return (status); - - /* This should not return BE_INPUT_DATA since it is well-formatted. */ - if ((status = AHChooseEncryptEncryptUpdate - (handler, partOut, partOutLen, maxPartOutLen, handler->z.block, - handler->z.blockLen, (B_Algorithm *)NULL_PTR, surrenderContext)) != 0) - return (status); - - /* Expect final to return zero bytes. */ - if ((status = AHChooseEncryptEncryptFinal - (handler, (unsigned char *)NULL_PTR, &dummyPartOutLen, 0, - (B_Algorithm *)NULL_PTR, surrenderContext)) != 0) - return (status); - - /* Restart the handle for new input. */ - handler->_inputLen = 0; - return (0); -} - -int AH_RSAEncryptionDecryptFinal - (handler, partOut, partOutLen, maxPartOutLen, randomAlgorithm, - surrenderContext) -AH_RSAEncryption *handler; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - ITEM output; - int status; - unsigned int decryptedLen, dummyPartOutLen; - -UNUSED_ARG (randomAlgorithm) - /* Decrypt block in place. The block lenghts are already within limits. - */ - if ((status = AHChooseEncryptDecryptUpdate - (handler, handler->z.block, &decryptedLen, handler->z.blockLen, - handler->z.block, handler->_inputLen, (B_Algorithm *)NULL_PTR, - surrenderContext)) != 0) - return (status); - /* Expect final to return zero bytes. */ - if ((status = AHChooseEncryptDecryptFinal - (handler, (unsigned char *)NULL_PTR, &dummyPartOutLen, 0, - (B_Algorithm *)NULL_PTR, surrenderContext)) != 0) - return (status); - - /* Restart the handle for new input. */ - handler->_inputLen = 0; - - /* Now decode the block and copy the result to the partOut. - */ - if ((status = (*handler->vTable->DecodeBlock) - (handler, &output, decryptedLen)) != 0) - return (status); - - if (output.len > handler->z.blockLen - 11) - /* This implies that the block was encrypted with less than - 8 bytes of padding */ - return (BE_INPUT_DATA); - - if ((*partOutLen = output.len) > maxPartOutLen) - return (BE_OUTPUT_LEN); - T_memcpy ((POINTER)partOut, (POINTER)output.data, output.len); - - return (0); -} - -static int AH_RSAEncryptionInitHelper (handler, encryptFlag) -AH_RSAEncryption *handler; -int encryptFlag; -{ - int status; - unsigned int newBlockLen; - - if ((status = AHChooseEncryptGetBlockLen (handler, &newBlockLen)) != 0) - return (status); - - if (newBlockLen < 12) - /* PKCS Requires at least 12 bytes of modulus */ - return (BE_NOT_SUPPORTED); - - /* During encrypt, this will ensure that there are 8 bytes of padding. - During decrypt, the DecodeBlock procedure must check that the block - was encrypted with 8 bytes of padding. - */ - handler->_maxInputLen = encryptFlag ? (newBlockLen - 11) : newBlockLen; - - handler->_inputLen = 0; - - /* Zeroize old block and realloc to new size. - */ - T_memset ((POINTER)handler->z.block, 0, handler->z.blockLen); - if ((handler->z.block = (unsigned char *)T_realloc - ((POINTER)handler->z.block, newBlockLen)) - == (unsigned char *)NULL_PTR) { - handler->z.blockLen = 0; - return (BE_ALLOC); - } - - handler->z.blockLen = newBlockLen; - return (0); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahrsaenc.h b/usr/src/lib/libresolv2/common/dnssafe/ahrsaenc.h deleted file mode 100644 index 5fa5f9be08..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahrsaenc.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AHRSAENC_H_ -#define _AHRSAENC_H_ - -#include "ahchencr.h" - -struct AH_RSAEncryption; - -/* For EncodeBlock, the block to encode is left justified in the - z.block with length given by z._inputLen. EncodeBlock encodes the block - in place to fill it out to z.blockLen. - For DecodeBlock, return the contents in the given ITEM by decoding - the z.block value which has length given by decryptedLen. This - procedure must also ensure that the block was encrypted with 8 bytes - of padding. - */ -typedef struct { - int (*EncodeBlock) PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, B_Algorithm * /* randomAlgorithm */, - A_SURRENDER_CTX *)); - int (*DecodeBlock) PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, ITEM *, unsigned int /* decryptedLen */)); -} AH_RSAEncryptionVTable; - -typedef struct AH_RSAEncryption { - AHChooseEncryptDecrypt chooseEncryptDecrypt; /* base class */ - - struct { - unsigned char *block; - unsigned int blockLen; - } z; /* Zeroized by constructor */ - - unsigned int _inputLen; /* Length of data accumulated by Update */ - unsigned int _maxInputLen; /* used during update to check for overflow */ - AH_RSAEncryptionVTable *vTable; /* pure virtual */ -} AH_RSAEncryption; - -void AH_RSAEncryptionConstructor1 PROTO_LIST - ((AH_RSAEncryption *, struct B_AlgorithmInfoType *)); -void AH_RSAEncryptionDestructor PROTO_LIST ((AH_RSAEncryption *)); - -int AH_RSAEncryptionGetBlockLen PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned int *)); -int AH_RSAEncryptionEncryptInit PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, B_Key *, B_ALGORITHM_CHOOSER, - A_SURRENDER_CTX *)); -int AH_RSAEncryptionDecryptInit PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, B_Key *, B_ALGORITHM_CHOOSER, - A_SURRENDER_CTX *)); -int AH_RSAEncryptionUpdate PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned char *, unsigned int *, - unsigned int, const unsigned char *, unsigned int, B_Algorithm *, - A_SURRENDER_CTX *)); -int AH_RSAEncryptionEncryptFinal PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned char *, unsigned int *, - unsigned int, B_Algorithm *, A_SURRENDER_CTX *)); -int AH_RSAEncryptionDecryptFinal PROTO_LIST - ((THIS_ENCRYPT_DECRYPT *, unsigned char *, unsigned int *, - unsigned int, B_Algorithm *, A_SURRENDER_CTX *)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahrsaepr.c b/usr/src/lib/libresolv2/common/dnssafe/ahrsaepr.c deleted file mode 100644 index e5d6dad1c6..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahrsaepr.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -/* Define this so that the type of the 'this' pointer in the - virtual functions will be correct for this derived class. - */ -struct AH_RSAEncryption; -#define THIS_ENCRYPT_DECRYPT struct AH_RSAEncryption - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ahrsaepr.h" -#include "port_after.h" - -static int EncodeBlock1 PROTO_LIST - ((AH_RSAEncryptionPrivate *, B_Algorithm *, A_SURRENDER_CTX *)); -static int DecodeBlock2 PROTO_LIST - ((AH_RSAEncryptionPrivate *, ITEM *, unsigned int)); - -static AH_RSAEncryptionVTable ENCRYPTION_V_TABLE = - {EncodeBlock1, DecodeBlock2}; - -extern struct B_AlgorithmInfoType AIT_RSAPrivate; - -AH_RSAEncryptionPrivate *AH_RSAEncrypPrivateConstructor (handler) -AH_RSAEncryptionPrivate *handler; -{ - if (handler == (AH_RSAEncryptionPrivate *)NULL_PTR) { - /* This constructor is being used to do a new */ - if ((handler = (AH_RSAEncryptionPrivate *)T_malloc (sizeof (*handler))) - == (AH_RSAEncryptionPrivate *)NULL_PTR) - return (handler); - } - - /* Construct base class */ - AH_RSAEncryptionConstructor1 (handler, &AIT_RSAPrivate); - - handler->vTable = &ENCRYPTION_V_TABLE; - return (handler); -} - -/* block1 starts out with the input bytes of length inputLen left-justified. - Returns 0, BE_INPUT_LEN. - */ -static int EncodeBlock1 (handler, randomAlgorithm, surrenderContext) -AH_RSAEncryptionPrivate *handler; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - unsigned int padLen; - -UNUSED_ARG (randomAlgorithm) -UNUSED_ARG (surrenderContext) - if ((handler->_inputLen + 3) > handler->z.blockLen) - /* input is too large to make a block 1 */ - return (BE_INPUT_LEN); - - padLen = handler->z.blockLen - (handler->_inputLen + 3); - T_memmove - ((POINTER)(handler->z.block + padLen + 3), (POINTER)handler->z.block, - handler->_inputLen); - - handler->z.block[0] = 0; - handler->z.block[1] = 1; - T_memset ((POINTER)(handler->z.block + 2), 0xff, padLen); - handler->z.block[2 + padLen] = 0; - return (0); -} - -static int DecodeBlock2 (handler, output, block2Len) -AH_RSAEncryptionPrivate *handler; -ITEM *output; -unsigned int block2Len; -{ - unsigned int i; - - if ((handler->z.block[0] != 0) || (handler->z.block[1] != 2)) - return (BE_INPUT_DATA); - - /* Should be able to find the data after the first zero byte following - the random bytes. */ - for (i = 2; i < block2Len && handler->z.block[i] != 0; i++); - i++; - - if (i > block2Len) - /* The data is not zero terminated. */ - return (BE_INPUT_DATA); - - output->len = block2Len - i; - output->data = handler->z.block + i; - return (0); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahrsaepr.h b/usr/src/lib/libresolv2/common/dnssafe/ahrsaepr.h deleted file mode 100644 index 9820017939..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahrsaepr.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AHRSAEPR_H_ -#define _AHRSAEPR_H_ - -#include "ahrsaenc.h" - -/* structure is identical to base class, so just re-typedef. */ -typedef AH_RSAEncryption AH_RSAEncryptionPrivate; - -AH_RSAEncryptionPrivate *AH_RSAEncrypPrivateConstructor PROTO_LIST - ((AH_RSAEncryptionPrivate *)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahrsaepu.c b/usr/src/lib/libresolv2/common/dnssafe/ahrsaepu.c deleted file mode 100644 index 40a6c8db35..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahrsaepu.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -/* Define this so that the type of the 'this' pointer in the - virtual functions will be correct for this derived class. - */ -struct AH_RSAEncryption; -#define THIS_ENCRYPT_DECRYPT struct AH_RSAEncryption - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ahrsaepu.h" -#include "port_after.h" - -static int EncodeBlock2 PROTO_LIST - ((AH_RSAEncryptionPublic *, B_Algorithm *, A_SURRENDER_CTX *)); -static int DecodeBlock1 PROTO_LIST - ((AH_RSAEncryptionPublic *, ITEM *, unsigned int)); - -static AH_RSAEncryptionVTable ENCRYPTION_V_TABLE = - {EncodeBlock2, DecodeBlock1}; - -extern struct B_AlgorithmInfoType AIT_RSAPublic; - -AH_RSAEncryptionPublic *AH_RSAEncrypPublicConstructor (handler) -AH_RSAEncryptionPublic *handler; -{ - if (handler == (AH_RSAEncryptionPublic *)NULL_PTR) { - /* This constructor is being used to do a new */ - if ((handler = (AH_RSAEncryptionPublic *)T_malloc (sizeof (*handler))) - == (AH_RSAEncryptionPublic *)NULL_PTR) - return (handler); - } - - /* Construct base class */ - AH_RSAEncryptionConstructor1 (handler, &AIT_RSAPublic); - - handler->vTable = &ENCRYPTION_V_TABLE; - return (handler); -} - -/* block starts out with the input bytes of length inputLen left-justified. - */ -static int EncodeBlock2 (handler, randomAlgorithm, surrenderContext) -AH_RSAEncryptionPublic *handler; -B_Algorithm *randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - unsigned char randomByte; - unsigned int padLen, i; - - if ((handler->_inputLen + 3) > handler->z.blockLen) - /* input is too large to make a block 2 */ - return (BE_INPUT_LEN); - - padLen = handler->z.blockLen - (handler->_inputLen + 3); - T_memmove - ((POINTER)(handler->z.block + padLen + 3), (POINTER)handler->z.block, - handler->_inputLen); - - handler->z.block[0] = 0; - handler->z.block[1] = 2; - - /* Pad out with random bytes, making sure that none of the bytes is zero. - */ - for (i = 2; i < (padLen + 2); i++) { - do { - if ((status = B_AlgorithmGenerateRandomBytes - (randomAlgorithm, &randomByte, 1, surrenderContext)) != 0) - return (status); - } while (randomByte == 0); - - handler->z.block[i] = randomByte; - } - - handler->z.block[2 + padLen] = 0; - return (0); -} - -static int DecodeBlock1 (handler, output, block1Len) -AH_RSAEncryptionPublic *handler; -ITEM *output; -unsigned int block1Len; -{ - unsigned int i; - - /* Locate the digestInfo within the PKCS block 1. - */ - if (handler->z.block[0] != 0 || handler->z.block[1] != 1) - return (BE_INPUT_DATA); - - /* Should be able to find the data after the first zero byte following - the 0xff. */ - for (i = 2; i < block1Len && handler->z.block[i] == 0xff; i++); - i++; - - if (i > block1Len || handler->z.block[i - 1] != 0) - /* The data is not zero terminated, or a byte other than 0xff. */ - return (BE_INPUT_DATA); - - output->len = block1Len - i; - output->data = handler->z.block + i; - return (0); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/ahrsaepu.h b/usr/src/lib/libresolv2/common/dnssafe/ahrsaepu.h deleted file mode 100644 index 5f13415fdf..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ahrsaepu.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AHRSAEPU_H_ -#define _AHRSAEPU_H_ - -#include "ahrsaenc.h" - -/* structure is identical to base class, so just re-typedef. */ -typedef AH_RSAEncryption AH_RSAEncryptionPublic; - -AH_RSAEncryptionPublic *AH_RSAEncrypPublicConstructor PROTO_LIST - ((AH_RSAEncryptionPublic *)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/aichdig.c b/usr/src/lib/libresolv2/common/dnssafe/aichdig.c deleted file mode 100644 index 6aa7043b99..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/aichdig.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ahchdig.h" -#include "aichdig.h" -#include "port_after.h" - -B_TypeCheck *AITChooseDigestNullNewHandler PROTO_LIST - ((B_AlgorithmInfoType *, B_Algorithm *)); - -B_AlgorithmInfoTypeVTable AITChooseDigestNull_V_TABLE = - {AITNullAddInfo, AITChooseDigestNullNewHandler, - B_AlgorithmInfoTypeMakeError}; - -/* This always uses NULL_PTR for the info. - */ -B_TypeCheck *AITChooseDigestNullNewHandler (infoType, algorithm) -B_AlgorithmInfoType *infoType; -B_Algorithm *algorithm; -{ -UNUSED_ARG (algorithm) - - /* Pass in NULL_PTR so that constructor will allocate. - */ - return ((B_TypeCheck *)AHChooseDigestConstructor2 - ((AHChooseDigest *)NULL_PTR, infoType, NULL_PTR)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/aichdig.h b/usr/src/lib/libresolv2/common/dnssafe/aichdig.h deleted file mode 100644 index a7366e40b5..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/aichdig.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AICHDIG_H_ -#define _AICHDIG_H_ 1 - -#include "ainfotyp.h" -#include "ainull.h" - -extern B_AlgorithmInfoTypeVTable AITChooseDigestNull_V_TABLE; - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/aichenc8.c b/usr/src/lib/libresolv2/common/dnssafe/aichenc8.c deleted file mode 100644 index 42f869d8ee..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/aichenc8.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "aichenc8.h" -#include "port_after.h" - -B_AlgorithmInfoTypeVTable AITChooseEncrypt8_V_TABLE = - {AIT_8AddInfo, AITChooseEncryptNewHandler, B_AlgorithmInfoTypeMakeError}; - -int AIT_8AddInfo (infoType, algorithm, info) -B_AlgorithmInfoType *infoType; -B_Algorithm *algorithm; -POINTER info; -{ - POINTER newInfo; - int status; - - if ((status = B_MemoryPoolAllocAndCopy - (&algorithm->infoCache.memoryPool, &newInfo, info, 8)) != 0) - return (status); - - return (B_InfoCacheAddInfo - (&algorithm->infoCache, (POINTER)infoType, newInfo)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/aichenc8.h b/usr/src/lib/libresolv2/common/dnssafe/aichenc8.h deleted file mode 100644 index 59c6bf44d2..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/aichenc8.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AICHENC8_H_ -#define _AICHENC8_H_ 1 - -#include "aichencr.h" - -extern B_AlgorithmInfoTypeVTable AITChooseEncrypt8_V_TABLE; - -int AIT_8AddInfo PROTO_LIST - ((THIS_ALGORITHM_INFO_TYPE *, B_Algorithm *, POINTER)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/aichencn.c b/usr/src/lib/libresolv2/common/dnssafe/aichencn.c deleted file mode 100644 index 0dc2fb6650..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/aichencn.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "aichencn.h" -#include "port_after.h" - -B_AlgorithmInfoTypeVTable AITChooseEncryptNull_V_TABLE = - {AITNullAddInfo, AITChooseEncryptNewHandler, B_AlgorithmInfoTypeMakeError}; - diff --git a/usr/src/lib/libresolv2/common/dnssafe/aichencn.h b/usr/src/lib/libresolv2/common/dnssafe/aichencn.h deleted file mode 100644 index 99af4ff8c7..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/aichencn.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AICHENCN_H_ -#define _AICHENCN_H_ 1 - -#include "aichencr.h" -#include "ainull.h" - -extern B_AlgorithmInfoTypeVTable AITChooseEncryptNull_V_TABLE; - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/aichencr.c b/usr/src/lib/libresolv2/common/dnssafe/aichencr.c deleted file mode 100644 index 4e50087014..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/aichencr.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ahchencr.h" -#include "aichencr.h" -#include "port_after.h" - -B_TypeCheck *AITChooseEncryptNewHandler (infoType, algorithm) -B_AlgorithmInfoType *infoType; -B_Algorithm *algorithm; -{ - POINTER info; - - if (B_InfoCacheFindInfo (&algorithm->infoCache, &info, (POINTER)infoType) - != 0) - /* This really shouldn't happen since the info was just added. */ - return ((B_TypeCheck *)NULL_PTR); - - /* Pass in NULL_PTR so that constructor will allocate. */ - return ((B_TypeCheck *)AHChooseEncryptConstructor2 - ((AHChooseEncryptDecrypt *)NULL_PTR, infoType, info)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/aichencr.h b/usr/src/lib/libresolv2/common/dnssafe/aichencr.h deleted file mode 100644 index 7d67ab0e31..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/aichencr.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AICHENCR_H_ -#define _AICHENCR_H_ 1 - -#include "ainfotyp.h" - -struct B_TypeCheck *AITChooseEncryptNewHandler PROTO_LIST - ((B_AlgorithmInfoType *, B_Algorithm *)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/aichgen.c b/usr/src/lib/libresolv2/common/dnssafe/aichgen.c deleted file mode 100644 index f23a715026..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/aichgen.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ahchgen.h" -#include "aichgen.h" -#include "port_after.h" - -B_TypeCheck *AITChooseGenerateNewHandler (infoType, algorithm) -B_AlgorithmInfoType *infoType; -B_Algorithm *algorithm; -{ - POINTER info; - - if (B_InfoCacheFindInfo (&algorithm->infoCache, &info, (POINTER)infoType) - != 0) - /* This really shouldn't happen since the info was just added. */ - return ((B_TypeCheck *)NULL_PTR); - - /* Pass in NULL_PTR so that constructor will allocate. */ - return ((B_TypeCheck *)AHChooseGenerateConstructor2 - ((AHChooseGenerate *)NULL_PTR, infoType, info)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/aichgen.h b/usr/src/lib/libresolv2/common/dnssafe/aichgen.h deleted file mode 100644 index 0b5e7086fa..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/aichgen.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AICHGEN_H_ -#define _AICHGEN_H_ 1 - -#include "ainfotyp.h" - -struct B_TypeCheck *AITChooseGenerateNewHandler PROTO_LIST - ((B_AlgorithmInfoType *, B_Algorithm *)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/aichrand.c b/usr/src/lib/libresolv2/common/dnssafe/aichrand.c deleted file mode 100644 index 9c3ea6d9fd..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/aichrand.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ahchrand.h" -#include "aichrand.h" -#include "port_after.h" - -B_TypeCheck *AITChooseRandomNullNewHandler PROTO_LIST - ((B_AlgorithmInfoType *, B_Algorithm *)); - -B_AlgorithmInfoTypeVTable AITChooseRandomNull_V_TABLE = - {AITNullAddInfo, AITChooseRandomNullNewHandler, - B_AlgorithmInfoTypeMakeError}; - -/* This always uses NULL_PTR for the info. - */ -B_TypeCheck *AITChooseRandomNullNewHandler (infoType, algorithm) -B_AlgorithmInfoType *infoType; -B_Algorithm *algorithm; -{ -UNUSED_ARG (algorithm) - - /* Pass in NULL_PTR so that constructor will allocate. - */ - return ((B_TypeCheck *)AHChooseRandomConstructor2 - ((AHChooseRandom *)NULL_PTR, infoType, NULL_PTR)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/aichrand.h b/usr/src/lib/libresolv2/common/dnssafe/aichrand.h deleted file mode 100644 index f36d7bfe7c..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/aichrand.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AICHRAND_H_ -#define _AICHRAND_H_ 1 - -#include "ainfotyp.h" -#include "ainull.h" - -extern B_AlgorithmInfoTypeVTable AITChooseRandomNull_V_TABLE; - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/aimd5.c b/usr/src/lib/libresolv2/common/dnssafe/aimd5.c deleted file mode 100644 index 8ac7c4d3f7..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/aimd5.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "aichdig.h" -#include "port_after.h" - -B_AlgorithmInfoType AIT_MD5 = {&AITChooseDigestNull_V_TABLE}; - -int AI_MD5 (infoType) -POINTER *infoType; -{ - *infoType = (POINTER)&AIT_MD5; - - /* Return 0 to indicate a B_AlgorithmInfoType, not a B_KeyInfoType */ - return (0); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/aimd5ran.c b/usr/src/lib/libresolv2/common/dnssafe/aimd5ran.c deleted file mode 100644 index c4ee058b0f..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/aimd5ran.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "aichrand.h" -#include "port_after.h" - -B_AlgorithmInfoType AIT_MD5Random = {&AITChooseRandomNull_V_TABLE}; - -int AI_MD5Random (infoType) -POINTER *infoType; -{ - *infoType = (POINTER)&AIT_MD5Random; - - /* Return 0 to indicate a B_AlgorithmInfoType, not a B_KeyInfoType */ - return (0); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/ainfotyp.c b/usr/src/lib/libresolv2/common/dnssafe/ainfotyp.c deleted file mode 100644 index 2b4f21d67b..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ainfotyp.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ainfotyp.h" -#include "port_after.h" - -/* This is the default routine which algorithm info types point MakeInfo to - if not redefined by a derived class. - */ -int B_AlgorithmInfoTypeMakeError (infoType, info, algorithm) -B_AlgorithmInfoType *infoType; -POINTER *info; -B_Algorithm *algorithm; -{ -UNUSED_ARG (infoType) -UNUSED_ARG (info) -UNUSED_ARG (algorithm) - - /* Should already have been found in the cache. */ - return (BE_WRONG_ALGORITHM_INFO); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/ainfotyp.h b/usr/src/lib/libresolv2/common/dnssafe/ainfotyp.h deleted file mode 100644 index 5a6bc782f3..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ainfotyp.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _AINFOTYP_H_ -#define _AINFOTYP_H_ 1 - -/* Use the THIS_ALGORITHM_INFO_TYPE macro to define the type of object in the - virtual function prototype. It defaults to the most base class, but - derived modules may define the macro to a more derived class before - including this header file. - */ -#ifndef THIS_ALGORITHM_INFO_TYPE -#define THIS_ALGORITHM_INFO_TYPE struct B_AlgorithmInfoType -#endif - -struct B_AlgorithmInfoType; - -typedef struct { - int (*AddInfo) PROTO_LIST - ((THIS_ALGORITHM_INFO_TYPE *, B_Algorithm *, POINTER)); - struct B_TypeCheck * (*NewHandler) PROTO_LIST - ((THIS_ALGORITHM_INFO_TYPE *, B_Algorithm *)); - int (*MakeInfo) PROTO_LIST - ((THIS_ALGORITHM_INFO_TYPE *, POINTER *, B_Algorithm *)); -} B_AlgorithmInfoTypeVTable; - -typedef struct B_AlgorithmInfoType { - B_AlgorithmInfoTypeVTable *vTable; -} B_AlgorithmInfoType; - -int B_AlgorithmInfoTypeMakeError PROTO_LIST - ((THIS_ALGORITHM_INFO_TYPE *, POINTER *, B_Algorithm *)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/ainull.c b/usr/src/lib/libresolv2/common/dnssafe/ainull.c deleted file mode 100644 index 2879369730..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ainull.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ainfotyp.h" -#include "ainull.h" -#include "port_after.h" - -int AITNullAddInfo (infoType, algorithm, info) -B_AlgorithmInfoType *infoType; -B_Algorithm *algorithm; -POINTER info; -{ -UNUSED_ARG (info) - /* Cache null parameters. */ - return (B_InfoCacheAddInfo - (&algorithm->infoCache, (POINTER)infoType, NULL_PTR)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/ainull.h b/usr/src/lib/libresolv2/common/dnssafe/ainull.h deleted file mode 100644 index c15b892f29..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ainull.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -int AITNullAddInfo PROTO_LIST - ((THIS_ALGORITHM_INFO_TYPE *, B_Algorithm *, POINTER)); diff --git a/usr/src/lib/libresolv2/common/dnssafe/airsaepr.c b/usr/src/lib/libresolv2/common/dnssafe/airsaepr.c deleted file mode 100644 index 328366e90b..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/airsaepr.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ainfotyp.h" -#include "ainull.h" -#include "ahrsaepr.h" -#include "port_after.h" - -B_TypeCheck *AIT_PKCS_RSAPrivateNewHandler PROTO_LIST - ((B_AlgorithmInfoType *, B_Algorithm *)); - -static B_AlgorithmInfoTypeVTable V_TABLE = - {AITNullAddInfo, AIT_PKCS_RSAPrivateNewHandler, - B_AlgorithmInfoTypeMakeError}; - -B_AlgorithmInfoType AIT_PKCS_RSAPrivate = {&V_TABLE}; - -int AI_PKCS_RSAPrivate (infoType) -POINTER *infoType; -{ - *infoType = (POINTER)&AIT_PKCS_RSAPrivate; - - /* Return 0 to indicate a B_AlgorithmInfoType, not a B_KeyInfoType */ - return (0); -} - -B_TypeCheck *AIT_PKCS_RSAPrivateNewHandler (infoType, algorithm) -B_AlgorithmInfoType *infoType; -B_Algorithm *algorithm; -{ -UNUSED_ARG (infoType) -UNUSED_ARG (algorithm) - /* Pass in NULL_PTR so that constructor will allocate. */ - return ((B_TypeCheck *)AH_RSAEncrypPrivateConstructor - ((AH_RSAEncryptionPrivate *)NULL_PTR)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/airsaepu.c b/usr/src/lib/libresolv2/common/dnssafe/airsaepu.c deleted file mode 100644 index 1271220f7c..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/airsaepu.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ainfotyp.h" -#include "ainull.h" -#include "ahrsaepu.h" -#include "port_after.h" - -B_TypeCheck *AIT_PKCS_RSAPublicNewHandler PROTO_LIST - ((B_AlgorithmInfoType *, B_Algorithm *)); - -static B_AlgorithmInfoTypeVTable V_TABLE = - {AITNullAddInfo, AIT_PKCS_RSAPublicNewHandler, - B_AlgorithmInfoTypeMakeError}; - -B_AlgorithmInfoType AIT_PKCS_RSAPublic = {&V_TABLE}; - -int AI_PKCS_RSAPublic (infoType) -POINTER *infoType; -{ - *infoType = (POINTER)&AIT_PKCS_RSAPublic; - - /* Return 0 to indicate a B_AlgorithmInfoType, not a B_KeyInfoType */ - return (0); -} - -B_TypeCheck *AIT_PKCS_RSAPublicNewHandler (infoType, algorithm) -B_AlgorithmInfoType *infoType; -B_Algorithm *algorithm; -{ -UNUSED_ARG (infoType) -UNUSED_ARG (algorithm) - /* Pass in NULL_PTR so that constructor will allocate. */ - return ((B_TypeCheck *)AH_RSAEncrypPublicConstructor - ((AH_RSAEncryptionPublic *)NULL_PTR)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/airsakgn.c b/usr/src/lib/libresolv2/common/dnssafe/airsakgn.c deleted file mode 100644 index dfe450fe37..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/airsakgn.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "intitem.h" -#include "aichgen.h" -#include "port_after.h" - -int AIT_RSAKeyGenAddInfo PROTO_LIST - ((THIS_ALGORITHM_INFO_TYPE *, B_Algorithm *, POINTER)); - -static A_RSA_KEY_GEN_PARAMS STATIC_KEY_GEN_PARAMS; -static ITEM *KEY_GEN_PARAMS_ITEMS[] = {&STATIC_KEY_GEN_PARAMS.publicExponent}; - -static B_AlgorithmInfoTypeVTable V_TABLE = - {AIT_RSAKeyGenAddInfo, AITChooseGenerateNewHandler, - B_AlgorithmInfoTypeMakeError}; - -B_AlgorithmInfoType AIT_RSAKeyGen = {&V_TABLE}; - -int AI_RSAKeyGen (infoType) -POINTER *infoType; -{ - *infoType = (POINTER)&AIT_RSAKeyGen; - - /* Return 0 to indicate a B_AlgorithmInfoType, not a B_KeyInfoType */ - return (0); -} - -int AIT_RSAKeyGenAddInfo (infoType, algorithm, info) -B_AlgorithmInfoType *infoType; -B_Algorithm *algorithm; -POINTER info; -{ - A_RSA_KEY_GEN_PARAMS *newInfo; - int status; - - if ((status = B_MemoryPoolAlloc - (&algorithm->infoCache.memoryPool, (POINTER *)&newInfo, - sizeof (A_RSA_KEY_GEN_PARAMS))) != 0) - return (status); - if ((status = AllocAndCopyIntegerItems - ((POINTER)newInfo, info, (POINTER)&STATIC_KEY_GEN_PARAMS, - KEY_GEN_PARAMS_ITEMS, - sizeof (KEY_GEN_PARAMS_ITEMS) / sizeof (KEY_GEN_PARAMS_ITEMS[0]), - &algorithm->infoCache.memoryPool)) != 0) - return (status); - - newInfo->modulusBits = ((A_RSA_KEY_GEN_PARAMS *)info)->modulusBits; - return (B_InfoCacheAddInfo - (&algorithm->infoCache, (POINTER)infoType, (POINTER)newInfo)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/airsaprv.c b/usr/src/lib/libresolv2/common/dnssafe/airsaprv.c deleted file mode 100644 index 4aaa53b37b..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/airsaprv.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "aichencn.h" -#include "port_after.h" - -B_AlgorithmInfoType AIT_RSAPrivate = {&AITChooseEncryptNull_V_TABLE}; - -int AI_RSAPrivate (infoType) -POINTER *infoType; -{ - *infoType = (POINTER)&AIT_RSAPrivate; - - /* Return 0 to indicate a B_AlgorithmInfoType, not a B_KeyInfoType */ - return (0); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/airsapub.c b/usr/src/lib/libresolv2/common/dnssafe/airsapub.c deleted file mode 100644 index f0aef24046..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/airsapub.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "aichencn.h" -#include "port_after.h" - -B_AlgorithmInfoType AIT_RSAPublic = {&AITChooseEncryptNull_V_TABLE}; - -int AI_RSAPublic (infoType) -POINTER *infoType; -{ - *infoType = (POINTER)&AIT_RSAPublic; - - /* Return 0 to indicate a B_AlgorithmInfoType, not a B_KeyInfoType */ - return (0); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/algae.h b/usr/src/lib/libresolv2/common/dnssafe/algae.h deleted file mode 100644 index 0f66f796f0..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/algae.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1992, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _ALGAE_H_ -#define _ALGAE_H_ 1 - -#ifndef T_CALL -#define T_CALL -#endif - -/* Used to reduce the stack size in routines with big scratch buffers. - If set to 1, this will make ALGAE allocate these buffers on the heap. - */ -#ifndef USE_ALLOCED_FRAME -#define USE_ALLOCED_FRAME 1 -#endif - -#include "atypes.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define AE_CANCEL 0x0001 -#define AE_DATA 0x0002 -#define AE_EXPONENT_EVEN 0x0003 -#define AE_EXPONENT_LEN 0x0004 -#define AE_INPUT_DATA 0x0005 -#define AE_INPUT_LEN 0x0006 -#define AE_MODULUS_LEN 0x0007 -#define AE_NEED_RANDOM 0x0008 -#define AE_NOT_SUPPORTED 0x0009 -#define AE_OUTPUT_LEN 0x000a -#define AE_NOT_INITIALIZED 0x000b -#define AE_KEY_LEN 0x000c -#define AE_KEY_INFO 0x000d -#define AE_SEQUENCE 0x000e -#define AE_PARAMS 0x000f - -#if USE_ALLOCED_FRAME -/* Needed only for big number code heap allocation of scratch arrays. - */ -#define AE_ALLOC 0x0080 -POINTER T_malloc PROTO_LIST ((unsigned int)); -void T_free PROTO_LIST ((POINTER)); -#endif - -/* Routines supplied by the implementor. - */ -void T_memset PROTO_LIST ((POINTER, int, unsigned int)); -void T_memcpy PROTO_LIST ((POINTER, CPOINTER, unsigned int)); -void T_memmove PROTO_LIST ((POINTER, POINTER, unsigned int)); -int T_memcmp PROTO_LIST ((CPOINTER, CPOINTER, unsigned int)); - -unsigned int A_IntegerBits PROTO_LIST ((const unsigned char *, unsigned int)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/algchoic.c b/usr/src/lib/libresolv2/common/dnssafe/algchoic.c deleted file mode 100644 index b444c41be6..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/algchoic.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "algae.h" -#include "balgmeth.h" -#include "bkey.h" -#include "algchoic.h" -#include "port_after.h" - -/* In C++: -ResizeContext::ResizeContext () -{ - T_memset ((POINTER)&z, 0, sizeof (z)); -} - */ -void ResizeContextConstructor (resizeContext) -ResizeContext *resizeContext; -{ - T_memset ((POINTER)&resizeContext->z, 0, sizeof (resizeContext->z)); -} - -/* In C++: -ResizeContext::~ResizeContext () -{ - T_memset (z.context, 0, z.contextSize); - T_free (z.context); -} - */ -void ResizeContextDestructor (resizeContext) -ResizeContext *resizeContext; -{ - T_memset (resizeContext->z.context, 0, resizeContext->z.contextSize); - T_free (resizeContext->z.context); -} - -/* If the resizeContext's context is already the requested size, do nothing. - Otherwise, this memsets the existing context to zero, then allocates - the context as a buffer of the requested size. - If the allocate fails, the context size is set to - zero so that later calls will not zeroize non-existing buffers. - */ -int ResizeContextMakeNewContext (resizeContext, contextSize) -ResizeContext *resizeContext; -unsigned int contextSize; -{ - if (resizeContext->z.contextSize == contextSize) - return (0); - - /* Take care of zeroizing the previous context. - */ - T_memset (resizeContext->z.context, 0, resizeContext->z.contextSize); - - if ((resizeContext->z.context = T_realloc - (resizeContext->z.context, contextSize)) == NULL_PTR) { - resizeContext->z.contextSize = 0; - return (BE_ALLOC); - } - - resizeContext->z.contextSize = contextSize; - return (0); -} - -int AlgaChoiceChoose (algaChoice, encryptFlag, key, chooser, surrenderContext) -AlgaChoice *algaChoice; -int encryptFlag; -B_Key *key; -B_ALGORITHM_CHOOSER chooser; -A_SURRENDER_CTX *surrenderContext; -{ - POINTER keyInfo; - int status, overallStatus; - - /* Each alga init callback returns BE_NOT_SUPPORTED if the Query fails. - Each also may return a more specific error like BE_MODULUS_LEN if the - method is not supported, so return the more specific error if possible. - */ - overallStatus = BE_METHOD_NOT_IN_CHOOSER; - - for (; *chooser != (B_ALGORITHM_METHOD *)NULL_PTR; chooser++) { - if ((*chooser)->algorithmInfoType != algaChoice->_algorithmInfoType || - (*chooser)->encryptFlag != encryptFlag) - /* Wrong type of algorithm, or the encryptFlag is wrong */ - continue; - - if ((*chooser)->keyInfoType != (struct B_KeyInfoType *)NULL_PTR) { - if ((status = B_KeyGetInfo - (key, &keyInfo, (*chooser)->keyInfoType)) != 0) { - if (IS_FATAL_BSAFE_ERROR (status)) - return (status); - - /* Update the overall status with this more specific error. */ - overallStatus = status; - continue; - } - } - else - keyInfo = NULL_PTR; - - if ((status = (*algaChoice->_InitAlga) - (algaChoice, keyInfo, *chooser, surrenderContext)) != 0) { - if (IS_FATAL_BSAFE_ERROR (status)) - return (status); - - /* Update the overall status with this more specific error. */ - overallStatus = status; - continue; - } - - /* Succeeded */ - algaChoice->_alga = (*chooser)->alga; - return (0); - } - - return (overallStatus); -} - -/* Convert the ALGAE error to a BSAFE2 error. - This does not check for zero since BSAFE should not bother to call - this function if there is no error. - */ -int ConvertAlgaeError (type) -int type; -{ - switch (type) { - case AE_CANCEL: - return (BE_CANCEL); - case AE_DATA: - return (BE_DATA); - case AE_EXPONENT_EVEN: - return (BE_EXPONENT_EVEN); - case AE_EXPONENT_LEN: - return (BE_EXPONENT_LEN); - case AE_INPUT_DATA: - return (BE_INPUT_DATA); - case AE_INPUT_LEN: - return (BE_INPUT_LEN); - case AE_KEY_INFO: - return (BE_KEY_INFO); - case AE_KEY_LEN: - return (BE_KEY_LEN); - case AE_MODULUS_LEN: - return (BE_MODULUS_LEN); - case AE_NOT_INITIALIZED: - return (BE_NOT_INITIALIZED); - case AE_NOT_SUPPORTED: - return (BE_NOT_SUPPORTED); - case AE_OUTPUT_LEN: - return (BE_OUTPUT_LEN); - case AE_PARAMS: - return (BE_ALGORITHM_INFO); - -#if USE_ALLOCED_FRAME - case AE_ALLOC: - return (BE_ALLOC); -#endif - - default: - return (BE_DATA); - } -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/algchoic.h b/usr/src/lib/libresolv2/common/dnssafe/algchoic.h deleted file mode 100644 index 699b5dbe7d..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/algchoic.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _ALGCHOICE_H_ -#define _ALGCHOICE_H_ 1 - -#define IS_FATAL_BSAFE_ERROR(status) \ - (status == BE_ALLOC || status == BE_HARDWARE || status == BE_CANCEL) - -/* Use the THIS_ALGA_CHOICE macro to define the type of object in the - INIT_ALGA prototype. It defaults to the AlgaChoice, but - derived modules may define the macro to a more derived class before - including this header file. - */ -struct AlgaChoice; -#ifndef THIS_ALGA_CHOICE -#define THIS_ALGA_CHOICE struct AlgaChoice -#endif - -/* In C++: -class ResizeContext { -public: - ResizeContext (); - ~ResizeContext (); - int makeNewContext (unsigned int contextSize); - POINTER context () {return z.context;} - -private: - struct { - POINTER context; - unsigned int contextSize; - } z; -}; - -class AlgaChoice; -typedef int (*INIT_ALGA) - (THIS_ALGA_CHOICE *algaChoice, POINTER keyInfo, - struct B_ALGORITHM_METHOD *algorithmMethod, - A_SURRENDER_CTX *surrenderContext); - -class AlgaChoice { -public: - AlgaChoice (INIT_ALGA InitAlga) : _InitAlga (InitAlga) {} - ~AlgaChoice () {} - int choose - (int encryptFlag, B_Key *key, B_ALGORITHM_CHOOSER chooser, - A_SURRENDER_CTX *surrenderContext); - int makeNewContext (unsigned int contextSize) { - context.makeNewContext (contextSize); } - POINTER alga () {return _alga;} - POINTER algorithmInfo () {return _algorithmInfo;} - POINTER context () {return context.context ();} - void setAlgorithmInfoType (B_AlgorithmInfoType *algorithmInfoType) { - _algorithmInfoType = algorithmInfoType; - } - void setAlgorithmInfo (POINTER algorithmInfo) { - _algorithmInfo = algorithmInfo; - } - -private: - POINTER _alga; - B_AlgorithmInfoType *_algorithmInfoType; - POINTER _algorithmInfo; - INIT_ALGA _InitAlga; - - ResizeContext context; -}; - */ -struct B_AlgorithmInfoType; - -typedef struct ResizeContext { - struct { - POINTER context; - unsigned int contextSize; - } z; /* zeriozed by constructor */ -} ResizeContext; - -typedef int (*INIT_ALGA) PROTO_LIST - ((THIS_ALGA_CHOICE *, POINTER, struct B_ALGORITHM_METHOD *, - A_SURRENDER_CTX *)); - -typedef struct AlgaChoice { - POINTER _alga; - struct B_AlgorithmInfoType *_algorithmInfoType; - POINTER _algorithmInfo; - INIT_ALGA _InitAlga; - - ResizeContext context; -} AlgaChoice; - -void ResizeContextConstructor PROTO_LIST ((ResizeContext *)); -void ResizeContextDestructor PROTO_LIST ((ResizeContext *)); -int ResizeContextMakeNewContext PROTO_LIST ((ResizeContext *, unsigned int)); - -#define ALGA_CHOICE_Constructor(algaChoice, InitAlga)\ - (ResizeContextConstructor (&(algaChoice)->context), \ - (algaChoice)->_InitAlga = (InitAlga)) -#define ALGA_CHOICE_Destructor(algaChoice)\ - (ResizeContextDestructor (&(algaChoice)->context)) - -int AlgaChoiceChoose PROTO_LIST - ((AlgaChoice *, int, B_Key *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); - -int ConvertAlgaeError PROTO_LIST ((int)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/algobj.c b/usr/src/lib/libresolv2/common/dnssafe/algobj.c deleted file mode 100644 index 6be38586f9..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/algobj.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ainfotyp.h" -#include "keyobj.h" -#include "algobj.h" -#include "port_after.h" - -static char ALGORITHM_TYPE_TAG = 0; - -int B_CreateAlgorithmObject (algorithmObject) -B_ALGORITHM_OBJ *algorithmObject; -{ - AlgorithmWrap *algorithmWrap; - - if ((*algorithmObject = T_malloc (sizeof (*algorithmWrap))) == NULL_PTR) - return (BE_ALLOC); - - algorithmWrap = (AlgorithmWrap *)*algorithmObject; - - /* First construct base class */ - B_AlgorithmConstructor (&algorithmWrap->algorithm); - - algorithmWrap->typeTag = &ALGORITHM_TYPE_TAG; - algorithmWrap->selfCheck = algorithmWrap; - return (0); -} - -void B_DestroyAlgorithmObject (algorithmObject) -B_ALGORITHM_OBJ *algorithmObject; -{ - AlgorithmWrap *algorithmWrap = (AlgorithmWrap *)*algorithmObject; - - if (AlgorithmWrapCheck (algorithmWrap) == 0) { - /* zeroize self check to invalidate memory. */ - algorithmWrap->selfCheck = (AlgorithmWrap *)NULL_PTR; - - /* Call base class descructor */ - B_AlgorithmDestructor (&algorithmWrap->algorithm); - - T_free ((POINTER)algorithmWrap); - } - - *algorithmObject = NULL_PTR; -} - -int B_SetAlgorithmInfo (algorithmObject, infoType, info) -B_ALGORITHM_OBJ algorithmObject; -B_INFO_TYPE infoType; -POINTER info; -{ - B_AlgorithmInfoType *algorithmInfoType; - int status; - - if ((status = AlgorithmWrapCheck (THE_ALG_WRAP)) != 0) - return (status); - - /* Get the AlgorithmInfoType from the B_INFO_TYPE, which returns - zero for an AlgorithmInfoType, non-zero for KeyInfoType - */ - if ((*infoType) ((POINTER *)&algorithmInfoType) != 0) - return (BE_KEY_OPERATION_UNKNOWN); - - return (B_AlgorithmSetInfo - (&THE_ALG_WRAP->algorithm, algorithmInfoType, info)); -} - -int B_GetAlgorithmInfo (info, algorithmObject, infoType) -POINTER *info; -B_ALGORITHM_OBJ algorithmObject; -B_INFO_TYPE infoType; -{ - B_AlgorithmInfoType *algorithmInfoType; - int status; - - if ((status = AlgorithmWrapCheck (THE_ALG_WRAP)) != 0) - return (status); - - /* Get the AlgorithmInfoType from the B_INFO_TYPE, which returns - zero for an AlgorithmInfoType, non-zero for KeyInfoType - */ - if ((*infoType) ((POINTER *)&algorithmInfoType) != 0) - return (BE_KEY_OPERATION_UNKNOWN); - - return (B_AlgorithmGetInfo - (&THE_ALG_WRAP->algorithm, info, algorithmInfoType)); -} - -/* Return 0 if this is a valid AlgorithmWrap object. Return BE_ALGORITHM_OBJ if - algorithmWrap is NULL_PTR or invalid. - */ -int AlgorithmWrapCheck (algorithmWrap) -AlgorithmWrap *algorithmWrap; -{ - return ((algorithmWrap != (AlgorithmWrap *)NULL_PTR && - algorithmWrap->selfCheck == algorithmWrap && - algorithmWrap->typeTag == &ALGORITHM_TYPE_TAG) ? - 0 : BE_ALGORITHM_OBJ); -} - -/* Like AlgorithmWrapCheck except returns BE_RANDOM_OBJ for error. - Also, return OK status if randomAlgorithm is NULL_PTR. - */ -int RandomAlgorithmCheck (randomAlgorithm) -B_ALGORITHM_OBJ randomAlgorithm; -{ - if (randomAlgorithm == NULL_PTR) - return (0); - - return (AlgorithmWrapCheck ((AlgorithmWrap *)randomAlgorithm) ? - BE_RANDOM_OBJ : 0); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/algobj.h b/usr/src/lib/libresolv2/common/dnssafe/algobj.h deleted file mode 100644 index a101e8f719..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/algobj.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#define THE_ALG_WRAP ((AlgorithmWrap *)algorithmObject) - -typedef struct AlgorithmWrap { - B_Algorithm algorithm; - char *typeTag; - struct AlgorithmWrap *selfCheck; -} AlgorithmWrap; - -int AlgorithmWrapCheck PROTO_LIST ((AlgorithmWrap *)); -int RandomAlgorithmCheck PROTO_LIST ((B_ALGORITHM_OBJ)); - diff --git a/usr/src/lib/libresolv2/common/dnssafe/amcrte.c b/usr/src/lib/libresolv2/common/dnssafe/amcrte.c deleted file mode 100644 index beb2c4555b..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/amcrte.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1994, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "bsafe2.h" -#include "balgmeth.h" -#include "crt2.h" -#include "amencdec.h" -#include "port_after.h" - -static int RSA_CRT2Query PROTO_LIST ((unsigned int *, POINTER, POINTER)); -static int RSA_CRT2Init PROTO_LIST - ((POINTER, POINTER, POINTER, A_SURRENDER_CTX *)); -static int RSA_CRT2Update PROTO_LIST - ((POINTER, unsigned char *, unsigned int *, unsigned int, - const unsigned char *, unsigned int, A_SURRENDER_CTX *)); -static int RSA_CRT2Final PROTO_LIST - ((POINTER, unsigned char *, unsigned int *, unsigned int, - A_SURRENDER_CTX *)); -static int RSA_CRT2GetMaxOutputLen PROTO_LIST - ((POINTER, unsigned int *, unsigned int)); -static int RSA_CRT2GetBlockLen PROTO_LIST ((POINTER, unsigned int *)); - -extern struct B_AlgorithmInfoType AIT_RSAPrivate; -extern struct B_KeyInfoType KIT_RSA_CRT; - -static A_ENCRYPT_DECRYPT_ALGA A_RSA_CRT2_CRYPT = { - RSA_CRT2Query, RSA_CRT2Init, RSA_CRT2Update, RSA_CRT2Final, - RSA_CRT2GetMaxOutputLen, RSA_CRT2GetBlockLen -}; - -B_ALGORITHM_METHOD AM_RSA_CRT_DECRYPT = - {&AIT_RSAPrivate, 0, &KIT_RSA_CRT, (POINTER)&A_RSA_CRT2_CRYPT}; -B_ALGORITHM_METHOD AM_RSA_CRT_ENCRYPT = - {&AIT_RSAPrivate, 1, &KIT_RSA_CRT, (POINTER)&A_RSA_CRT2_CRYPT}; - -static int RSA_CRT2Query (contextLen, key, params) -unsigned int *contextLen; -POINTER key; -POINTER params; -{ -UNUSED_ARG (params) - - if (A_IntegerBits - (((A_RSA_CRT_KEY *)key)->modulus.data, - ((A_RSA_CRT_KEY *)key)->modulus.len) > MAX_RSA_MODULUS_BITS) - /* Key size is too big to handle. */ - return (AE_MODULUS_LEN); - - *contextLen = sizeof (A_RSA_CRT2_CTX); - return (0); -} - -static int RSA_CRT2Init (context, key, params, surrenderContext) -POINTER context; -POINTER key; -POINTER params; -A_SURRENDER_CTX *surrenderContext; -{ -UNUSED_ARG (params) -UNUSED_ARG (surrenderContext) - - return (A_RSA_CRT2Init ((A_RSA_CRT2_CTX *)context, (A_RSA_CRT_KEY *)key)); -} - -static int RSA_CRT2Update - (context, output, outputLen, maxOutputLen, input, inputLen, surrenderContext) -POINTER context; -unsigned char *output; -unsigned int *outputLen; -unsigned int maxOutputLen; -const unsigned char *input; -unsigned int inputLen; -A_SURRENDER_CTX *surrenderContext; -{ - return (A_RSA_CRT2Update - ((A_RSA_CRT2_CTX *)context, output, outputLen, maxOutputLen, input, - inputLen, surrenderContext)); -} - -static int RSA_CRT2Final - (context, output, outputLen, maxOutputLen, surrenderContext) -POINTER context; -unsigned char *output; -unsigned int *outputLen; -unsigned int maxOutputLen; -A_SURRENDER_CTX * surrenderContext; -{ -UNUSED_ARG (output) -UNUSED_ARG (maxOutputLen) -UNUSED_ARG (surrenderContext) - - *outputLen = 0; - return (A_RSA_CRT2Final ((A_RSA_CRT2_CTX *)context)); -} - -static int RSA_CRT2GetMaxOutputLen (context, outputLen, inputLen) -POINTER context; -unsigned int *outputLen; -unsigned int inputLen; -{ - *outputLen = A_RSA_CRT2_MAX_OUTPUT_LEN ((A_RSA_CRT2_CTX *)context, inputLen); - return (0); -} - -static int RSA_CRT2GetBlockLen (context, blockLen) -POINTER context; -unsigned int *blockLen; -{ - *blockLen = A_RSA_CRT2_BLOCK_LEN ((A_RSA_CRT2_CTX *)context); - return(0); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/amdigest.h b/usr/src/lib/libresolv2/common/dnssafe/amdigest.h deleted file mode 100644 index f58f2e1fcf..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/amdigest.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1994, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -typedef struct { - int (*Query) PROTO_LIST ((unsigned int *, POINTER)); - int (*Init) PROTO_LIST ((POINTER, POINTER, A_SURRENDER_CTX *)); - int (*Update) PROTO_LIST - ((POINTER, const unsigned char *, unsigned int, A_SURRENDER_CTX *)); - int (*Final) PROTO_LIST - ((POINTER, unsigned char *, unsigned int *, unsigned int, - A_SURRENDER_CTX *)); - int (*GetMaxOutputLen) PROTO_LIST ((POINTER, unsigned int *)); -} A_DIGEST_ALGA; - diff --git a/usr/src/lib/libresolv2/common/dnssafe/amencdec.h b/usr/src/lib/libresolv2/common/dnssafe/amencdec.h deleted file mode 100644 index 0cacf5236c..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/amencdec.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1994, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -typedef struct { - int (*Query) PROTO_LIST ((unsigned int *, POINTER, POINTER)); - int (*Init) PROTO_LIST ((POINTER, POINTER, POINTER, A_SURRENDER_CTX *)); - int (*Update) PROTO_LIST - ((POINTER, unsigned char *, unsigned int *, unsigned int, - const unsigned char *, unsigned int, A_SURRENDER_CTX *)); - int (*Final) PROTO_LIST - ((POINTER, unsigned char *, unsigned int *, unsigned int, - A_SURRENDER_CTX *)); - int (*GetMaxOutputLen) PROTO_LIST ((POINTER, unsigned int *, unsigned int)); - int (*GetBlockLen) PROTO_LIST ((POINTER, unsigned int *)); -} A_ENCRYPT_DECRYPT_ALGA; - diff --git a/usr/src/lib/libresolv2/common/dnssafe/amgen.h b/usr/src/lib/libresolv2/common/dnssafe/amgen.h deleted file mode 100644 index dfc56deba5..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/amgen.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1994, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -struct B_KeyInfoType; - -typedef struct { - int (*Query) PROTO_LIST - ((unsigned int *, unsigned int *, unsigned int *, struct B_KeyInfoType **, - POINTER)); - int (*Init) PROTO_LIST ((POINTER, POINTER, POINTER, A_SURRENDER_CTX *)); - int (*Generate) PROTO_LIST - ((POINTER, POINTER *, unsigned char *, A_SURRENDER_CTX *)); -} A_GENERATE_ALGA; - diff --git a/usr/src/lib/libresolv2/common/dnssafe/ammd5.c b/usr/src/lib/libresolv2/common/dnssafe/ammd5.c deleted file mode 100644 index 26c7503952..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ammd5.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "bsafe2.h" -#include "balgmeth.h" -#include "md5.h" -#include "amdigest.h" -#include "port_after.h" - -static int amMD5Query PROTO_LIST ((unsigned int *, POINTER)); -static int amMD5Init PROTO_LIST ((POINTER, POINTER, A_SURRENDER_CTX*)); -static int amMD5Update PROTO_LIST - ((POINTER, const unsigned char *, unsigned int, A_SURRENDER_CTX*)); -static int amMD5Final PROTO_LIST - ((POINTER, unsigned char *, unsigned int *, unsigned int, A_SURRENDER_CTX*)); -static int amMD5GetMaxOutputLen PROTO_LIST ((POINTER, unsigned int *)); - -static A_DIGEST_ALGA A_MD5_DIGEST = { - amMD5Query, amMD5Init, amMD5Update, amMD5Final, amMD5GetMaxOutputLen -}; - -extern struct B_AlgorithmInfoType AIT_MD5; - -B_ALGORITHM_METHOD AM_MD5 = - {&AIT_MD5, 0, (struct B_KeyInfoType *)NULL_PTR, (POINTER)&A_MD5_DIGEST}; - -/* Returns 0. - */ -static int amMD5Query (contextLen, params) -unsigned int *contextLen; -POINTER params; -{ -UNUSED_ARG (params) - - *contextLen = sizeof (A_MD5_CTX); - return (0); -} - -/* Returns 0. - */ -static int amMD5Init (context, params, surrenderContext) -POINTER context; -POINTER params; -A_SURRENDER_CTX *surrenderContext; -{ -UNUSED_ARG (params) -UNUSED_ARG (surrenderContext) - - A_MD5Init ((A_MD5_CTX *)context); - return (0); -} - -/* Returns 0. - */ -static int amMD5Update (context, input, inputLen, surrenderContext) -POINTER context; -const unsigned char *input; -unsigned int inputLen; -A_SURRENDER_CTX *surrenderContext; -{ -UNUSED_ARG (surrenderContext) - - A_MD5Update ((A_MD5_CTX *)context, input, inputLen); - return (0); -} - -/* Returns 0, AE_OUTPUT_LEN if maxDigestLen is too small. - */ -static int amMD5Final - (context, digest, digestLen, maxDigestLen, surrenderContext) -POINTER context; -unsigned char *digest; -unsigned int *digestLen; -unsigned int maxDigestLen; -A_SURRENDER_CTX *surrenderContext; -{ -UNUSED_ARG (surrenderContext) - - if ((*digestLen = A_MD5_DIGEST_LEN) > maxDigestLen) - return (AE_OUTPUT_LEN); - - A_MD5Final ((A_MD5_CTX *)context, digest); - return (0); -} - -static int amMD5GetMaxOutputLen (context, outputLen) -POINTER context; -unsigned int *outputLen; -{ -UNUSED_ARG (context) - - *outputLen = A_MD5_DIGEST_LEN; - return(0); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/ammd5r.c b/usr/src/lib/libresolv2/common/dnssafe/ammd5r.c deleted file mode 100644 index 10ffb58635..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ammd5r.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "bsafe2.h" -#include "balgmeth.h" -#include "md5rand.h" -#include "amrandom.h" -#include "port_after.h" - -static int MD5RandomQuery PROTO_LIST ((unsigned int *, POINTER)); -static int MD5RandomInit PROTO_LIST ((POINTER, POINTER, A_SURRENDER_CTX *)); -static int MD5RandomUpdate PROTO_LIST - ((POINTER, unsigned char *, unsigned int, A_SURRENDER_CTX *)); -static int MD5RandomGenerateBytes PROTO_LIST - ((POINTER, unsigned char *, unsigned int, A_SURRENDER_CTX *)); - -extern struct B_AlgorithmInfoType AIT_MD5Random; - -static A_RANDOM_ALGA A_MD5_RANDOM = - {MD5RandomQuery, MD5RandomInit, MD5RandomUpdate, MD5RandomGenerateBytes}; - -B_ALGORITHM_METHOD AM_MD5_RANDOM = - {&AIT_MD5Random, 0, (struct B_KeyInfoType *)NULL_PTR, - (POINTER)&A_MD5_RANDOM}; - -static int MD5RandomQuery (contextLen, params) -unsigned int *contextLen; -POINTER params; -{ -UNUSED_ARG (params) - - *contextLen = sizeof (A_MD5_RANDOM_CTX); - return (0); -} - -static int MD5RandomInit (context, params, surrenderContext) -POINTER context; -POINTER params; -A_SURRENDER_CTX *surrenderContext; -{ -UNUSED_ARG (params) -UNUSED_ARG (surrenderContext) - - A_MD5RandomInit ((A_MD5_RANDOM_CTX *)context); - return (0); -} - -static int MD5RandomUpdate (context, input, inputLen, surrenderContext) -POINTER context; -unsigned char *input; -unsigned int inputLen; -A_SURRENDER_CTX *surrenderContext; -{ -UNUSED_ARG (surrenderContext) - - A_MD5RandomUpdate ((A_MD5_RANDOM_CTX *)context, input, inputLen); - return (0); -} - -static int MD5RandomGenerateBytes - (context, output, outputLen, surrenderContext) -POINTER context; -unsigned char *output; -unsigned int outputLen; -A_SURRENDER_CTX *surrenderContext; -{ -UNUSED_ARG (surrenderContext) - - A_MD5RandomGenerateBytes ((A_MD5_RANDOM_CTX *)context, output, outputLen); - return (0); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/amrandom.h b/usr/src/lib/libresolv2/common/dnssafe/amrandom.h deleted file mode 100644 index 2576e389c8..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/amrandom.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1994, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -typedef struct { - int (*Query) PROTO_LIST ((unsigned int *, POINTER)); - int (*Init) PROTO_LIST ((POINTER, POINTER, A_SURRENDER_CTX *)); - int (*Update) PROTO_LIST - ((POINTER, unsigned char *, unsigned int, A_SURRENDER_CTX *)); - int (*Generate) PROTO_LIST - ((POINTER, unsigned char *, unsigned int, A_SURRENDER_CTX *)); -} A_RANDOM_ALGA; - diff --git a/usr/src/lib/libresolv2/common/dnssafe/amrkg.c b/usr/src/lib/libresolv2/common/dnssafe/amrkg.c deleted file mode 100644 index 7fe6905899..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/amrkg.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1994, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "algae.h" -#include "rsakeygn.h" -#include "balgmeth.h" -#include "amgen.h" -#include "port_after.h" - -#define THE_GEN_PARAMS ((A_RSA_KEY_GEN_PARAMS *)params) - -extern struct B_AlgorithmInfoType AIT_RSAKeyGen; -extern struct B_KeyInfoType KIT_PKCS_RSAPrivate; - -static int RSAKeyGenQuery PROTO_LIST - ((unsigned int *, unsigned int *, unsigned int *, struct B_KeyInfoType **, - POINTER)); -static int RSAKeyGenInit PROTO_LIST - ((POINTER, POINTER, POINTER, A_SURRENDER_CTX *)); -static int RSAKeyGen PROTO_LIST - ((POINTER, POINTER *, unsigned char *, A_SURRENDER_CTX *)); - -static A_GENERATE_ALGA A_RSA_KEY_GEN = - {RSAKeyGenQuery, RSAKeyGenInit, RSAKeyGen}; - -B_ALGORITHM_METHOD AM_RSA_KEY_GEN = - {&AIT_RSAKeyGen, 0, (struct B_KeyInfoType *)NULL_PTR, - (POINTER)&A_RSA_KEY_GEN}; - -static int RSAKeyGenQuery - (contextLen, secondContextLen, randomBlockLen, resultInfoType, params) -unsigned int *contextLen; -unsigned int *secondContextLen; -unsigned int *randomBlockLen; -struct B_KeyInfoType **resultInfoType; -POINTER params; -{ - if ((THE_GEN_PARAMS->modulusBits > MAX_RSA_MODULUS_BITS) || - (THE_GEN_PARAMS->modulusBits < MIN_RSA_MODULUS_BITS)) - /* Can't support a keypair of this size. */ - return (AE_MODULUS_LEN); - - *contextLen = sizeof (A_RSA_KEY_GEN_CTX); - *secondContextLen = 0; - *randomBlockLen = - A_RSA_KEY_GEN_RANDOM_BLOCK_LEN (THE_GEN_PARAMS->modulusBits); - *resultInfoType = &KIT_PKCS_RSAPrivate; - - return (0); -} - -static int RSAKeyGenInit (context, secondContext, params, surrenderContext) -POINTER context; -POINTER secondContext; -POINTER params; -A_SURRENDER_CTX *surrenderContext; -{ -UNUSED_ARG (secondContext) -UNUSED_ARG (surrenderContext) - - return (A_RSAKeyGenInit - ((A_RSA_KEY_GEN_CTX *)context, (A_RSA_KEY_GEN_PARAMS *)params)); -} - -static int RSAKeyGen (context, result, randomBlock, surrenderContext) -POINTER context; -POINTER *result; -unsigned char *randomBlock; -A_SURRENDER_CTX *surrenderContext; -{ - return (A_RSAKeyGen - ((A_RSA_KEY_GEN_CTX *)context, (A_PKCS_RSA_PRIVATE_KEY **)result, - randomBlock, surrenderContext)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/amrsae.c b/usr/src/lib/libresolv2/common/dnssafe/amrsae.c deleted file mode 100644 index 01a26bef47..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/amrsae.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1994, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "bsafe2.h" -#include "balgmeth.h" -#include "rsa.h" -#include "amencdec.h" -#include "port_after.h" - -static int RSAQuery PROTO_LIST ((unsigned int *, POINTER, POINTER)); -static int RSAInit PROTO_LIST ((POINTER, POINTER, POINTER, A_SURRENDER_CTX *)); -static int RSAUpdate PROTO_LIST - ((POINTER, unsigned char *, unsigned int *, unsigned int, - const unsigned char *, unsigned int, A_SURRENDER_CTX *)); -static int RSAFinal PROTO_LIST - ((POINTER, unsigned char *, unsigned int *, unsigned int, - A_SURRENDER_CTX *)); -static int RSAGetMaxOutputLen PROTO_LIST - ((POINTER, unsigned int *, unsigned int)); -static int RSAGetBlockLen PROTO_LIST ((POINTER, unsigned int *)); - -extern struct B_AlgorithmInfoType AIT_RSAPublic; -extern struct B_KeyInfoType KIT_RSAPublic; - -static A_ENCRYPT_DECRYPT_ALGA A_RSA_CRYPT = { - RSAQuery, RSAInit, RSAUpdate, RSAFinal, RSAGetMaxOutputLen, RSAGetBlockLen -}; - -B_ALGORITHM_METHOD AM_RSA_DECRYPT = - {&AIT_RSAPublic, 0, &KIT_RSAPublic, (POINTER)&A_RSA_CRYPT}; -B_ALGORITHM_METHOD AM_RSA_ENCRYPT = - {&AIT_RSAPublic, 1, &KIT_RSAPublic, (POINTER)&A_RSA_CRYPT}; - -static int RSAQuery (contextLen, key, params) -unsigned int *contextLen; -POINTER key; -POINTER params; -{ -UNUSED_ARG (params) - - if (A_IntegerBits - (((A_RSA_KEY *)key)->modulus.data, ((A_RSA_KEY *)key)->modulus.len) - > MAX_RSA_MODULUS_BITS) - /* Key size is too big to handle. */ - return (AE_MODULUS_LEN); - - *contextLen = sizeof (A_RSA_CTX); - return (0); -} - -static int RSAInit (context, key, params, surrenderContext) -POINTER context; -POINTER key; -POINTER params; -A_SURRENDER_CTX *surrenderContext; -{ -UNUSED_ARG (params) -UNUSED_ARG (surrenderContext) - - return (A_RSAInit ((A_RSA_CTX *)context, (A_RSA_KEY *)key)); -} - -static int RSAUpdate - (context, output, outputLen, maxOutputLen, input, inputLen, surrenderContext) -POINTER context; -unsigned char *output; -unsigned int *outputLen; -unsigned int maxOutputLen; -const unsigned char *input; -unsigned int inputLen; -A_SURRENDER_CTX *surrenderContext; -{ - return (A_RSAUpdate - ((A_RSA_CTX *)context, output, outputLen, maxOutputLen, input, - inputLen, surrenderContext)); -} - -static int RSAFinal - (context, output, outputLen, maxOutputLen, surrenderContext) -POINTER context; -unsigned char *output; -unsigned int *outputLen; -unsigned int maxOutputLen; -A_SURRENDER_CTX * surrenderContext; -{ -UNUSED_ARG (output) -UNUSED_ARG (maxOutputLen) -UNUSED_ARG (surrenderContext) - - *outputLen = 0; - return (A_RSAFinal ((A_RSA_CTX *)context)); -} - -static int RSAGetMaxOutputLen (context, outputLen, inputLen) -POINTER context; -unsigned int *outputLen; -unsigned int inputLen; -{ - *outputLen = A_RSA_MAX_OUTPUT_LEN ((A_RSA_CTX *)context, inputLen); - return (0); -} - -static int RSAGetBlockLen (context, blockLen) -POINTER context; -unsigned int *blockLen; -{ - *blockLen = A_RSA_BLOCK_LEN ((A_RSA_CTX *)context); - return(0); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/atypes.h b/usr/src/lib/libresolv2/common/dnssafe/atypes.h deleted file mode 100644 index 8fbfeb6b27..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/atypes.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1992, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _ATYPES_H_ -#define _ATYPES_H_ 1 - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ITEM_ -#define _ITEM_ 1 -typedef struct { - unsigned char *data; - unsigned int len; -} ITEM; -#endif - -typedef struct { - int (T_CALL *Surrender) PROTO_LIST ((POINTER)); - POINTER handle; - POINTER reserved; -} A_SURRENDER_CTX; - -typedef struct { - ITEM modulus; - ITEM publicExponent; - ITEM privateExponent; - ITEM prime[2]; /* prime factors */ - ITEM primeExponent[2]; /* exponents for prime factors */ - ITEM coefficient; /* CRT coefficient */ -} A_PKCS_RSA_PRIVATE_KEY; - -typedef struct { - ITEM modulus; - ITEM prime[2]; /* prime factors */ - ITEM primeExponent[2]; /* exponents for prime factors */ - ITEM coefficient; /* CRT coefficient */ -} A_RSA_CRT_KEY; - -typedef struct { - ITEM modulus; /* modulus */ - ITEM exponent; /* exponent */ -} A_RSA_KEY; - -typedef struct { - unsigned int modulusBits; - ITEM publicExponent; -} A_RSA_KEY_GEN_PARAMS; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/balg.c b/usr/src/lib/libresolv2/common/dnssafe/balg.c deleted file mode 100644 index 0105aa2873..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/balg.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "btypechk.h" -#include "ainfotyp.h" -#include "port_after.h" - -void B_AlgorithmConstructor (algorithm) -B_Algorithm *algorithm; -{ - /* Construct immediate base class. */ - B_InfoCacheConstructor (&algorithm->infoCache); - - T_memset ((POINTER)&algorithm->z, 0, sizeof (algorithm->z)); -} - -void B_AlgorithmDestructor (algorithm) -B_Algorithm *algorithm; -{ - if (algorithm->z.handler != (B_TypeCheck *)NULL_PTR) { - B_TYPE_CHECK_Destructor (algorithm->z.handler); - T_free ((POINTER)algorithm->z.handler); - } - - /* Destroy base class */ - B_INFO_CACHE_Destructor (&algorithm->infoCache); -} - -int B_AlgorithmCheckType (algorithm, Destructor) -B_Algorithm *algorithm; -B_TYPE_CHECK_DESTRUCTOR Destructor; -{ - if (algorithm->z.handler == (B_TypeCheck *)NULL_PTR) - return (BE_ALGORITHM_NOT_SET); - - if (algorithm->z.handler->_Destructor != Destructor) - return (BE_ALG_OPERATION_UNKNOWN); - - return (0); -} - -int B_AlgorithmCheckTypeAndInitFlag (algorithm, Destructor) -B_Algorithm *algorithm; -B_TYPE_CHECK_DESTRUCTOR Destructor; -{ - int status; - - /* Check the type first. */ - if ((status = B_AlgorithmCheckType (algorithm, Destructor)) != 0) - return (status); - - if (!algorithm->z.initFlag) - return (BE_ALGORITHM_NOT_INITIALIZED); - - return (0); -} - -int B_AlgorithmSetInfo (algorithm, algorithmInfoType, info) -B_Algorithm *algorithm; -B_AlgorithmInfoType *algorithmInfoType; -POINTER info; -{ - int status; - - if (algorithm->infoCache.z.infoCount > 0) - return (BE_ALGORITHM_ALREADY_SET); - - /* This will cache the encoding. */ - if ((status = (*algorithmInfoType->vTable->AddInfo) - (algorithmInfoType, algorithm, info)) != 0) - return (status); - - /* Allocate the algorithm handler. NewHandler returns NULL_PTR for error. - */ - if ((algorithm->z.handler = (*algorithmInfoType->vTable->NewHandler) - (algorithmInfoType, algorithm)) == (B_TypeCheck *)NULL_PTR) - return (BE_ALLOC); - - return (0); -} - -int B_AlgorithmGetInfo (algorithm, info, algorithmInfoType) -B_Algorithm *algorithm; -POINTER *info; -B_AlgorithmInfoType *algorithmInfoType; -{ - int status; - - if (algorithm->infoCache.z.infoCount == 0) - return (BE_ALGORITHM_NOT_SET); - - /* First check if the encoding is already in the encoding cache. - */ - if (B_InfoCacheFindInfo - (&algorithm->infoCache, info, (POINTER)algorithmInfoType) == 0) - return (0); - - /* Info is not in the cache, go ahead and encode. - */ - if ((status = (*algorithmInfoType->vTable->MakeInfo) - (algorithmInfoType, info, algorithm)) != 0) - return (status); - - return (B_InfoCacheAddInfo - (&algorithm->infoCache, (POINTER)algorithmInfoType, *info)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/balg.h b/usr/src/lib/libresolv2/common/dnssafe/balg.h deleted file mode 100644 index 8c2e2cfe26..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/balg.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _BALG_H_ -#define _BALG_H_ 1 - -#include "binfocsh.h" -#include "btypechk.h" - -typedef struct { - B_InfoCache infoCache; /* inherited */ - - struct { - B_TypeCheck *handler; - int initFlag; - /* POINTER reserved; */ - } z; -} B_Algorithm; - -void B_AlgorithmConstructor PROTO_LIST ((B_Algorithm *)); -void B_AlgorithmDestructor PROTO_LIST ((B_Algorithm *)); - -int B_AlgorithmCheckType PROTO_LIST ((B_Algorithm *, B_TYPE_CHECK_DESTRUCTOR)); -int B_AlgorithmCheckTypeAndInitFlag PROTO_LIST - ((B_Algorithm *, B_TYPE_CHECK_DESTRUCTOR)); - -struct B_AlgorithmInfoType; -int B_AlgorithmSetInfo PROTO_LIST - ((B_Algorithm *, struct B_AlgorithmInfoType *, POINTER)); -int B_AlgorithmGetInfo PROTO_LIST - ((B_Algorithm *, POINTER *, struct B_AlgorithmInfoType *)); - -int B_AlgorithmRandomInit PROTO_LIST - ((B_Algorithm *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int B_AlgorithmRandomUpdate PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int, A_SURRENDER_CTX *)); -int B_AlgorithmGenerateRandomBytes PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int, A_SURRENDER_CTX *)); - -int B_AlgorithmDigestInit PROTO_LIST - ((B_Algorithm *, B_Key *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int B_AlgorithmDigestUpdate PROTO_LIST - ((B_Algorithm *, const unsigned char *, unsigned int, A_SURRENDER_CTX *)); -int B_AlgorithmDigestFinal PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int *, unsigned int, - A_SURRENDER_CTX *)); - -int B_AlgorithmEncryptInit PROTO_LIST - ((B_Algorithm *, B_Key *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int B_AlgorithmDecryptInit PROTO_LIST - ((B_Algorithm *, B_Key *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int B_AlgorithmEncryptUpdate PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int *, unsigned int, - unsigned char *, unsigned int, B_Algorithm *, A_SURRENDER_CTX *)); -int B_AlgorithmDecryptUpdate PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int *, unsigned int, - const unsigned char *, unsigned int, B_Algorithm *, A_SURRENDER_CTX *)); -int B_AlgorithmEncryptFinal PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int *, unsigned int, - B_Algorithm *, A_SURRENDER_CTX *)); -int B_AlgorithmDecryptFinal PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int *, unsigned int, - B_Algorithm *, A_SURRENDER_CTX *)); - -int B_AlgorithmEncodeInit PROTO_LIST ((B_Algorithm *)); -int B_AlgorithmDecodeInit PROTO_LIST ((B_Algorithm *)); -int B_AlgorithmEncodeUpdate PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int *, unsigned int, - unsigned char *, unsigned int)); -int B_AlgorithmDecodeUpdate PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int *, unsigned int, - unsigned char *, unsigned int)); -int B_AlgorithmEncodeFinal PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int *, unsigned int)); -int B_AlgorithmDecodeFinal PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int *, unsigned int)); - -int B_AlgorithmSignInit PROTO_LIST - ((B_Algorithm *, B_Key *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int B_AlgorithmSignUpdate PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int, A_SURRENDER_CTX *)); -int B_AlgorithmSignFinal PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int *, unsigned int, - B_Algorithm *, A_SURRENDER_CTX *)); - -int B_AlgorithmVerifyInit PROTO_LIST - ((B_Algorithm *, B_Key *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int B_AlgorithmVerifyUpdate PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int, A_SURRENDER_CTX *)); -int B_AlgorithmVerifyFinal PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int, B_Algorithm *, - A_SURRENDER_CTX *)); - -int B_AlgorithmKeyAgreeInit PROTO_LIST - ((B_Algorithm *, B_Key *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int B_AlgorithmKeyAgreePhase1 PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int *, unsigned int, - B_Algorithm *, A_SURRENDER_CTX *)); -int B_AlgorithmKeyAgreePhase2 PROTO_LIST - ((B_Algorithm *, unsigned char *, unsigned int *, unsigned int, - unsigned char *, unsigned int, A_SURRENDER_CTX *)); - -int B_AlgorithmGenerateInit PROTO_LIST - ((B_Algorithm *, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int B_AlgorithmGenerateKeypair PROTO_LIST - ((B_Algorithm *, B_Key *, B_Key *, B_Algorithm *, - A_SURRENDER_CTX *)); -int B_AlgorithmGenerateParameters PROTO_LIST - ((B_Algorithm *, B_Algorithm *, B_Algorithm *, A_SURRENDER_CTX *)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/balgmeth.h b/usr/src/lib/libresolv2/common/dnssafe/balgmeth.h deleted file mode 100644 index 98ea56077c..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/balgmeth.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -struct B_AlgorithmInfoType; -struct B_KeyInfoType; - -struct B_ALGORITHM_METHOD { - struct B_AlgorithmInfoType *algorithmInfoType; - int encryptFlag; - struct B_KeyInfoType *keyInfoType; - POINTER alga; -}; - diff --git a/usr/src/lib/libresolv2/common/dnssafe/bgclrbit.c b/usr/src/lib/libresolv2/common/dnssafe/bgclrbit.c deleted file mode 100644 index 717e985a7c..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bgclrbit.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* BigClrbit (a, v) -- clears v-th bit of a, where v is nonnegative. - */ -void BigClrbit (a, v) -UINT2 *a; -unsigned int v; -{ - a[v/16] &= ~ (1 << (v % 16)); -} - -/* BigSetbit (a, v) -- sets v-th bit of a, where v is nonnegative. - */ -void BigSetbit (a, v) -UINT2 *a; -unsigned int v; -{ - a[v/16] |= (1 << (v % 16)); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bgmdmpyx.c b/usr/src/lib/libresolv2/common/dnssafe/bgmdmpyx.c deleted file mode 100644 index 8c0bc71172..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bgmdmpyx.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* BigModMpyx (a, b, c, d, dInv, n) -- a = (b * c) mod d !! EXPRESS. - -- assumes a, b, c, d of length n, dInv of length n+2. - -- assumes dInv previously computed by BigInv. - */ -void BigModMpyx (a, b, c, d, dInv, n) -UINT2 *a, *b, *c, *d, *dInv; -unsigned int n; -{ - UINT2 prod[2 * MAX_RSA_MODULUS_WORDS]; - - BigPmpy (prod, b, c, n); - BigModx (a, prod, d, dInv, n); - - T_memset ((POINTER)prod, 0, sizeof (prod)); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bgmdsqx.c b/usr/src/lib/libresolv2/common/dnssafe/bgmdsqx.c deleted file mode 100644 index f976aa7bbd..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bgmdsqx.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* BigModSqx (a, b, d, dInv, n) -- a = (b * b) mod d !! EXPRESS. - */ -void BigModSqx (a, b, d, dInv, n) -UINT2 *a, *b, *d, *dInv; -unsigned int n; -{ - UINT2 prod[2 * MAX_RSA_MODULUS_WORDS]; - - BigPsq (prod, b, n); - BigModx (a, prod, d, dInv, n); - - T_memset ((POINTER)prod, 0, sizeof (prod)); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bgmodexp.c b/usr/src/lib/libresolv2/common/dnssafe/bgmodexp.c deleted file mode 100644 index 9ae08ec962..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bgmodexp.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "surrendr.h" -#include "port_after.h" - -/* BigModExp (a, b, c, d, n): a = b**c (mod d) - Assumes a, b, c, d of length n. - Returns 0, AE_CANCEL. - */ -int BigModExp (a, b, c, d, n, surrenderContext) -UINT2 *a, *b, *c, *d; -unsigned int n; -A_SURRENDER_CTX *surrenderContext; -{ - struct BigModExpFrame { - UINT2 dInv[MAX_RSA_MODULUS_WORDS + 2], result[MAX_RSA_MODULUS_WORDS], - tab[16][MAX_RSA_MODULUS_WORDS]; - } *frame = (struct BigModExpFrame *)NULL_PTR; -#if !USE_ALLOCED_FRAME - struct BigModExpFrame stackFrame; -#endif - int i, didAMultiply, status; - unsigned int cLen, w, setup[64], power, mask; - - /* Initialize. - */ - do { -#if USE_ALLOCED_FRAME - if ((frame = (struct BigModExpFrame *)T_malloc (sizeof (*frame))) - == (struct BigModExpFrame *)NULL_PTR) { - status = AE_ALLOC; - break; - } -#else - /* Just use the buffers allocated on the stack. */ - frame = &stackFrame; -#endif - - /* precompute inverse of d to enable express mod-outs */ - BigInv (frame->dInv, d, n); - if ((status = CheckSurrender (surrenderContext)) != 0) - break; - - /* precompute small (size 2**w) table of powers of b */ - cLen = BigLen (c, n); - if (cLen < 4) - w = 1; - else if (cLen < 16) - w = 2; - else if (cLen < 64) - w = 3; - else - w = 4; - - /* zeroth power is one */ - BigConst (frame->tab[0], 1, n); - - /* first power is b */ - BigCopy (frame->tab[1], b, n); - setup[0] = 1; - setup[1] = 1; - for (i = 2; i < 64; i++) - setup[i] = 0; - - /* Loop over elements of exponent c in appropriate radix. - */ - power = 0; - didAMultiply = 0; - mask = 1 << ((cLen) % 16); - for (i = cLen; i >= 0; i--) { - if (didAMultiply) { - BigModSqx (frame->result, frame->result, d, frame->dInv, n); - if ((status = CheckSurrender (surrenderContext)) != 0) - break; - } - - power = power << 1; - if (setup[power] == 0) { - BigModSqx (frame->tab[power], frame->tab[power/2], d, frame->dInv, n); - if ((status = CheckSurrender (surrenderContext)) != 0) - break; - setup[power] = 1; - } - if (c[i/16] & mask) - power = power + 1; - if (mask == 1) - mask = 0x8000; - else - mask = (mask >> 1) & 0x7FFF; - if (setup[power] == 0) { - BigModMpyx - (frame->tab[power], frame->tab[power-1], b, d, frame->dInv, n); - if ((status = CheckSurrender (surrenderContext)) != 0) - break; - setup[power] = 1; - } - if ((i == 0) || (power >= (unsigned int)(1 << (w-1)))) { - if (didAMultiply) { - BigModMpyx - (frame->result, frame->result, frame->tab[power], d, frame->dInv, - n); - if ((status = CheckSurrender (surrenderContext)) != 0) - break; - } - else - BigCopy (frame->result, frame->tab[power], n); - - power = 0; - didAMultiply = 1; - } - } - if (status) - break; - - BigCopy (a, frame->result, n); - } while (0); - - if (frame != (struct BigModExpFrame *)NULL_PTR) { - T_memset ((POINTER)frame, 0, sizeof (*frame)); -#if USE_ALLOCED_FRAME - T_free ((POINTER)frame); -#endif - } - return (status); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bgpegcd.c b/usr/src/lib/libresolv2/common/dnssafe/bgpegcd.c deleted file mode 100644 index ade4d386b6..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bgpegcd.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* BigPegcd - input - u, v bignums - k int size of u, v regs - restriction u, v positive - output - u3=GCD (u, v) (pos) - u1=inv (u)modv (pos) - u2=inv (v)modu (pos) - if GCD (u, v)!=1 then u1, u2 st - u3=u * u1mod (v) & u3=v * u2mod (u) - (see KNUTH vol 2) - */ -void BigPegcd (u3, u1, u2, u, v, k) -UINT2 *u3, *u2, *u1, *u, *v; -unsigned int k; -{ - UINT2 v1[2 * MAX_RSA_PRIME_WORDS], v2[2 * MAX_RSA_PRIME_WORDS], - v3[2 * MAX_RSA_PRIME_WORDS], q[2 * MAX_RSA_PRIME_WORDS], - r[2 * MAX_RSA_PRIME_WORDS], t1[2 * MAX_RSA_PRIME_WORDS], - t2[2 * MAX_RSA_PRIME_WORDS], t3[2 * MAX_RSA_PRIME_WORDS]; - - BigConst (u1, 1, k); - BigConst (u2, 0, k); - BigCopy (u3, u, k); - BigConst (v1, 0, k); - BigConst (v2, 1, k); - BigCopy (v3, v, k); - - /* Begin calc. - */ - while (1) { - if (BigSign (v3, k) == 0) - break; - BigPdiv (q, r, u3, v3, k, k); - BigPmpyl (t1, v1, q, k); - BigPmpyl (t2, v2, q, k); - BigPmpyl (t3, v3, q, k); - BigSub (t1, u1, t1, k); - BigSub (t2, u2, t2, k); - BigSub (t3, u3, t3, k); - - BigCopy (u1, v1, k); - BigCopy (u2, v2, k); - BigCopy (u3, v3, k); - BigCopy (v1, t1, k); - BigCopy (v2, t2, k); - BigCopy (v3, t3, k); - } - - if (BigSign (u1, k) == -1) - /* make positive */ - BigAdd (u1, u1, v, k); - - if (BigSign (u2, k) == -1) - /* make positive */ - BigAdd (u2, u2, u, k); - - T_memset ((POINTER)v1, 0, sizeof (v1)); - T_memset ((POINTER)v2, 0, sizeof (v2)); - T_memset ((POINTER)v3, 0, sizeof (v3)); - T_memset ((POINTER)q, 0, sizeof (q)); - T_memset ((POINTER)r, 0, sizeof (r)); - T_memset ((POINTER)t1, 0, sizeof (t1)); - T_memset ((POINTER)t2, 0, sizeof (t2)); - T_memset ((POINTER)t3, 0, sizeof (t3)); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/big2exp.c b/usr/src/lib/libresolv2/common/dnssafe/big2exp.c deleted file mode 100644 index b0422779d6..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/big2exp.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* Big2Exp (a, v, n) -- a = 2**v, where v is nonnegative int. - Sets a to be 2**v. - */ -void Big2Exp (a, v, n) -UINT2 *a; -unsigned v; -unsigned int n; -{ - register unsigned int i; - - for (i = 0; i < n; i++) - a[i] = 0; - a[v/16] = 1 << (v % 16); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigabs.c b/usr/src/lib/libresolv2/common/dnssafe/bigabs.c deleted file mode 100644 index f6a105988d..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigabs.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* BigAbs (a, b, n) -- a = ABS (b). - */ -void BigAbs (a, b, n) -UINT2 *a, *b; -unsigned int n; -{ - if (BigSign (b, n) >= 0) - BigCopy (a, b, n); - else - BigNeg (a, b, n); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigacc.c b/usr/src/lib/libresolv2/common/dnssafe/bigacc.c deleted file mode 100644 index 06d68ab680..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigacc.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1987, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* Returns carry: vector a = b * vector c. - */ -UINT2 BigAcc (a, b, c, n) -UINT2 *a; -unsigned int b; -UINT2 *c; -unsigned int n; -{ - UINT4 bTemp, result = (UINT4)0; - register unsigned int i; - - if (!b) - return (0); - - bTemp = b; - for (i = 0; i < n; i++) { - result += bTemp * ((UINT4) c[i]); - result += ((UINT4) a[i]); - a[i] = (UINT2) result; - result >>= 16; - } - return ((UINT2)result); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigarith.c b/usr/src/lib/libresolv2/common/dnssafe/bigarith.c deleted file mode 100644 index adc1b0b194..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigarith.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1987, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -void BigZero (a, n) -UINT2 *a; -unsigned int n; -{ - register unsigned int i; - - for (i = 0; i < n; i++) - a[i] = 0; -} - -void BigAdd (a, b, c, n) -UINT2 *a, *b, *c; -unsigned int n; -{ - UINT4 result = (UINT4)0; - register unsigned int i; - - for (i = 0; i < n; i++) { - result += (UINT4) b[i]; - result += (UINT4) c[i]; - a[i] = (UINT2) result; - result >>= 16; - } -} - -void BigSub (a, b, c, n) -UINT2 *a, *b, *c; -unsigned int n; -{ - UINT4 result = (UINT4)1; /* carry bit for negation of c */ - register unsigned int i; - - for (i = 0; i < n; i++) { - result += (UINT4) b[i]; - result += (((UINT4) ~c[i]) & 0x0000FFFFL); - a[i] = (UINT2)result; - result >>= 16; - } -} - -void BigNeg (a, b, n) -UINT2 *a, *b; -unsigned int n; -{ - register unsigned int i; - unsigned int carry = 1; - - for (i = 0; i < n-1; i++) { - a[i] = ~b[i] + carry; - if (a[i]) - carry = 0; - } - - a[i] = ~b[i] + carry; -} - -void BigInc (a, n) -UINT2 *a; -unsigned int n; -{ - register unsigned int i; - unsigned int carry = 1; /* carry to start */ - - for (i = 0; i < n-1 && carry; i++) { - a[i]++; - if (a[i]) - carry = 0; - } - - if (carry) - a[i]++; -} - -void BigDec (a, n) -UINT2 *a; -unsigned int n; -{ - register unsigned int i; - unsigned int borrow = 1; /* borrow to start */ - - for (i = 0; i < n-1 && borrow; i++) { - a[i]--; - if (a[i] != 0xFFFF) - borrow = 0; - } - - if (borrow) - a[i]--; -} - -int BigSign (a, n) -UINT2 *a; -unsigned int n; -{ - register int i; - - if (a[n-1] & 0x8000) - return (-1); - for (i = n-1; i >= 0; i--) - if (a[i]) - return (1); - return (0); -} - -void BigCopy (a, b, n) -UINT2 *a, *b; -unsigned int n; -{ - register unsigned int i; - - for (i = 0; i < n; i++) - a[i] = b[i]; -} - -/* Assumes a is nonnegative. - */ -unsigned int BigLenw (a, n) -UINT2 *a; -unsigned int n; -{ - register int i; - - for (i = n-1; i >= 0; i--) - if (a[i]) - return (i+1); - return (0); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigcmp.c b/usr/src/lib/libresolv2/common/dnssafe/bigcmp.c deleted file mode 100644 index f4df4281f8..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigcmp.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* Comparison operator. - BigCmp (a, b, n) -- returns sign of a-b. - */ -int BigCmp (a, b, n) -UINT2 *a, *b; -unsigned int n; -{ - register int i; - int aSign = BigSign (a, n), bSign = BigSign (b, n); - - if (aSign > bSign) - return (1); - if (aSign < bSign) - return (-1); - - for (i = n-1; i >= 0 && a[i] == b[i]; i--); - - if (i == -1) - return (0); - if (a[i] > b[i]) - return (1); - return (-1); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigconst.c b/usr/src/lib/libresolv2/common/dnssafe/bigconst.c deleted file mode 100644 index e4754cb60d..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigconst.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* BigConst (a, v, n) -- a = v, where v is an int. Initialize bignum a to - value v. - */ -void BigConst (a, v, n) -UINT2 *a; -unsigned int v; -unsigned int n; -{ - UINT2 signWord = (((UINT2)v & 0x8000) ? ~0 : 0); - register unsigned int i; - - a[0] = (UINT2)v; - for (i = 1; i < n; i++) - a[i] = signWord; -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/biginv.c b/usr/src/lib/libresolv2/common/dnssafe/biginv.c deleted file mode 100644 index 92fee05ebf..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/biginv.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -static unsigned int Log2 PROTO_LIST ((unsigned int)); - -/* BigInv (a, b, n) -- compute a as an "inverse" to b, suitable for - modding out integers which are < b**2. - -- assumes a has n+2 words, b has n words. - -- assumes b is a positive integer. - */ -void BigInv (a, b, n) -UINT2 *a, *b; -unsigned int n; -{ - UINT2 p[2 * (MAX_RSA_MODULUS_WORDS + 2)], - q[2 * (MAX_RSA_MODULUS_WORDS + 3)], t1[MAX_RSA_MODULUS_WORDS + 3]; - register int i; - unsigned int bl, u, uw, sw; - - /* Do initializations. - */ - /* 2** (bl-1) <= b < 2 ** bl */ - bl = BigLen (b, n); - u = BigU (2 * bl); - - /* uw and sw are in words */ - uw = u/16; - sw = (bl - 2) / 16; - - /* since a = floor ((2**u)/b), 2**(u-bl) < a <= 2**(u-bl+1) */ - - /* Initialize a to 1+2**(u-bl) -- we will converge from below. - */ - Big2Exp (a, u - bl, n + 2); - BigInc (a, n + 2); - - /* Copy b to local register. - */ - BigZero (t1, n + 3); - BigCopy (t1, b, n); - - /* Convergence is quadratic, so iterate log (len (a)) times. - */ - for (i = 1 + Log2 (u - bl + 1); i > 0; i--) { - /* use fast squaring routine to compute p = a**2 - 2**(2 * (u-bl)) < p <= 2**(2 * (u-bl+1)) */ - BigPsq (p, a, n + 2); - - /* compute q = b * floor (p/ (2**s)) - 2**(2 * (u-bl)-s+bl-1) <= q <= 2**(2 * (u-bl+1)-s+bl - 2**(2 * u-bl-s-1) <= q <= 2**(2 * u-bl-s+2) */ - BigPmpy (q, t1, &p[sw], n + 3); - - /* double a - 2**(u-bl+1) < a <= 2**(u-bl+2) */ - BigAdd (a, a, a, n + 2); - /* a = a - floor (q/(2**(u-s))) - 2**(u-bl) < a <= 2**(u-bl+1) + epsilon */ - BigSub (a, a, &q[uw-sw], n + 2); - } - - /* now we are guaranteed that a is not too small */ - BigInc (a, n + 2); - - while (1) { - BigPmpy (p, a, t1, n + 2); - /* makes comparison to 2**u easier */ - BigDec (p, 2 * (n + 2)); - - /* a is desired result */ - if (BigLen (p, 2 * (n + 2)) <= u) - break; - - /* a was too big, reduce and try again */ - BigDec (a, n + 2); - } - - T_memset ((POINTER)p, 0, sizeof (p)); - T_memset ((POINTER)q, 0, sizeof (q)); - T_memset ((POINTER)t1, 0, sizeof (t1)); -} - -/* Log2 (x) -- ceiling of log base 2 of x > 0. Auxiliary function. - */ -static unsigned int Log2 (x) -unsigned int x; -{ - unsigned int i; - - x = x - 1; - /* now Log2 is equal to len in bits of x */ - for (i = 0; x > 0; i++, x >>= 1); - - return (i); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/biglen.c b/usr/src/lib/libresolv2/common/dnssafe/biglen.c deleted file mode 100644 index 8f5ffb0a32..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/biglen.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -unsigned int BigLen (a, n) -UINT2 *a; -unsigned int n; -{ - UINT2 signWord = ((a[n-1] & 0x8000) ? ~0 : 0); - int i, j; - unsigned int k; - - for (i = n-1; i >= 0 && a[i] == signWord; i--); - if (i == -1) - return (1); /* len of 0 or -1 */ - - for (j = 16, k = 0x8000; - j >= 0 && 0 == (k & (signWord ^ a[i])); - j--, k >>= 1); - return (16 * i + j); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigmath.h b/usr/src/lib/libresolv2/common/dnssafe/bigmath.h deleted file mode 100644 index 1675046bc7..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigmath.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1992, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _BIGMATH_H_ -#define _BIGMATH_H_ 1 - -#include "algae.h" -#include "bigmaxes.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void Big2Exp PROTO_LIST ((UINT2 *, unsigned int, unsigned int)); -void BigAbs PROTO_LIST ((UINT2 *, UINT2 *, unsigned int)); -UINT2 BigAcc PROTO_LIST ((UINT2 *, unsigned int, UINT2 *, unsigned int)); -void BigZero PROTO_LIST ((UINT2 *, unsigned int)); -void BigAdd PROTO_LIST ((UINT2 *, UINT2 *, UINT2 *, unsigned int)); -void BigSub PROTO_LIST ((UINT2 *, UINT2 *, UINT2 *, unsigned int)); -void BigNeg PROTO_LIST ((UINT2 *, UINT2 *, unsigned int)); -void BigInc PROTO_LIST ((UINT2 *, unsigned int)); -void BigDec PROTO_LIST ((UINT2 *, unsigned int)); -int BigSign PROTO_LIST ((UINT2 *, unsigned int)); -void BigCopy PROTO_LIST ((UINT2 *, UINT2 *, unsigned int)); -unsigned int BigLenw PROTO_LIST ((UINT2 *, unsigned int)); -void BigClrbit PROTO_LIST ((UINT2 *, unsigned int)); -void BigSetbit PROTO_LIST ((UINT2 *, unsigned int)); -int BigCmp PROTO_LIST ((UINT2 *, UINT2 *, unsigned int)); -void BigConst PROTO_LIST ((UINT2 *, unsigned int, unsigned int)); -void BigInv PROTO_LIST ((UINT2 *, UINT2 *, unsigned int)); -unsigned int BigLen PROTO_LIST ((UINT2 *, unsigned int)); -void BigModMpyx PROTO_LIST - ((UINT2 *, UINT2 *, UINT2 *, UINT2 *, UINT2 *, unsigned int)); -void BigModSqx PROTO_LIST - ((UINT2 *, UINT2 *, UINT2 *, UINT2 *, unsigned int)); -int BigModExp PROTO_LIST - ((UINT2 *, UINT2 *, UINT2 *, UINT2 *, unsigned int, A_SURRENDER_CTX *)); -void BigModx PROTO_LIST - ((UINT2 *, UINT2 *, UINT2 *, UINT2 *, unsigned int)); -void BigMpy PROTO_LIST ((UINT2 *, UINT2 *, UINT2 *, unsigned int)); -void BigPdiv PROTO_LIST - ((UINT2 *, UINT2 *, UINT2 *, UINT2 *, unsigned int , unsigned int)); -void BigPegcd PROTO_LIST - ((UINT2 *, UINT2 *, UINT2 *, UINT2 *, UINT2 *, unsigned int)); -void BigPmpy PROTO_LIST ((UINT2 *, UINT2 *, UINT2 *, unsigned int)); -void BigPmpyh PROTO_LIST - ((UINT2 *, UINT2 *, UINT2 *, unsigned int, unsigned int)); -void BigPmpyl PROTO_LIST ((UINT2 *, UINT2 *, UINT2 *, unsigned int)); -void BigPsq PROTO_LIST ((UINT2 *, UINT2 *, unsigned int)); -void BigQrx PROTO_LIST - ((UINT2 *, UINT2 *, UINT2 *, UINT2 *, UINT2 *, unsigned int)); -UINT2 BigSmod PROTO_LIST ((UINT2 *, unsigned int, unsigned int)); -int BigToCanonical PROTO_LIST - ((unsigned char *, unsigned int, UINT2 *, unsigned int)); -unsigned int BigU PROTO_LIST ((unsigned int)); -int BigUnexp PROTO_LIST - ((UINT2 *, UINT2 *, UINT2 *, UINT2 *, UINT2 *, UINT2 *, UINT2 *, - unsigned int, A_SURRENDER_CTX *)); -int CanonicalToBig PROTO_LIST - ((UINT2 *, unsigned int, const unsigned char *, unsigned int)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigmaxes.h b/usr/src/lib/libresolv2/common/dnssafe/bigmaxes.h deleted file mode 100644 index 4f803e6025..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigmaxes.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _BIGMAXES_H_ -#define _BIGMAXES_H_ 1 - -#ifdef __cplusplus -extern "C" { -#endif - -#define MAX_RSA_MODULUS_BITS 4096 - -#define BITS_TO_LEN(modulusBits) (((modulusBits) + 7) / 8) -#define RSA_PRIME_BITS(modulusBits) (((modulusBits) + 1) / 2) -#define RSA_PRIME_LEN(modulusBits) ((RSA_PRIME_BITS (modulusBits) + 7) / 8) -#define BITS_TO_WORDS(bits) ((bits >> 4) + 1) -#define LEN_TO_WORDS(len) ((len >> 1) + 1) - -/* MAX_RSA_PRIME_BITS -- length in bits of the maximum allowed RSA prime - MAX_RSA_MODULUS_LEN -- length in bytes of the maximum allowed RSA modulus, - in canonical format (no sign bit) - MAX_RSA_PRIME_LEN -- length in bytes of the maximum allowed RSA prime, in - canonical format (no sign bit) - */ -#define MAX_RSA_PRIME_BITS RSA_PRIME_BITS (MAX_RSA_MODULUS_BITS) -#define MAX_RSA_PRIME_LEN RSA_PRIME_LEN (MAX_RSA_MODULUS_BITS) -#define MAX_RSA_MODULUS_LEN BITS_TO_LEN (MAX_RSA_MODULUS_BITS) - -/* MAX_RSA_MODULUS_WORDS -- length in 16-bit words of the maximum allowed RSA - modulus, in bignum format (including sign bit) - MAX_RSA_PRIME_WORDS -- length in 16-bit words of the maximum allowed RSA - prime, in bignum format (including sign bit) - */ - -#define MAX_RSA_MODULUS_WORDS BITS_TO_WORDS (MAX_RSA_MODULUS_BITS) -#define MAX_RSA_PRIME_WORDS BITS_TO_WORDS (MAX_RSA_PRIME_BITS) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigmodx.c b/usr/src/lib/libresolv2/common/dnssafe/bigmodx.c deleted file mode 100644 index a58f6cdaab..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigmodx.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* BigModx (a, b, c, cInv, n) -- compute a as (b mod c). - -- assumes a and c of length n, cInv of length n + 2, b of length 2n. - -- assumes cInv computed with BigInv, and that b < c**2. - */ -void BigModx (a, b, c, cInv, n) -UINT2 *a, *b, *c, *cInv; -unsigned int n; -{ - UINT2 q[MAX_RSA_MODULUS_WORDS]; - - BigQrx (q, a, b, c, cInv, n); - - T_memset ((POINTER)q, 0, sizeof (q)); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigmpy.c b/usr/src/lib/libresolv2/common/dnssafe/bigmpy.c deleted file mode 100644 index 7ef2d16a85..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigmpy.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* BigMpy (a, b, c, n) -- a = b * c - -- assumes b and c have n words, a has 2*n words - -- inputs may be positive or negative. - */ -void BigMpy (a, b, c, n) -UINT2 *a, *b, *c; -unsigned int n; -{ - UINT2 prod[2 * MAX_RSA_PRIME_WORDS], absb[MAX_RSA_PRIME_WORDS], - absc[MAX_RSA_PRIME_WORDS]; - int bSign = BigSign (b, n), cSign = BigSign (c, n); - - BigAbs (absb, b, n); - BigAbs (absc, c, n); - BigPmpy (prod, absb, absc, n); - - if (bSign * cSign >= 0) - BigCopy (a, prod, 2 * n); - else - BigNeg (a, prod, 2 * n); - - T_memset ((POINTER)prod, 0, sizeof (prod)); - T_memset ((POINTER)absb, 0, sizeof (absb)); - T_memset ((POINTER)absc, 0, sizeof (absc)); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigpdiv.c b/usr/src/lib/libresolv2/common/dnssafe/bigpdiv.c deleted file mode 100644 index 0609f469ef..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigpdiv.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* BigPdiv POSITIVE DIVIDE - uu=vv * qi+ri - uu in reg of ll cells - vv in reg of kk cells - qi assumed to be ll cells - ri assumed to be kk cells - restriction uu>=0, vv>0 - - input uu in reg of ll cells - input vv in reg of kk cells - output qi assumed to be ll cells - output ri assumed to be kk cells - restriction uu>=0, vv>0 - uu=vv * qi+ri - */ -#define UJN (u[(j+n)/2] & mk[(j+n)%2]) -#define VN (v[n/2] & mk[n%2]) -#define UT (u[t/2] & mk[t%2]) -void BigPdiv (qi, ri, uu, vv, ll, kk) -UINT2 *qi, *ri, *uu, *vv; -unsigned int ll, kk; -{ - UINT2 u[2 * MAX_RSA_PRIME_WORDS + 2], us[2 * MAX_RSA_PRIME_WORDS + 2], - v[2 * MAX_RSA_PRIME_WORDS + 2], vs[2 * MAX_RSA_PRIME_WORDS + 2], - q[2 * MAX_RSA_PRIME_WORDS + 2], r[2 * MAX_RSA_PRIME_WORDS + 2], - t1[2 * MAX_RSA_PRIME_WORDS + 2], t2[2 * MAX_RSA_PRIME_WORDS + 2], - t3[2 * MAX_RSA_PRIME_WORDS + 2], mk[2]; - int j, l, n, m, t, x; - unsigned int a, b, c, d, e, vh, qq; - - if (ll >= kk) - l = ll + 2; - else - l = kk + 2; - - mk[0] = 0x00FF; - mk[1] = 0xFF00; - b = 0x0100; - - BigConst (u, 0, l); - BigConst (v, 0, l); - BigCopy (u, uu, ll); - BigCopy (us, u, l); - BigCopy (v, vv, kk); - BigCopy (vs, v, l); - - /* zero q */ - BigConst (q, 0, l); - - /* Calculate len of v=n. - */ - for (n = (2 * l) - 1; n >= 0; n--) { - if (VN == 0) - continue; - break; - } - - /* Normalize. - */ - a = VN; - if (n % 2 == 1) - a = a >> 8; - d = b / (a+1); - BigConst (t1, d, l); - BigPmpyl (t2, t1, v, l); - BigCopy (v, t2, l); - - /* vh=high order digit of normalized v */ - vh = VN; - if (n % 2 == 1) - vh = vh >> 8; - BigPmpyl (t2, t1, u, l); - BigCopy (u, t2, l); - - /* Calculate len of u=t. - */ - for (t = (2 * l)-1; t >= 0; t--) { - if (UT == 0) - continue; - break; - } - - /* calc t = n + m */ - m = t - n; - - /* Divide u by v. - */ - for (j = m + 1 + n; j > n; j--) { - if (j % 2 == 1) - c = u[j / 2]; - else { - a = u[j/2]; - a = a << 8; - e = u[(j - 1) / 2]; - e = e >> 8; - c = a + e; - } - a = c >> 8; - if (vh == a) - qq = b - 1; - else - qq = c / vh; - - BigConst (t1, qq, l); - BigPmpyl (t2, v, t1, l); - Big2Exp (t3, (j - 1 - n) * 8, l); - BigPmpyl (t1, t3, t2, l); - BigSub (t2, u, t1, l); - - /* Adjust q. - */ - for (x = 0; ; qq --, x ++) { - if (BigSign (t2, l) != -1) - break; - BigPmpyl (t1, t3, v, l); - BigAdd (t2, t2, t1, l); - } - - BigCopy (u, t2, l); - BigConst (t3, qq, l); - Big2Exp (t2, 8, l); - BigPmpyl (t1, q, t2, l); - BigAdd (q, t3, t1, l); - } - - /* Check result. - */ - - BigPmpyl (t1, vs, q, l); - /* t2 has remainder */ - BigSub (t2, us, t1, l); - - BigSub (t3, vs, t2, l); - - /* transfer results to input registers */ - BigCopy (qi, q, ll); - BigCopy (ri, t2, kk); - - T_memset ((POINTER)u, 0, sizeof (u)); - T_memset ((POINTER)us, 0, sizeof (us)); - T_memset ((POINTER)v, 0, sizeof (v)); - T_memset ((POINTER)vs, 0, sizeof (vs)); - T_memset ((POINTER)q, 0, sizeof (q)); - T_memset ((POINTER)r, 0, sizeof (r)); - T_memset ((POINTER)t1, 0, sizeof (t1)); - T_memset ((POINTER)t2, 0, sizeof (t2)); - T_memset ((POINTER)t3, 0, sizeof (t3)); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigpmpy.c b/usr/src/lib/libresolv2/common/dnssafe/bigpmpy.c deleted file mode 100644 index 5baa3e5884..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigpmpy.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1987, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* a = b * c. - */ -void BigPmpy (a, b, c, n) -UINT2 *a, *b, *c; -unsigned int n; -{ - register unsigned int i; - unsigned int cLen; - - BigZero (a, 2*n); - cLen = BigLenw (c, n); - for (i = 0; i < n; i++) - a[cLen+i] = BigAcc (&a[i], (unsigned int)b[i], c, cLen); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigpmpyh.c b/usr/src/lib/libresolv2/common/dnssafe/bigpmpyh.c deleted file mode 100644 index 6e94d3cf11..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigpmpyh.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1987, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* Returns high order t bytes of result. - */ -void BigPmpyh (a, b, c, t, n) -UINT2 *a, *b, *c; -unsigned int t, n; -{ - register unsigned int i; - unsigned int iStart, cLen, j; - - BigZero (a, 2*n); - cLen = BigLenw (c, n); - iStart = (t >= n-1) ? t - (n-1) : 0; - - for (i = iStart; i < n; i++) { - j = (t >= i) ? t - i : 0; - a[cLen+i] = BigAcc - (&a[i+j], (unsigned int)b[i], &c[j], (cLen >= j) ? cLen-j : 0); - } -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigpmpyl.c b/usr/src/lib/libresolv2/common/dnssafe/bigpmpyl.c deleted file mode 100644 index b6bd3d7617..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigpmpyl.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1987, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* Single precision multiply, a is same len as b and c. - Returns low order n bytes of result. - */ -void BigPmpyl (a, b, c, n) -UINT2 *a, *b, *c; -unsigned int n; -{ - register unsigned int i; - unsigned int cLen; - - BigZero (a, n); - cLen = BigLenw (c, n); - for (i = 0; i < n; i++) { - if (cLen < n-i) - a[cLen+i] = BigAcc (&a[i], (unsigned int)b[i], c, cLen); - else - BigAcc (&a[i], (unsigned int)b[i], c, n-i); - } -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigpsq.c b/usr/src/lib/libresolv2/common/dnssafe/bigpsq.c deleted file mode 100644 index ee058e2c82..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigpsq.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1987, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* Similar to BigPmpy (a, b, b, n) but faster. - */ -void BigPsq (a, b, n) -UINT2 *a, *b; -unsigned int n; -{ - UINT4 result = (UINT4)0; - register unsigned int i; - unsigned int bLen; - - BigZero (a, 2*n); - bLen = BigLenw (b, n); - if (!bLen) - return; - - for (i = 0; i < bLen-1; i++) - a[bLen+i] = BigAcc (&a[2*i+1], (unsigned int)b[i], &b[i+1], bLen-i-1); - BigAdd (a, a, a, 2*n); - - /* add in trace b[i] * b[i] */ - for (i = 0; i < bLen; i++) { - result += ((UINT4)b[i]) * ((UINT4)b[i]); - result += (UINT4)a[2*i]; - a[2*i] = (UINT2)result; - result >>= 16; - result += (UINT4)a[2*i+1]; - a[2*i+1] = (UINT2)result; - result >>= 16; - } - a[2*i] = (UINT2)result; -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigqrx.c b/usr/src/lib/libresolv2/common/dnssafe/bigqrx.c deleted file mode 100644 index 7614783715..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigqrx.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - - -/* BigQrx (q, r, b, c, cInv, n) -- compute quotient and remainder fast. - -- computes q and r s.t. b = q * c + r with 0 <= r < c. - -- assumes b and c are positive integers. - -- assumes q, r, c have n words, cInv has n+2 words, b has 2*n words. - -- assumes cInv previously computed with BigInv. - */ -void BigQrx (q, r, b, c, cInv, n) -UINT2 *q, *r, *b, *c, *cInv; -unsigned int n; -{ - UINT2 qc[2 * (MAX_RSA_MODULUS_WORDS + 2)], /* current product of q and c */ - qsc[2 * (MAX_RSA_MODULUS_WORDS + 2)], /* temporary q scaled by 2**(u-s) */ - t1[2 * MAX_RSA_MODULUS_WORDS + 2]; - int uwsw3; - register unsigned int i; - unsigned int u, uw, cl, sw; - - /* 2**(cl-1) <= c < 2**cl - 2**(u-cl) <= cInv <= 2**(u-cl+1) */ - cl = BigLen (c, n); - - /* u is in bits, uw is in words */ - u = BigU (2 * cl); - uw = u/16; - - /* sw is in words, s is is bits */ - sw = (cl - 2) / 16; - - uwsw3 = uw - sw - 3; - - if (uwsw3 < 0) - uwsw3 = 0; - - /* Copy b to local register. - */ - BigZero (t1, 2 * n + 2); - BigCopy (t1, b, 2 * n); - - /* Compute qsc = cInv * floor (b/ (2**s)). - qsc an approximation to (b/c) * (2**(u-s)) - 2**((u-cl)+ (bl-1-s)) <= qsc 2**((u-cl+1)+ (bl-s)) - 2**(u-cl+bl-s-1) <= qsc <= 2 ** (u-cl+bl-s+1) - (Actually, we only compute a "high-order" approximation - to qsc, by using BigPmpyh.) - */ - BigPmpyh (qsc, cInv, &t1[sw], uwsw3, n + 2); - - /* Divide by 2**(u-s) to get initial estimate for quotient q - 2**(bl-cl-1) <= q <= 2**(bl-cl+1) (unless q = 0). - */ - for (i = 0; i < n; i++) - q[i] = qsc[i+ (uw - sw)]; - - /* compute qc = low-order part of q * c - 2 ** (bl - 2) <= qc <= 2 ** (bl + 1) */ - BigPmpyl (qc, q, c, n); - - /* subtract qc from b to get initial estimate for remainder r */ - BigSub (r, b, qc, n); - - /* Adjust to be exactly right by repeated subtraction. - */ - while (BigCmp (r, c, n) >= 0) { - BigSub (r, r, c, n); - BigInc (q, n); - } - - T_memset ((POINTER)qc, 0, sizeof (qc)); - T_memset ((POINTER)qsc, 0, sizeof (qsc)); - T_memset ((POINTER)t1, 0, sizeof (t1)); -} - - diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigsmod.c b/usr/src/lib/libresolv2/common/dnssafe/bigsmod.c deleted file mode 100644 index 8e44e84773..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigsmod.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1987, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -UINT2 BigSmod (a, v, n) -UINT2 *a; -unsigned int v; -unsigned int n; -{ - UINT4 r = (UINT4)0; - register int i; - unsigned int scale; - - scale = (unsigned int)((UINT4)65536 % (UINT4)v); - - for (i = n-1; i >= 0; i--) { - r = (r*scale) + (UINT4)a[i]; - r = r % (UINT4)v; - } - return ((UINT2)r); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigtocan.c b/usr/src/lib/libresolv2/common/dnssafe/bigtocan.c deleted file mode 100644 index c3722323ab..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigtocan.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "bigmath.h" -#include "port_after.h" - - -/* BigToCanonical () copies a word vector to a byte vector while REVERSING the - order of significance. The word vector is input LSWord first and the - byte vector is written out MSByte first. It also removes a leading zero - sign bit. (The byte vector must represent a nonnegative number.) - Returns 0, AE_DATA. - */ -int BigToCanonical (bytePointer, numBytes, wordPointer, wordCount) -unsigned char *bytePointer; -unsigned int numBytes; -UINT2 *wordPointer; -unsigned int wordCount; -{ - unsigned int copyCount; - - if (BigSign (wordPointer, wordCount) < 0 || - (BigLen (wordPointer, wordCount) + 7) / 8 > numBytes) - return (AE_DATA); - - /* start at end of byte vector */ - bytePointer += numBytes-1; - - /* copy as much as possible */ - copyCount = (wordCount < numBytes / 2) ? wordCount : numBytes / 2; - wordCount -= copyCount; - numBytes -= 2 * copyCount; - while (copyCount--) { - /* Copy two bytes.*/ - *bytePointer-- = (unsigned char)*wordPointer; - *bytePointer-- = (unsigned char)(*wordPointer >> 8); - wordPointer++; - } - - if (wordCount && numBytes & 1) { - /* The number of output bytes was odd. Copy one last byte */ - *bytePointer-- = (unsigned char)*wordPointer++; - wordCount--; - numBytes--; - } - - /* zero fill remainder of byte vector */ - while (numBytes--) - *bytePointer-- = 0; - - return (0); -} - - diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigu.c b/usr/src/lib/libresolv2/common/dnssafe/bigu.c deleted file mode 100644 index d5cc036706..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigu.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "port_after.h" - -/* BigU (t) -- returns length u where floor (2**u/b) is used as scaled version - of (1/b) when modding out modulo b, and where (positive) integers to be - reduced are < 2**t; i.e. they are at most t bits in length. - Result is (t+1) rounded up if necessary to next multiple of 16. -*/ -unsigned int BigU (t) -unsigned int t; -{ - return (16 * (((t+1) + 15)/16)); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/bigunexp.c b/usr/src/lib/libresolv2/common/dnssafe/bigunexp.c deleted file mode 100644 index 14b5302740..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bigunexp.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1986, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bigmath.h" -#include "surrendr.h" -#include "port_after.h" - -/* BigUnexp - decrypt ciphertext c into message m using Chinese remainder. - Assumes m, c of length 2*pSize, pp, qq, dp, dq and cr of length pSize. - Returns 0, AE_CANCEL. - */ -int BigUnexp (m, c, pp, qq, dp, dq, cr, pSize, surrenderContext) -UINT2 *m; /* output message size 2*pSize words */ -UINT2 *c; /* input `ciphertext' size 2*pSize */ -UINT2 *pp; /* first prime size pSize */ -UINT2 *qq; /* second prime; size pSize */ -UINT2 *dp; /* decryption exponent mod p size pSize */ -UINT2 *dq; /* decryption exponent mod q size pSize */ -UINT2 *cr; /* CRT coef (inverse of q mod p) cr has len pSize */ -unsigned int pSize; /* length of p in words */ -A_SURRENDER_CTX *surrenderContext; -{ - struct BigUnexpFrame { - UINT2 t1[2 * MAX_RSA_PRIME_WORDS], t2[2 * MAX_RSA_PRIME_WORDS], - t3[2 * MAX_RSA_PRIME_WORDS], u1[2 * MAX_RSA_PRIME_WORDS], - u2[2 * MAX_RSA_PRIME_WORDS], u3[2 * MAX_RSA_PRIME_WORDS]; - } *frame = (struct BigUnexpFrame *)NULL_PTR; -#if !USE_ALLOCED_FRAME - struct BigUnexpFrame stackFrame; -#endif - int status; - - do { -#if USE_ALLOCED_FRAME - if ((frame = (struct BigUnexpFrame *)T_malloc (sizeof (*frame))) - == (struct BigUnexpFrame *)NULL_PTR) { - status = AE_ALLOC; - break; - } -#else - /* Just use the buffers allocated on the stack. */ - frame = &stackFrame; -#endif - - BigConst (frame->t1, 0, 2 * pSize); - BigConst (frame->t2, 0, 2 * pSize); - - /* u2=c mod p */ - BigPdiv (frame->u1, frame->u2, c, pp, 2 * pSize, pSize); - if ((status = CheckSurrender (surrenderContext)) != 0) - break; - - /* t1=c**dp modP */ - if ((status = BigModExp - (frame->t1, frame->u2, dp, pp, pSize, surrenderContext)) != 0) - break; - - /* u3=CmodQ */ - BigPdiv (frame->u2, frame->u3, c, qq, 2 * pSize, pSize); - if ((status = CheckSurrender (surrenderContext)) != 0) - break; - - /* t2=c**DQmodQ */ - if ((status = BigModExp - (frame->t2, frame->u3, dq, qq, pSize, surrenderContext)) != 0) - break; - - /* CRT. - */ - BigSub (frame->u1, frame->t1, frame->t2, pSize); - - while (-1 == BigSign (frame->u1, pSize)) - BigAdd (frame->u1, frame->u1, pp, pSize); - - BigMpy (frame->u2, frame->u1, cr, pSize); - if ((status = CheckSurrender (surrenderContext)) != 0) - break; - BigPdiv (frame->u3, frame->u1, frame->u2, pp, 2 * pSize, pSize); - if ((status = CheckSurrender (surrenderContext)) != 0) - break; - BigMpy (m, frame->u1, qq, pSize); - - BigAdd (m, m, frame->t2, 2 * pSize); - } while (0); - - if (frame != (struct BigUnexpFrame *)NULL_PTR) { - T_memset ((POINTER)frame, 0, sizeof (*frame)); -#if USE_ALLOCED_FRAME - T_free ((POINTER)frame); -#endif - } - return (status); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/binfocsh.c b/usr/src/lib/libresolv2/common/dnssafe/binfocsh.c deleted file mode 100644 index ffc04dd2f2..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/binfocsh.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "binfocsh.h" -#include "port_after.h" - -void B_InfoCacheConstructor (infoCache) -B_InfoCache *infoCache; -{ - /* Construct immediate base class. */ - B_MemoryPoolConstructor (&infoCache->memoryPool); - - T_memset ((POINTER)&infoCache->z, 0, sizeof (infoCache->z)); -} - -/* Returns 0, BE_ALLOC. - */ -int B_InfoCacheAddInfo (infoCache, infoType, info) -B_InfoCache *infoCache; -POINTER infoType; -POINTER info; -{ - int status; - - if ((status = B_MemoryPoolRealloc - (&infoCache->memoryPool, (POINTER *)&infoCache->z.infos, - (infoCache->z.infoCount + 1) * sizeof (infoCache->z.infos[0]))) != 0) - return (status); - - infoCache->z.infos[infoCache->z.infoCount].infoType = infoType; - infoCache->z.infos[infoCache->z.infoCount].info = info; - infoCache->z.infoCount++; - - return (0); -} - -/* Set info to the entry in the cache for the given infoType. - Returns 0, or BE_NOT_SUPPORTED if infoType is not in the cache. - */ -int B_InfoCacheFindInfo (infoCache, info, infoType) -B_InfoCache *infoCache; -POINTER *info; -POINTER infoType; -{ - unsigned int i; - - for (i = 0; i < infoCache->z.infoCount; ++i) { - if (infoCache->z.infos[i].infoType == infoType) { - /* The info has already been constructed. */ - *info = infoCache->z.infos[i].info; - return (0); - } - } - - return (BE_NOT_SUPPORTED); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/binfocsh.h b/usr/src/lib/libresolv2/common/dnssafe/binfocsh.h deleted file mode 100644 index 8600e4bcb1..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/binfocsh.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _BINFOCSH_H_ -#define _BINFOCSH_H_ 1 - -#include "bmempool.h" - -typedef struct B_InfoCache { - B_MemoryPool memoryPool; /* inherited */ - struct { - unsigned int infoCount; - struct { - POINTER infoType; - POINTER info; - } *infos; - /* POINTER reserved; */ - } z; /* z gives the members that are zeroized by the constructor */ -} B_InfoCache; - -void B_InfoCacheConstructor PROTO_LIST ((B_InfoCache *)); -#define B_INFO_CACHE_Destructor(infoCache) \ - B_MemoryPoolDestructor (&(infoCache)->memoryPool) - -int B_InfoCacheAddInfo PROTO_LIST ((B_InfoCache *, POINTER, POINTER)); -int B_InfoCacheFindInfo PROTO_LIST ((B_InfoCache *, POINTER *, POINTER)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/bkey.c b/usr/src/lib/libresolv2/common/dnssafe/bkey.c deleted file mode 100644 index be9b547452..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bkey.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "kinfotyp.h" -#include "kiitem.h" -#include "port_after.h" - -int B_KeySetInfo (key, keyInfoType, info) -B_Key *key; -B_KeyInfoType *keyInfoType; -POINTER info; -{ - if (key == (B_Key *)NULL_PTR) - return (BE_KEY_OBJ); - - if (key->infoCache.z.infoCount > 0) - return (BE_KEY_ALREADY_SET); - - /* This will cache the encoding. */ - return ((*keyInfoType->AddInfo) (key, info)); -} - -int B_KeyGetInfo (key, info, keyInfoType) -B_Key *key; -POINTER *info; -B_KeyInfoType *keyInfoType; -{ - int status; - - if (key == (B_Key *)NULL_PTR) - return (BE_KEY_OBJ); - - if (key->infoCache.z.infoCount == 0) - return (BE_KEY_NOT_SET); - - /* First check if the encoding is already in the encoding cache. - */ - if (B_InfoCacheFindInfo (&key->infoCache, info, (POINTER)keyInfoType) == 0) - return (0); - - /* Info is not in the cache, go ahead and encode. - */ - if ((status = (*keyInfoType->MakeInfo) (info, key)) != 0) - return (status); - - return (B_InfoCacheAddInfo (&key->infoCache, (POINTER)keyInfoType, *info)); -} - -/* Create an ITEM out of the data and len and cache it as KITItem. - The data is already alloced in the info cache. - Returns 0, BE_ALLOC. - */ -int B_KeyAddItemInfo (key, data, len) -B_Key *key; -unsigned char *data; -unsigned int len; -{ - ITEM *newInfo; - int status; - - if ((status = B_MemoryPoolAlloc - (&key->infoCache.memoryPool, (POINTER *)&newInfo, sizeof (*newInfo))) - != 0) - return (status); - - newInfo->data = data; - newInfo->len = len; - - return (B_InfoCacheAddInfo - (&key->infoCache, (POINTER)&KITItem, (POINTER)newInfo)); -} - -/* Return the number of bits in the canonical, positive integer. - B_IntegerBits (0) = 0. - */ -unsigned int B_IntegerBits (integer, integerLen) -unsigned char *integer; -unsigned int integerLen; -{ - unsigned char mask, byte; - unsigned int bytes, bits; - - for (bytes = 0; bytes < integerLen && integer[bytes] == 0; bytes++); - if (bytes == integerLen) - return (0); - - /* Get byte to test and increment byte count for final calculation */ - byte = integer[bytes++]; - - /* Get number of bits in most significant byte */ - for (bits = 8, mask = 0x80; (byte & mask) == 0; bits--, mask >>= 1); - return (8 * (integerLen - bytes) + bits); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/bkey.h b/usr/src/lib/libresolv2/common/dnssafe/bkey.h deleted file mode 100644 index 0d9d761068..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bkey.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _BKEY_H_ -#define _BKEY_H_ 1 - -#include "binfocsh.h" - -typedef struct { - B_InfoCache infoCache; /* inherited */ - - /* For now we don't need to worry about a reserved field. - struct { - POINTER reserved; - } z; - */ -} B_Key; - -#define B_KEY_Constructor(key) (B_InfoCacheConstructor (&(key)->infoCache)) -#define B_KEY_Destructor(key) (B_INFO_CACHE_Destructor (&(key)->infoCache)) - -struct B_KeyInfoType; -int B_KeySetInfo PROTO_LIST ((B_Key *, struct B_KeyInfoType *, POINTER)); -int B_KeyGetInfo PROTO_LIST ((B_Key *, POINTER *, struct B_KeyInfoType *)); -int B_KeyAddItemInfo PROTO_LIST ((B_Key *, unsigned char *, unsigned int)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/bmempool.c b/usr/src/lib/libresolv2/common/dnssafe/bmempool.c deleted file mode 100644 index e5d9ae28e0..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bmempool.c +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bmempool.h" -#include "port_after.h" - -#define ALLOCED_LIST_SLACK 10 - -void B_MemoryPoolConstructor (memoryPool) -B_MemoryPool *memoryPool; -{ - T_memset ((POINTER)&memoryPool->z, 0, sizeof (memoryPool->z)); -} - -void B_MemoryPoolDestructor (memoryPool) -B_MemoryPool *memoryPool; -{ - B_MemoryPoolReset (memoryPool); - T_free ((POINTER)memoryPool->z.allocedList); -} - -/* For each item on the alloced list, call the DeleteFuncion if - there is one, otherwise zerioze and free. - Leave the list itself allocated with all NULL entries. - */ -void B_MemoryPoolReset (memoryPool) -B_MemoryPool *memoryPool; -{ - B_ALLOCED_DATA *allocedData; - unsigned int i; - - for (i = memoryPool->z.allocedCount, - allocedData = memoryPool->z.allocedList; - i-- > 0; - ++allocedData) { - /* Only process this entry if the data is not NULL_PTR. - */ - if (allocedData->object != NULL_PTR) { - if (allocedData->DeleteFunction != NULL) - /* There is a destroy function, so call. */ - (*allocedData->DeleteFunction) (allocedData->object); - else { - T_memset (allocedData->object, 0, allocedData->size); - T_free (allocedData->object); - } - allocedData->object = NULL_PTR; - } - } - - memoryPool->z.allocedCount = 0; - /* Note that maxAllocedCount still indicates the size of the alloced list. */ -} - -/* On any error return, NULL_PTR is returned for the data. - Returns 0 if successful, or BE_ALLOC if cannot alloc the memory. - */ -int B_MemoryPoolAlloc (memoryPool, data, size) -B_MemoryPool *memoryPool; -POINTER *data; -unsigned int size; -{ - if ((*data = T_malloc (size)) == NULL_PTR) - return (BE_ALLOC); - return (B_MemoryPoolAdoptData (memoryPool, data, size)); -} - -/* Use alloc to allocate the newData of length size and T_memcpy data into it. - On any error return, NULL_PTR is returned for the newData. - Returns 0 if successful or BE_ALLOC if cannot alloc the memory. - */ -int B_MemoryPoolAllocAndCopy (memoryPool, newData, data, size) -B_MemoryPool *memoryPool; -POINTER *newData; -POINTER data; -unsigned int size; -{ - int status; - - if ((status = B_MemoryPoolAlloc (memoryPool, newData, size)) != 0) - return (status); - - T_memcpy (*newData, data, size); - return (0); -} - -/* Put the given data on the memory pool's alloced list. - The size of the alloced data buffer must be passed in so that it can - be zeroized when the object is reset (Pass in a size of zero if - the buffer does not need to be zeroized.) - The data is passed by reference, so that if there is an error, - the data is zeroized and freed, and the pointer to the data is set - to NULL_PTR. - This routine should be used with caution - it is meant be called - immediately after an alloc. - No check is made as to whether the data is already on the memory pool's - alloced list (which would be a problem since it will get freed twice). - Returns 0 if successful or BE_ALLOC if cannot expand the alloced list. - */ -int B_MemoryPoolAdoptData (memoryPool, data, size) -B_MemoryPool *memoryPool; -POINTER *data; -unsigned int size; -{ - int status; - - if ((status = B_MemoryPoolAdoptHelper(memoryPool, *data, size, NULL)) != 0) { - T_memset (*data, 0, size); - T_free (*data); - *data = NULL_PTR; - return (status); - } - - return (0); -} - -/* Put the given object on the memory pool's alloced list. - The size of the alloced object must be passed in so that it can - be zeroized when the object is reset (Pass in a size of zero if - the buffer does not need to be zeroized, especially if it - is an object and not a data buffer.) - The object is not passed by reference. If there is an error, - the calling routine should clean up the object, such as zeroizing - and freeing. - No check is made as to whether the object is already on the memory pool's - alloced list (which would be a problem since it will get freed twice). - Returns 0 if successful or BE_ALLOC if cannot expand the alloced list. - */ -int B_MemoryPoolAdoptHelper (memoryPool, object, size, DeleteFunction) -B_MemoryPool *memoryPool; -POINTER object; -unsigned int size; -B_MEMORY_POOL_DELETE_FUNCTION DeleteFunction; -{ - POINTER newList; - unsigned int newMaxCount; - - if (memoryPool->z.allocedCount + 1 > memoryPool->z.maxAllocedCount) { - /* Make extra room on the alloced list. - */ - newMaxCount = memoryPool->z.allocedCount + ALLOCED_LIST_SLACK; - if ((newList = T_malloc (newMaxCount * sizeof (B_ALLOCED_DATA))) - == NULL_PTR) - /* alloc errorm so caller should clean up the object it passed. */ - return (BE_ALLOC); - - /* move in new list and free old list */ - T_memcpy - (newList, (POINTER)memoryPool->z.allocedList, - memoryPool->z.allocedCount * sizeof (B_ALLOCED_DATA)); - T_free ((POINTER)memoryPool->z.allocedList); - memoryPool->z.allocedList = (B_ALLOCED_DATA *)newList; - memoryPool->z.maxAllocedCount = newMaxCount; - } - - /* Put object on alloced list and increment count. - */ - memoryPool->z.allocedList[memoryPool->z.allocedCount].object = object; - memoryPool->z.allocedList[memoryPool->z.allocedCount].size = size; - memoryPool->z.allocedList[memoryPool->z.allocedCount++].DeleteFunction = - DeleteFunction; - return (0); -} - -/* 'data' points to the pointer to realloc and also is used to - return the realloced memory. - If data points to NULL_PTR, behaves like B_MemoryPoolAlloc. - Find 'data' on the allocedList and realloc it to the given size, - replacing the entry on the alloced list with the new memory. - If it is not on the allocedList, the adopt the reallocated memory. - If the buffer must be moved during the realloc, the old buffer is not - zeroized (unless T_realloc does the zeroizing). - This assumes that the (POINTER *)data is not (POINTER *)NULL_PTR. - This assumes there is no DesroyFunction for this entry. That is, - you should not try to resize an object. - On any error return, NULL_PTR is returned for the data. - Returns 0 if successful or BE_ALLOC if cannot alloc the memory. - */ -int B_MemoryPoolRealloc (memoryPool, data, size) -B_MemoryPool *memoryPool; -POINTER *data; -unsigned int size; -{ - B_ALLOCED_DATA *allocedData; - - allocedData = B_MemoryPoolFindAllocedObject (memoryPool, *data); - - if ((*data = T_realloc (*data, size)) == NULL_PTR) { - if (allocedData != (B_ALLOCED_DATA *)NULL_PTR) - /* Could not reallocate, so nullify this entry. */ - allocedData->object = NULL_PTR; - - return (BE_ALLOC); - } - - /* Realloc was successful. - */ - if (allocedData == (B_ALLOCED_DATA *)NULL_PTR) - /* The data was not in the memory pool to start with, so adopt it. - Note that this also happens when the data is initially NULL_PTR. */ - return (B_MemoryPoolAdoptData (memoryPool, data, size)); - - /* Replace the entry on the alloced list with the new memory. - */ - allocedData->object = *data; - allocedData->size = size; - return (0); -} - -/* Find the object in the alloced list, call the DeleteFunction if - there is one, zeroize it and free it, nullifying that alloced list entry. - The object to be freed is passed by pointer and is set to NULL_PTR to - enforce the fact that the address no longer points to valid memory. - This assumes that the (POINTER *)data is not (POINTER *)NULL_PTR. - If the address is not found on the alloced list, only set the address - to NULL_PTR. - */ -void B_MemoryPoolFree (memoryPool, object) -B_MemoryPool *memoryPool; -POINTER *object; -{ - B_ALLOCED_DATA *allocedData; - - if ((allocedData = B_MemoryPoolFindAllocedObject (memoryPool, *object)) - != (B_ALLOCED_DATA *)NULL_PTR) { - if (allocedData->DeleteFunction != NULL) - /* There is a destroy function, so call. */ - (*allocedData->DeleteFunction) (allocedData->object); - else { - T_memset (*object, 0, allocedData->size); - T_free (*object); - } - - /* Set this entry to NULL_PTR so that reset will not process it. */ - allocedData->object = NULL_PTR; - } - - *object = NULL_PTR; -} - -/* Return a pointer to the alloced object entry in the memoryPool. - Return (ALLOCED_DATA *)NULL_PTR if object is NULL_PTR or object is not - in the memoryPool. - */ -B_ALLOCED_DATA *B_MemoryPoolFindAllocedObject (memoryPool, object) -B_MemoryPool *memoryPool; -POINTER object; -{ - B_ALLOCED_DATA *allocedData; - unsigned int i; - - if (object == NULL_PTR) - return ((B_ALLOCED_DATA *)NULL_PTR); - - for (i = memoryPool->z.allocedCount, - allocedData = memoryPool->z.allocedList; - i-- > 0; - ++allocedData) { - if (allocedData->object == object) - return (allocedData); - } - - /* data not found. */ - return ((B_ALLOCED_DATA *)NULL_PTR); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/bmempool.h b/usr/src/lib/libresolv2/common/dnssafe/bmempool.h deleted file mode 100644 index 923a5f6967..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bmempool.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _BMEMPOOL_H_ -#define _BMEMPOOL_H_ 1 - -typedef void (*B_MEMORY_POOL_DELETE_FUNCTION) PROTO_LIST ((POINTER)); - -typedef struct { - POINTER object; - unsigned int size; - B_MEMORY_POOL_DELETE_FUNCTION DeleteFunction; -} B_ALLOCED_DATA; - -typedef struct { - struct { - unsigned int allocedCount; - unsigned int maxAllocedCount; /* Size of the actuall allocated list */ - B_ALLOCED_DATA *allocedList; - /* POINTER reserved; */ - } z; /* z gives the members that are zeroized by the constructor */ -} B_MemoryPool; - -void B_MemoryPoolConstructor PROTO_LIST ((B_MemoryPool *)); -void B_MemoryPoolDestructor PROTO_LIST ((B_MemoryPool *)); - -void B_MemoryPoolReset PROTO_LIST ((B_MemoryPool *)); -int B_MemoryPoolAlloc PROTO_LIST ((B_MemoryPool *, POINTER *, unsigned int)); -int B_MemoryPoolAllocAndCopy PROTO_LIST - ((B_MemoryPool *, POINTER *, POINTER, unsigned int)); -int B_MemoryPoolAdoptData PROTO_LIST - ((B_MemoryPool *, POINTER *, unsigned int)); -int B_MemoryPoolAdoptObject PROTO_LIST - ((B_MemoryPool *, POINTER *, B_MEMORY_POOL_DELETE_FUNCTION)); -int B_MemoryPoolRealloc PROTO_LIST ((B_MemoryPool *, POINTER *, unsigned int)); -int B_MemoryPoolSafeRealloc PROTO_LIST - ((B_MemoryPool *, POINTER *, unsigned int)); -void B_MemoryPoolFree PROTO_LIST ((B_MemoryPool *, POINTER *)); -void B_MemoryPoolResetExceptObject PROTO_LIST ((B_MemoryPool *, POINTER)); - -/* These are "private member functions ". - */ -B_ALLOCED_DATA *B_MemoryPoolFindAllocedObject PROTO_LIST - ((B_MemoryPool *, POINTER)); -int B_MemoryPoolAdoptHelper PROTO_LIST - ((B_MemoryPool *, POINTER, unsigned int, B_MEMORY_POOL_DELETE_FUNCTION)); - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/bsafe2.h b/usr/src/lib/libresolv2/common/dnssafe/bsafe2.h deleted file mode 100644 index 1bae822a8a..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/bsafe2.h +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _BSAFE_H_ -#define _BSAFE_H_ 1 - -#ifndef T_CALL -#define T_CALL -#endif - -#include "atypes.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define BE_ALGORITHM_ALREADY_SET 0x0200 -#define BE_ALGORITHM_INFO 0x0201 -#define BE_ALGORITHM_NOT_INITIALIZED 0x0202 -#define BE_ALGORITHM_NOT_SET 0x0203 -#define BE_ALGORITHM_OBJ 0x0204 -#define BE_ALG_OPERATION_UNKNOWN 0x0205 -#define BE_ALLOC 0x0206 -#define BE_CANCEL 0x0207 -#define BE_DATA 0x0208 -#define BE_EXPONENT_EVEN 0x0209 -#define BE_EXPONENT_LEN 0x020a -#define BE_HARDWARE 0x020b -#define BE_INPUT_DATA 0x020c -#define BE_INPUT_LEN 0x020d -#define BE_KEY_ALREADY_SET 0x020e -#define BE_KEY_INFO 0x020f -#define BE_KEY_LEN 0x0210 -#define BE_KEY_NOT_SET 0x0211 -#define BE_KEY_OBJ 0x0212 -#define BE_KEY_OPERATION_UNKNOWN 0x0213 -#define BE_MEMORY_OBJ 0x0214 -#define BE_MODULUS_LEN 0x0215 -#define BE_NOT_INITIALIZED 0x0216 -#define BE_NOT_SUPPORTED 0x0217 -#define BE_OUTPUT_LEN 0x0218 -#define BE_OVER_32K 0x0219 -#define BE_RANDOM_NOT_INITIALIZED 0x021a -#define BE_RANDOM_OBJ 0x021b -#define BE_SIGNATURE 0x021c -#define BE_WRONG_ALGORITHM_INFO 0x021d -#define BE_WRONG_KEY_INFO 0x021e -#define BE_INPUT_COUNT 0x021f -#define BE_OUTPUT_COUNT 0x0220 -#define BE_METHOD_NOT_IN_CHOOSER 0x221 - -typedef POINTER B_KEY_OBJ; -typedef POINTER B_ALGORITHM_OBJ; - -typedef int (T_CALL *B_INFO_TYPE) PROTO_LIST ((POINTER *)); - -typedef struct B_ALGORITHM_METHOD B_ALGORITHM_METHOD; -typedef B_ALGORITHM_METHOD **B_ALGORITHM_CHOOSER; - -/* Routines supplied by the implementor. - */ -void T_CALL T_memset PROTO_LIST ((POINTER, int, unsigned int)); -void T_CALL T_memcpy PROTO_LIST ((POINTER, CPOINTER, unsigned int)); -void T_CALL T_memmove PROTO_LIST ((POINTER, POINTER, unsigned int)); -int T_CALL T_memcmp PROTO_LIST ((CPOINTER, CPOINTER, unsigned int)); -POINTER T_CALL T_malloc PROTO_LIST ((unsigned int)); -POINTER T_CALL T_realloc PROTO_LIST ((POINTER, unsigned int)); -void T_CALL T_free PROTO_LIST ((POINTER)); - -/* The key object. - */ -int T_CALL B_CreateKeyObject PROTO_LIST ((B_KEY_OBJ *)); -void T_CALL B_DestroyKeyObject PROTO_LIST ((B_KEY_OBJ *)); -int T_CALL B_SetKeyInfo PROTO_LIST ((B_KEY_OBJ, B_INFO_TYPE, POINTER)); -int T_CALL B_GetKeyInfo PROTO_LIST ((POINTER *, B_KEY_OBJ, B_INFO_TYPE)); - -/* The algorithm object. - */ -int T_CALL B_CreateAlgorithmObject PROTO_LIST ((B_ALGORITHM_OBJ *)); -void T_CALL B_DestroyAlgorithmObject PROTO_LIST ((B_ALGORITHM_OBJ *)); -int T_CALL B_SetAlgorithmInfo PROTO_LIST - ((B_ALGORITHM_OBJ, B_INFO_TYPE, POINTER)); -int T_CALL B_GetAlgorithmInfo PROTO_LIST - ((POINTER *, B_ALGORITHM_OBJ, B_INFO_TYPE)); - -unsigned int B_IntegerBits PROTO_LIST ((unsigned char *, unsigned int)); - -/* Algorithm operations. - */ -int T_CALL B_RandomInit PROTO_LIST - ((B_ALGORITHM_OBJ, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int T_CALL B_RandomUpdate PROTO_LIST - ((B_ALGORITHM_OBJ, unsigned char *, unsigned int, A_SURRENDER_CTX *)); -int T_CALL B_GenerateRandomBytes PROTO_LIST - ((B_ALGORITHM_OBJ, unsigned char *, unsigned int, A_SURRENDER_CTX *)); - -int T_CALL B_DigestInit PROTO_LIST - ((B_ALGORITHM_OBJ, B_KEY_OBJ, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int T_CALL B_DigestUpdate PROTO_LIST - ((B_ALGORITHM_OBJ, const unsigned char *, unsigned int, A_SURRENDER_CTX *)); -int T_CALL B_DigestFinal PROTO_LIST - ((B_ALGORITHM_OBJ, unsigned char *, unsigned int *, unsigned int, - A_SURRENDER_CTX *)); - -int T_CALL B_EncryptInit PROTO_LIST - ((B_ALGORITHM_OBJ, B_KEY_OBJ, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int T_CALL B_EncryptUpdate PROTO_LIST - ((B_ALGORITHM_OBJ, unsigned char *, unsigned int *, unsigned int, - unsigned char *, unsigned int, B_ALGORITHM_OBJ, A_SURRENDER_CTX *)); -int T_CALL B_EncryptFinal PROTO_LIST - ((B_ALGORITHM_OBJ, unsigned char *, unsigned int *, unsigned int, - B_ALGORITHM_OBJ, A_SURRENDER_CTX *)); - -int T_CALL B_DecryptInit PROTO_LIST - ((B_ALGORITHM_OBJ, B_KEY_OBJ, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int T_CALL B_DecryptUpdate PROTO_LIST - ((B_ALGORITHM_OBJ, unsigned char *, unsigned int *, unsigned int, - const unsigned char *, unsigned int, B_ALGORITHM_OBJ, A_SURRENDER_CTX *)); -int T_CALL B_DecryptFinal PROTO_LIST - ((B_ALGORITHM_OBJ, unsigned char *, unsigned int *, unsigned int, - B_ALGORITHM_OBJ, A_SURRENDER_CTX *)); - - - -int T_CALL B_GenerateInit PROTO_LIST - ((B_ALGORITHM_OBJ, B_ALGORITHM_CHOOSER, A_SURRENDER_CTX *)); -int T_CALL B_GenerateKeypair PROTO_LIST - ((B_ALGORITHM_OBJ, B_KEY_OBJ, B_KEY_OBJ, B_ALGORITHM_OBJ, - A_SURRENDER_CTX *)); -int T_CALL B_GenerateParameters PROTO_LIST - ((B_ALGORITHM_OBJ, B_ALGORITHM_OBJ, B_ALGORITHM_OBJ, A_SURRENDER_CTX *)); - - -/* Information for password-based encryption (PBE) algorithms. - */ -typedef struct { - unsigned char *salt; /* salt value */ - unsigned int iterationCount; /* iteration count */ -} B_PBE_PARAMS; - -/* Information for MAC algorithm. - */ -typedef struct { - unsigned int macLen; /* length of MAC value */ -} B_MAC_PARAMS; - - -/* Information for BSAFE 1.x compatible encryption algorithms. - */ - - -typedef struct { - unsigned int threshold; /* share threshold */ -} B_SECRET_SHARING_PARAMS; - -/* Key Info Types. - */ -int T_CALL KI_8Byte PROTO_LIST ((POINTER *)); -int T_CALL KI_Item PROTO_LIST ((POINTER *)); -int T_CALL KI_PKCS_RSAPrivate PROTO_LIST ((POINTER *)); -int T_CALL KI_RSAPublic PROTO_LIST ((POINTER *)); -int T_CALL KI_RSA_CRT PROTO_LIST ((POINTER *)); - -/* Algorithm Info Types. - */ -int T_CALL AI_MD5 PROTO_LIST ((POINTER *)); -int T_CALL AI_MD5Random PROTO_LIST ((POINTER *)); -int T_CALL AI_PKCS_RSAPrivate PROTO_LIST ((POINTER *)); -int T_CALL AI_PKCS_RSAPublic PROTO_LIST ((POINTER *)); -int T_CALL AI_RSAKeyGen PROTO_LIST ((POINTER *)); -int T_CALL AI_RSAPrivate PROTO_LIST ((POINTER *)); -int T_CALL AI_RSAPublic PROTO_LIST ((POINTER *)); - - -/* Algorithm methods for use int the algorithm chooser. - */ -extern B_ALGORITHM_METHOD T_CALL AM_MD5; -extern B_ALGORITHM_METHOD T_CALL AM_MD5_RANDOM; -extern B_ALGORITHM_METHOD T_CALL AM_RSA_CRT_DECRYPT; -extern B_ALGORITHM_METHOD T_CALL AM_RSA_CRT_ENCRYPT; -extern B_ALGORITHM_METHOD T_CALL AM_RSA_DECRYPT; -extern B_ALGORITHM_METHOD T_CALL AM_RSA_ENCRYPT; -extern B_ALGORITHM_METHOD T_CALL AM_RSA_KEY_GEN; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/btypechk.h b/usr/src/lib/libresolv2/common/dnssafe/btypechk.h deleted file mode 100644 index 328e5008e1..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/btypechk.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _BTYPECHK_H_ -#define _BTYPECHK_H_ 1 - -struct B_TypeCheck; - -typedef void (*B_TYPE_CHECK_DESTRUCTOR) PROTO_LIST ((struct B_TypeCheck *)); - -typedef struct B_TypeCheck { - B_TYPE_CHECK_DESTRUCTOR _Destructor; -} B_TypeCheck; - -#define B_TYPE_CHECK_Constructor(typeCheck, Destructor)\ - (typeCheck)->_Destructor = (Destructor) -#define B_TYPE_CHECK_Destructor(typeCheck)\ - (*(typeCheck)->_Destructor) (typeCheck) - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/cantobig.c b/usr/src/lib/libresolv2/common/dnssafe/cantobig.c deleted file mode 100644 index b41c3d758a..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/cantobig.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "bigmath.h" -#include "port_after.h" - -/* CanonicalToBig () copies a byte vector into a word vector while REVERSING - the order of significance. The byte vector is input MSByte first while - the word vector is written out LSWord first. It also adds a leading zero - sign bit if necessary. - Returns 0, AE_DATA. - */ -int CanonicalToBig (wordPointer, wordCount, bytePointer, numBytes) -UINT2 *wordPointer; -unsigned int wordCount; -const unsigned char *bytePointer; -unsigned int numBytes; -{ - unsigned int copyCount; - - if (A_IntegerBits (bytePointer, numBytes) / 16 + 1 > wordCount) - return (AE_DATA); - - /* start at end of byte vector */ - bytePointer += numBytes-1; - - /* copy as much as possible */ - copyCount = (wordCount < numBytes / 2) ? wordCount : numBytes / 2; - wordCount -= copyCount; - numBytes -= 2 * copyCount; - while (copyCount--) { - /* Copy two bytes.*/ - *wordPointer++ = (UINT2)*bytePointer + (*(bytePointer - 1) << 8); - bytePointer -= 2; - } - - if (wordCount && numBytes & 1) { - /* If the number of input bytes was odd. Copy one last byte.*/ - *wordPointer++ = (UINT2)*bytePointer--; - wordCount--; - numBytes--; - } - - /* zero fill remainder of word vector */ - while (wordCount--) - *wordPointer++ = 0; - - return (0); -} - - diff --git a/usr/src/lib/libresolv2/common/dnssafe/crt2.c b/usr/src/lib/libresolv2/common/dnssafe/crt2.c deleted file mode 100644 index 0428183591..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/crt2.c +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "crt2.h" -#include "bigmath.h" -#include "port_after.h" - -/* RSA encryption/decryption with Chinese Remainder Theorem. - */ - -#define GENERATE_BREAK(type) { \ - status = type; \ - break; \ - } - -static int RSA_CRT2 PROTO_LIST - ((A_RSA_CRT2_CTX *, unsigned char *, unsigned int *, unsigned int, - const unsigned char *, A_SURRENDER_CTX *)); - -int A_RSA_CRT2Init (context, key) -A_RSA_CRT2_CTX *context; -A_RSA_CRT_KEY *key; -{ - if (A_IntegerBits (key->modulus.data, key->modulus.len) - > MAX_RSA_MODULUS_BITS) - /* Key len is too big to handle. */ - return (AE_MODULUS_LEN); - - /* Set the block update blockLen to be big enough to hold the modulus. - */ - context->blockLen = - BITS_TO_LEN (A_IntegerBits (key->modulus.data, key->modulus.len)); - - context->inputLen = 0; - - /* convert first prime to bignum format */ - if (CanonicalToBig - (context->primeP, MAX_RSA_PRIME_WORDS, key->prime[0].data, - key->prime[0].len)) - return (AE_KEY_INFO); - - /* compute significant length of first prime */ - context->primeWords = BITS_TO_WORDS - (BigLen (context->primeP, MAX_RSA_PRIME_WORDS)); - - /* convert other private key parameters to bignum format */ - if (CanonicalToBig - (context->primeQ, context->primeWords, key->prime[1].data, - key->prime[1].len) || - CanonicalToBig - (context->exponentP, context->primeWords, - key->primeExponent[0].data, key->primeExponent[0].len) || - CanonicalToBig - (context->exponentQ, context->primeWords, - key->primeExponent[1].data, key->primeExponent[1].len) || - CanonicalToBig - (context->coefficient, context->primeWords, - key->coefficient.data, key->coefficient.len)) - return (AE_KEY_INFO); - - /* convert modulus to bignum format */ - if (CanonicalToBig - (context->modulus, 2 * context->primeWords, - key->modulus.data, key->modulus.len)) - return (AE_KEY_INFO); - - return (0); -} - -int A_RSA_CRT2Update - (context, partOut, partOutLen, maxPartOutLen, partIn, partInLen, - surrenderContext) -A_RSA_CRT2_CTX *context; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -const unsigned char *partIn; -unsigned int partInLen; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - unsigned int partialLen, localPartOutLen; - - /* Initialize partOutLen to zero. */ - *partOutLen = 0; - - if (context->inputLen + partInLen < context->blockLen) { - /* Not enough to encrypt - just accumulate. - */ - T_memcpy - ((POINTER)(context->input + context->inputLen), (CPOINTER)partIn, - partInLen); - context->inputLen += partInLen; - return (0); - } - - if (context->inputLen > 0) { - /* Need to accumulate the rest of the block bytes into the input and - encrypt from there (otherwise it's OK to encrypt straight from - the partIn). - */ - partialLen = context->blockLen - context->inputLen; - T_memcpy - ((POINTER)(context->input + context->inputLen), (CPOINTER)partIn, - partialLen); - partIn += partialLen; - partInLen -= partialLen; - - if ((status = RSA_CRT2 - (context, partOut, &localPartOutLen, maxPartOutLen, context->input, - surrenderContext)) != 0) - return (status); - (*partOutLen) += localPartOutLen; - partOut += localPartOutLen; - maxPartOutLen -= localPartOutLen; - } - - /* Encrypt as many blocks of input as provided. - */ - while (partInLen >= context->blockLen) { - if ((status = RSA_CRT2 - (context, partOut, &localPartOutLen, maxPartOutLen, partIn, - surrenderContext)) != 0) - return (status); - - partIn += context->blockLen; - partInLen -= context->blockLen; - (*partOutLen) += localPartOutLen; - partOut += localPartOutLen; - maxPartOutLen -= localPartOutLen; - } - - /* Copy remaining input bytes to the context's input buffer. - */ - T_memcpy - ((POINTER)context->input, partIn, partInLen); - context->inputLen = partInLen; - return (0); -} - -int A_RSA_CRT2Final (context) -A_RSA_CRT2_CTX *context; -{ - if (context->inputLen != 0) - return (AE_INPUT_LEN); - - /* Restart context to accumulate a new block. - */ - context->inputLen = 0; - return (0); -} - -/* Assume input length is context->blockLen. - */ -static int RSA_CRT2 - (context, output, outputLen, maxOutputLen, input, surrenderContext) -A_RSA_CRT2_CTX *context; -unsigned char *output; -unsigned int *outputLen; -unsigned int maxOutputLen; -const unsigned char *input; -A_SURRENDER_CTX *surrenderContext; -{ - struct ModExpCRTFrame { - UINT2 bigInBuf[2 * MAX_RSA_PRIME_WORDS], - bigOutBuf[2 * MAX_RSA_PRIME_WORDS]; - } *frame = (struct ModExpCRTFrame *)NULL_PTR; -#if !USE_ALLOCED_FRAME - struct ModExpCRTFrame stackFrame; -#endif - int status; - - status = 0; - do { - if ((*outputLen = context->blockLen) > maxOutputLen) - return (AE_OUTPUT_LEN); - -#if USE_ALLOCED_FRAME - if ((frame = (struct ModExpCRTFrame *)T_malloc (sizeof (*frame))) - == (struct ModExpCRTFrame *)NULL_PTR) { - status = AE_ALLOC; - break; - } -#else - /* Just use the buffers allocated on the stack. */ - frame = &stackFrame; -#endif - - /* Convert input to bignum representation. - This won't return AE_DATA since input length was checked at Update. - */ - CanonicalToBig - (frame->bigInBuf, 2 * context->primeWords, input, context->blockLen); - - /* Check for overflow. */ - if (BigCmp - (frame->bigInBuf, context->modulus, 2 * context->primeWords) >= 0) - GENERATE_BREAK (AE_INPUT_DATA); - - /* Chinese remainder exponentiation. */ - if ((status = BigUnexp - (frame->bigOutBuf, frame->bigInBuf, context->primeP, context->primeQ, - context->exponentP, context->exponentQ, context->coefficient, - context->primeWords, surrenderContext)) != 0) - break; - - /* Convert output to canonical representation. - This won't return AE_DATA since outputLen was set above. - */ - BigToCanonical - (output, *outputLen, frame->bigOutBuf, 2 * context->primeWords); - } while (0); - - if (frame != (struct ModExpCRTFrame *)NULL_PTR) { - T_memset ((POINTER)frame, 0, sizeof (*frame)); -#if USE_ALLOCED_FRAME - T_free ((POINTER)frame); -#endif - } - return (status); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/crt2.h b/usr/src/lib/libresolv2/common/dnssafe/crt2.h deleted file mode 100644 index c26d7bdacb..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/crt2.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1994, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _RSA_H_ -#define _RSA_H_ 1 - -#include "bigmaxes.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Note, these are only valid after a call to A_RSA_CRT2Init. - */ -#define A_RSA_CRT2_BLOCK_LEN(context) ((context)->blockLen) -#define A_RSA_CRT2_MAX_OUTPUT_LEN(context, inputLen)\ - (inputLen) + (((inputLen) % (context)->blockLen) ?\ - (context)->blockLen - ((inputLen) % (context)->blockLen) : 0) - -typedef struct { - unsigned int blockLen; /* total size of the block to be computed */ - unsigned char input[MAX_RSA_MODULUS_LEN]; - unsigned int inputLen; - unsigned int primeWords; - UINT2 modulus[2 * MAX_RSA_PRIME_WORDS]; - UINT2 primeP[MAX_RSA_PRIME_WORDS]; - UINT2 primeQ[MAX_RSA_PRIME_WORDS]; - UINT2 exponentP[MAX_RSA_PRIME_WORDS]; - UINT2 exponentQ[MAX_RSA_PRIME_WORDS]; - UINT2 coefficient[MAX_RSA_PRIME_WORDS]; -} A_RSA_CRT2_CTX; - -int A_RSA_CRT2Init PROTO_LIST ((A_RSA_CRT2_CTX *, A_RSA_CRT_KEY *)); -int A_RSA_CRT2Update PROTO_LIST - ((A_RSA_CRT2_CTX *, unsigned char *, unsigned int *, unsigned int, - const unsigned char *, unsigned int, A_SURRENDER_CTX *)); -int A_RSA_CRT2Final PROTO_LIST ((A_RSA_CRT2_CTX *)); -void A_RSA_CRT2GetMaxOutputLen PROTO_LIST - ((A_RSA_CRT2_CTX *, unsigned int *, unsigned int)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/digest.c b/usr/src/lib/libresolv2/common/dnssafe/digest.c deleted file mode 100644 index 4394f579ec..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/digest.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "keyobj.h" -#include "algobj.h" -#include "port_after.h" - -int B_DigestInit - (algorithmObject, keyObject, algorithmChooser, surrenderContext) -B_ALGORITHM_OBJ algorithmObject; -B_KEY_OBJ keyObject; -B_ALGORITHM_CHOOSER algorithmChooser; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = AlgorithmWrapCheck (THE_ALG_WRAP)) != 0) - return (status); - if ((status = KeyWrapCheck ((KeyWrap *)keyObject)) != 0) - return (status); - - return (B_AlgorithmDigestInit - (&THE_ALG_WRAP->algorithm, &((KeyWrap *)keyObject)->key, - algorithmChooser, surrenderContext)); -} - -int B_DigestUpdate (algorithmObject, partIn, partInLen, surrenderContext) -B_ALGORITHM_OBJ algorithmObject; -const unsigned char *partIn; -unsigned int partInLen; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = AlgorithmWrapCheck (THE_ALG_WRAP)) != 0) - return (status); - - return (B_AlgorithmDigestUpdate - (&THE_ALG_WRAP->algorithm, partIn, partInLen, surrenderContext)); -} - -int B_DigestFinal - (algorithmObject, digest, digestLen, maxDigestLen, surrenderContext) -B_ALGORITHM_OBJ algorithmObject; -unsigned char *digest; -unsigned int *digestLen; -unsigned int maxDigestLen; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = AlgorithmWrapCheck (THE_ALG_WRAP)) != 0) - return (status); - - return (B_AlgorithmDigestFinal - (&THE_ALG_WRAP->algorithm, digest, digestLen, maxDigestLen, - surrenderContext)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/digrand.c b/usr/src/lib/libresolv2/common/dnssafe/digrand.c deleted file mode 100644 index 62ba5ba337..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/digrand.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1992, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "digrand.h" -#include "port_after.h" - -/* Calling routine must initialize the digest algorithm and set - digestRandom->vTable. - digestLen is the length of the output of the digest algorithm (i.e. 16). - state must point to an unsigned char * array of 3 * digestLen. - */ -void A_DigestRandomInit (digestRandom, digestLen, state) -A_DigestRandom *digestRandom; -unsigned int digestLen; -unsigned char *state; -{ - digestRandom->_state = state; - digestRandom->_output = state + digestLen; - digestRandom->_digest = digestRandom->_output + digestLen; - - digestRandom->_outputAvailable = 0; - digestRandom->_digestLen = digestLen; - - T_memset ((POINTER)digestRandom->_state, 0, digestLen); -} - -void A_DigestRandomUpdate (digestRandom, input, inputLen) -A_DigestRandom *digestRandom; -unsigned char *input; -unsigned int inputLen; -{ - unsigned int i, j, x; - - (*digestRandom->vTable->DigestUpdate) (digestRandom, input, inputLen); - (*digestRandom->vTable->DigestFinal) (digestRandom, digestRandom->_digest); - - /* add digest to state */ - x = 0; - for (i = 0; i < digestRandom->_digestLen; i++) { - j = digestRandom->_digestLen-1-i; - x += digestRandom->_state[j] + digestRandom->_digest[j]; - digestRandom->_state[j] = (unsigned char)x; - x >>= 8; - } -} - -void A_DigestRandomGenerateBytes (digestRandom, output, outputLen) -A_DigestRandom *digestRandom; -unsigned char *output; -unsigned int outputLen; -{ - unsigned int available, i; - - available = digestRandom->_outputAvailable; - - while (outputLen > available) { - T_memcpy - ((POINTER)output, - (POINTER)&digestRandom->_output[digestRandom->_digestLen-available], - available); - output += available; - outputLen -= available; - - /* generate new output */ - (*digestRandom->vTable->DigestUpdate) - (digestRandom, digestRandom->_state, digestRandom->_digestLen); - (*digestRandom->vTable->DigestFinal) (digestRandom, digestRandom->_output); - available = digestRandom->_digestLen; - - /* increment state */ - for (i = 0; i < digestRandom->_digestLen; i++) - if (digestRandom->_state[digestRandom->_digestLen-1-i]++) - break; - } - - T_memcpy - ((POINTER)output, - (POINTER)&digestRandom->_output[digestRandom->_digestLen-available], - outputLen); - digestRandom->_outputAvailable = available - outputLen; -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/digrand.h b/usr/src/lib/libresolv2/common/dnssafe/digrand.h deleted file mode 100644 index f93ea1d63a..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/digrand.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1992, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _DIGRAND_H_ -#define _DIGRAND_H_ 1 - -#ifdef __cplusplus -extern "C" { -#endif - -/* Use the THIS_DIGEST_RANDOM macro to define the type of object in the - virtual function prototype. It defaults to the most base class, but - derived modules may define the macro to a more derived class before - including this header file. - */ -#ifndef THIS_DIGEST_RANDOM -#define THIS_DIGEST_RANDOM struct A_DigestRandom -#endif - -struct A_DigestRandom; - -typedef struct { - void (*DigestUpdate) PROTO_LIST - ((THIS_DIGEST_RANDOM *, unsigned char *, unsigned int)); - void (*DigestFinal) PROTO_LIST ((THIS_DIGEST_RANDOM *, unsigned char *)); -} A_DigestRandomVTable; - -typedef struct A_DigestRandom { - unsigned char *_state; /* input to digest */ - unsigned char *_output; /* current output of digest */ - unsigned int _outputAvailable; - unsigned char *_digest; - unsigned int _digestLen; - A_DigestRandomVTable *vTable; -} A_DigestRandom; - -void A_DigestRandomInit PROTO_LIST - ((A_DigestRandom *, unsigned int, unsigned char *)); -void A_DigestRandomUpdate PROTO_LIST - ((A_DigestRandom *, unsigned char *, unsigned int)); -void A_DigestRandomGenerateBytes PROTO_LIST - ((A_DigestRandom *, unsigned char *, unsigned int)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/encrypt.c b/usr/src/lib/libresolv2/common/dnssafe/encrypt.c deleted file mode 100644 index 71e34ea714..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/encrypt.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "keyobj.h" -#include "algobj.h" -#include "port_after.h" - -int B_EncryptInit - (algorithmObject, keyObject, algorithmChooser, surrenderContext) -B_ALGORITHM_OBJ algorithmObject; -B_KEY_OBJ keyObject; -B_ALGORITHM_CHOOSER algorithmChooser; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = AlgorithmWrapCheck (THE_ALG_WRAP)) != 0) - return (status); - if ((status = KeyWrapCheck ((KeyWrap *)keyObject)) != 0) - return (status); - - return (B_AlgorithmEncryptInit - (&THE_ALG_WRAP->algorithm, &((KeyWrap *)keyObject)->key, - algorithmChooser, surrenderContext)); -} - -int B_EncryptUpdate - (algorithmObject, partOut, partOutLen, maxPartOutLen, partIn, partInLen, - randomAlgorithm, surrenderContext) -B_ALGORITHM_OBJ algorithmObject; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -unsigned char *partIn; -unsigned int partInLen; -B_ALGORITHM_OBJ randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = AlgorithmWrapCheck (THE_ALG_WRAP)) != 0) - return (status); - if ((status = RandomAlgorithmCheck (randomAlgorithm)) != 0) - return (status); - - return (B_AlgorithmEncryptUpdate - (&THE_ALG_WRAP->algorithm, partOut, partOutLen, maxPartOutLen, - partIn, partInLen, - &((AlgorithmWrap *)randomAlgorithm)->algorithm, surrenderContext)); -} - -int B_EncryptFinal - (algorithmObject, partOut, partOutLen, maxPartOutLen, randomAlgorithm, - surrenderContext) -B_ALGORITHM_OBJ algorithmObject; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -B_ALGORITHM_OBJ randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = AlgorithmWrapCheck (THE_ALG_WRAP)) != 0) - return (status); - if ((status = RandomAlgorithmCheck (randomAlgorithm)) != 0) - return (status); - - return (B_AlgorithmEncryptFinal - (&THE_ALG_WRAP->algorithm, partOut, partOutLen, maxPartOutLen, - &((AlgorithmWrap *)randomAlgorithm)->algorithm, surrenderContext)); -} - -int B_DecryptInit - (algorithmObject, keyObject, algorithmChooser, surrenderContext) -B_ALGORITHM_OBJ algorithmObject; -B_KEY_OBJ keyObject; -B_ALGORITHM_CHOOSER algorithmChooser; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = AlgorithmWrapCheck (THE_ALG_WRAP)) != 0) - return (status); - if ((status = KeyWrapCheck ((KeyWrap *)keyObject)) != 0) - return (status); - - return (B_AlgorithmDecryptInit - (&THE_ALG_WRAP->algorithm, &((KeyWrap *)keyObject)->key, - algorithmChooser, surrenderContext)); -} - -int B_DecryptUpdate - (algorithmObject, partOut, partOutLen, maxPartOutLen, partIn, partInLen, - randomAlgorithm, surrenderContext) -B_ALGORITHM_OBJ algorithmObject; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -const unsigned char *partIn; -unsigned int partInLen; -B_ALGORITHM_OBJ randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = AlgorithmWrapCheck (THE_ALG_WRAP)) != 0) - return (status); - if ((status = RandomAlgorithmCheck (randomAlgorithm)) != 0) - return (status); - - return (B_AlgorithmDecryptUpdate - (&THE_ALG_WRAP->algorithm, partOut, partOutLen, maxPartOutLen, - partIn, partInLen, - &((AlgorithmWrap *)randomAlgorithm)->algorithm, surrenderContext)); -} - -int B_DecryptFinal - (algorithmObject, partOut, partOutLen, maxPartOutLen, randomAlgorithm, - surrenderContext) -B_ALGORITHM_OBJ algorithmObject; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -B_ALGORITHM_OBJ randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = AlgorithmWrapCheck (THE_ALG_WRAP)) != 0) - return (status); - if ((status = RandomAlgorithmCheck (randomAlgorithm)) != 0) - return (status); - - return (B_AlgorithmDecryptFinal - (&THE_ALG_WRAP->algorithm, partOut, partOutLen, maxPartOutLen, - &((AlgorithmWrap *)randomAlgorithm)->algorithm, surrenderContext)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/generate.c b/usr/src/lib/libresolv2/common/dnssafe/generate.c deleted file mode 100644 index f892ad60e9..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/generate.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ainfotyp.h" -#include "keyobj.h" -#include "algobj.h" -#include "port_after.h" - -int B_GenerateInit (algorithmObject, algorithmChooser, surrenderContext) -B_ALGORITHM_OBJ algorithmObject; -B_ALGORITHM_CHOOSER algorithmChooser; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = AlgorithmWrapCheck (THE_ALG_WRAP)) != 0) - return (status); - - return (B_AlgorithmGenerateInit - (&THE_ALG_WRAP->algorithm, algorithmChooser, surrenderContext)); -} - -int B_GenerateKeypair - (algorithmObject, publicKey, privateKey, randomAlgorithm, surrenderContext) -B_ALGORITHM_OBJ algorithmObject; -B_KEY_OBJ publicKey; -B_KEY_OBJ privateKey; -B_ALGORITHM_OBJ randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = AlgorithmWrapCheck (THE_ALG_WRAP)) != 0) - return (status); - if ((status = KeyWrapCheck ((KeyWrap *)publicKey)) != 0) - return (status); - if ((status = KeyWrapCheck ((KeyWrap *)privateKey)) != 0) - return (status); - if ((status = RandomAlgorithmCheck (randomAlgorithm)) != 0) - return (status); - - return (B_AlgorithmGenerateKeypair - (&THE_ALG_WRAP->algorithm, &((KeyWrap *)publicKey)->key, - &((KeyWrap *)privateKey)->key, - &((AlgorithmWrap *)randomAlgorithm)->algorithm, surrenderContext)); -} - -int B_GenerateParameters - (algorithmObject, resultAlgorithmObject, randomAlgorithm, surrenderContext) -B_ALGORITHM_OBJ algorithmObject; -B_ALGORITHM_OBJ resultAlgorithmObject; -B_ALGORITHM_OBJ randomAlgorithm; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - - if ((status = AlgorithmWrapCheck (THE_ALG_WRAP)) != 0) - return (status); - if ((status = AlgorithmWrapCheck ((AlgorithmWrap *)resultAlgorithmObject)) - != 0) - return (status); - if ((status = RandomAlgorithmCheck (randomAlgorithm)) != 0) - return (status); - - return (B_AlgorithmGenerateParameters - (&THE_ALG_WRAP->algorithm, - &((AlgorithmWrap *)resultAlgorithmObject)->algorithm, - &((AlgorithmWrap *)randomAlgorithm)->algorithm, surrenderContext)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/global.h b/usr/src/lib/libresolv2/common/dnssafe/global.h deleted file mode 100644 index 811ba42cc4..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/global.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _GLOBAL_H_ -#define _GLOBAL_H_ 1 - -#ifdef __cplusplus -extern "C" { -#endif - -/* PROTOTYPES should be set to one if and only if the compiler supports - function argument prototyping. - The following makes PROTOTYPES default to 1 if it has not already been - defined as 0 with C compiler flags. - */ -#ifndef PROTOTYPES -#define PROTOTYPES 1 -#endif - -#include <sys/types.h> -#include <sys/param.h> -#if (!defined(BSD)) || (BSD < 199306) -# include <sys/bitypes.h> -#endif - -/* POINTER defines a generic pointer type */ -typedef unsigned char *POINTER; -typedef const unsigned char *CPOINTER; - -/* UINT2 defines a two byte word */ -typedef u_int16_t UINT2; - -/* UINT4 defines a four byte word */ -typedef u_int32_t UINT4; - -#ifndef NULL_PTR -#define NULL_PTR ((POINTER)0) -#endif - -#ifndef UNUSED_ARG -#define UNUSED_ARG(x) x = *(&x); -#endif - -/* PROTO_LIST is defined depending on how PROTOTYPES is defined above. - If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it - returns an empty list. - */ -#if PROTOTYPES -#define PROTO_LIST(list) list -#else -#define PROTO_LIST(list) () -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* end _GLOBAL_H_ */ diff --git a/usr/src/lib/libresolv2/common/dnssafe/intbits.c b/usr/src/lib/libresolv2/common/dnssafe/intbits.c deleted file mode 100644 index 6a213d30ee..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/intbits.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "port_after.h" - -/* Return the number of bits in the canonical, positive integer. - IntgerBits (0) = 0. - */ -unsigned int A_IntegerBits (integer, integerLen) -const unsigned char *integer; -unsigned int integerLen; -{ - unsigned char mask, byte; - unsigned int bytes, bits; - - for (bytes = 0; bytes < integerLen && integer[bytes] == 0; bytes++); - if (bytes == integerLen) - return (0); - - /* Get byte to test and increment byte count for final calculation */ - byte = integer[bytes++]; - - /* Get number of bits in most significant byte */ - for (bits = 8, mask = 0x80; (byte & mask) == 0; bits--, mask >>= 1); - return (8 * (integerLen - bytes) + bits); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/intitem.c b/usr/src/lib/libresolv2/common/dnssafe/intitem.c deleted file mode 100644 index 8c8d0ce4aa..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/intitem.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bmempool.h" -#include "intitem.h" -#include "port_after.h" - -/* Copy itemCount ITEMs from source to destination, allocating new - memory in the memoryPool. - Each ITEM is a canonical integer, and is stripped of leading zeros. - Use the list of staticItems as a template. Each of the staticItems - points to the ITEM within the staticStruct, which is a structure - of the same format as destination and source. - Returns 0, BE_ALLOC. - */ -int AllocAndCopyIntegerItems - (destination, source, staticStruct, staticItems, itemCount, memoryPool) -POINTER destination; -POINTER source; -POINTER staticStruct; -ITEM **staticItems; -unsigned int itemCount; -B_MemoryPool *memoryPool; -{ - ITEM sourceItem, *destinationItem; - int status; - unsigned int i, offset; - - for (i = 0; i < itemCount; i++) { - offset = (unsigned int)((char *)staticItems[i] - (char *)staticStruct); - sourceItem = *(ITEM *)((char *)source + offset); - destinationItem = (ITEM *)((char *)destination + offset); - - while (sourceItem.len > 0 && *sourceItem.data == 0) { - sourceItem.len--; - sourceItem.data++; - } - - if ((status = B_MemoryPoolAllocAndCopy - (memoryPool, (POINTER *)&destinationItem->data, - (POINTER)sourceItem.data, destinationItem->len = sourceItem.len)) - != 0) - return (status); - } - - return (0); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/intitem.h b/usr/src/lib/libresolv2/common/dnssafe/intitem.h deleted file mode 100644 index 6da83ce8e8..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/intitem.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -int AllocAndCopyIntegerItems PROTO_LIST - ((POINTER, POINTER, POINTER, ITEM **, unsigned int, B_MemoryPool *)); - diff --git a/usr/src/lib/libresolv2/common/dnssafe/keyobj.c b/usr/src/lib/libresolv2/common/dnssafe/keyobj.c deleted file mode 100644 index 9ac577d6de..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/keyobj.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "kinfotyp.h" -#include "keyobj.h" -#include "port_after.h" - -#define THE_KEY_WRAP ((KeyWrap *)keyObject) - -static char KEY_TYPE_TAG = 0; - -int B_CreateKeyObject (keyObject) -B_KEY_OBJ *keyObject; -{ - KeyWrap *keyWrap; - - if ((*keyObject = T_malloc (sizeof (*keyWrap))) == NULL_PTR) - return (BE_ALLOC); - - keyWrap = (KeyWrap *)*keyObject; - - /* First construct base class */ - B_KEY_Constructor (&keyWrap->key); - - keyWrap->typeTag = &KEY_TYPE_TAG; - keyWrap->selfCheck = keyWrap; - return (0); -} - -void B_DestroyKeyObject (keyObject) -B_KEY_OBJ *keyObject; -{ - KeyWrap *keyWrap = (KeyWrap *)*keyObject; - - /* Need to explicitly check for NULL_PTR since KeyWrapCheck does not. - */ - if (*keyObject == NULL_PTR) - return; - - if (KeyWrapCheck (keyWrap) == 0) { - /* zeroize self check to invalidate memory. */ - keyWrap->selfCheck = (KeyWrap *)NULL_PTR; - - /* Call base class descructor */ - B_KEY_Destructor (&keyWrap->key); - - T_free ((POINTER)keyWrap); - } - - *keyObject = NULL_PTR; -} - -int B_SetKeyInfo (keyObject, infoType, info) -B_KEY_OBJ keyObject; -B_INFO_TYPE infoType; -POINTER info; -{ - B_KeyInfoType *keyInfoType; - int status; - - if ((status = KeyWrapCheck (THE_KEY_WRAP)) != 0) - return (status); - - /* Get the KeyInfoType from the B_INFO_TYPE, which returns - zero for an AlgorithmInfoType, non-zero for KeyInfoType - */ - if ((*infoType) ((POINTER *)&keyInfoType) == 0) - return (BE_ALG_OPERATION_UNKNOWN); - - return (B_KeySetInfo (&THE_KEY_WRAP->key, keyInfoType, info)); -} - -int B_GetKeyInfo (info, keyObject, infoType) -POINTER *info; -B_KEY_OBJ keyObject; -B_INFO_TYPE infoType; -{ - B_KeyInfoType *keyInfoType; - int status; - - if ((status = KeyWrapCheck (THE_KEY_WRAP)) != 0) - return (status); - - /* Get the KeyInfoType from the B_INFO_TYPE, which returns - zero for an AlgorithmInfoType, non-zero for KeyInfoType - */ - if ((*infoType) ((POINTER *)&keyInfoType) == 0) - return (BE_ALG_OPERATION_UNKNOWN); - - return (B_KeyGetInfo (&THE_KEY_WRAP->key, info, keyInfoType)); -} - -/* Return 0 if this is a valid KeyWrap object, else BE_KEY_OBJ. - If keyWrap is NULL_PTR, return 0 and expect the lower routines - to check for NULL. - */ -int KeyWrapCheck (keyWrap) -KeyWrap *keyWrap; -{ - if (keyWrap == (KeyWrap *)NULL_PTR) - return (0); - - return ((keyWrap->selfCheck == keyWrap && keyWrap->typeTag == &KEY_TYPE_TAG) - ? 0 : BE_KEY_OBJ); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/keyobj.h b/usr/src/lib/libresolv2/common/dnssafe/keyobj.h deleted file mode 100644 index 41ad52e7eb..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/keyobj.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -typedef struct KeyWrap { - B_Key key; - char *typeTag; - struct KeyWrap *selfCheck; -} KeyWrap; - -int KeyWrapCheck PROTO_LIST ((KeyWrap *)); - diff --git a/usr/src/lib/libresolv2/common/dnssafe/ki8byte.c b/usr/src/lib/libresolv2/common/dnssafe/ki8byte.c deleted file mode 100644 index 8e6a069cfc..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ki8byte.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "kinfotyp.h" -#include "kiitem.h" -#include "ki8byte.h" -#include "port_after.h" - -int KIT_8ByteAddInfo PROTO_LIST ((B_Key *, POINTER)); -int KIT_8ByteMakeInfo PROTO_LIST ((POINTER *, B_Key *)); - -B_KeyInfoType KIT_8Byte = {KIT_8ByteAddInfo, KIT_8ByteMakeInfo}; - -int KI_8Byte (keyInfoType) -POINTER *keyInfoType; -{ - *keyInfoType = (POINTER)&KIT_8Byte; - - /* Return 1 to indicate a KeyInfoType, not an AlgorithmInfoType */ - return (1); -} - -/* info points to 8 byte key. - Cache as a KITItem and a KIT_8Byte. - */ -int KIT_8ByteAddInfo (key, info) -B_Key *key; -POINTER info; -{ - POINTER newData; - int status; - - /* Copy the 8 byte key. */ - if ((status = B_MemoryPoolAllocAndCopy - (&key->infoCache.memoryPool, &newData, info, 8)) != 0) - return (status); - - /* Cache as a KITItem as well as KIT_8Byte. - */ - if ((status = B_KeyAddItemInfo (key, (unsigned char *)newData, 8)) != 0) - return (status); - return (B_InfoCacheAddInfo (&key->infoCache, (POINTER)&KIT_8Byte, newData)); -} - -int KIT_8ByteMakeInfo (info, key) -POINTER *info; -B_Key *key; -{ - ITEM *item; - int status; - - /* Try to make one from a KI_Item. Since KI_Item doesn't - call KI_8Byte, this should not cause an endless loop. - */ - if ((status = B_KeyGetInfo (key, (POINTER *)&item, &KITItem)) != 0) - return (status); - if (item->len != 8) - return (BE_WRONG_KEY_INFO); - - *(unsigned char **)info = item->data; - return (0); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/ki8byte.h b/usr/src/lib/libresolv2/common/dnssafe/ki8byte.h deleted file mode 100644 index 197d3dcbe3..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/ki8byte.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -extern B_KeyInfoType KIT_8Byte; diff --git a/usr/src/lib/libresolv2/common/dnssafe/kifulprv.c b/usr/src/lib/libresolv2/common/dnssafe/kifulprv.c deleted file mode 100644 index 050f115e4a..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/kifulprv.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "kinfotyp.h" -#include "kifulprv.h" -#include "port_after.h" - -typedef struct { - ITEM modulus; /* modulus */ - ITEM publicExponent; /* exponent for the public key */ - ITEM privateExponent; /* exponent for the private key */ - ITEM prime[2]; /* prime factors */ - ITEM primeExponent[2]; /* exponents for prime factors */ - ITEM coefficient; /* CRT coefficient */ -} FULL_PRIVATE_KEY; - -static int KITFullPrivateKeyAddInfo PROTO_LIST ((B_Key *, POINTER)); - -static B_KeyInfoType KITFullPrivate = - {KITFullPrivateKeyAddInfo, B_KeyInfoTypeMakeError}; - -/* Create a FULL_PRIVATE_KEY value and only copy inthe entries - that are not (ITEM *)NULL_PTR. - primes and primeExponents point to a 2 entry ITEM array. - */ -int CacheFullPrivateKey - (key, modulus, publicExponent, privateExponent, primes, - primeExponents, coefficient) -B_Key *key; -ITEM *modulus; -ITEM *publicExponent; -ITEM *privateExponent; -ITEM *primes; -ITEM *primeExponents; -ITEM *coefficient; -{ - FULL_PRIVATE_KEY *fullKey; - int status; - - /* Allocate memory for FULL_PRIVATE_KEY value. - */ - if ((status = B_MemoryPoolAlloc - (&key->infoCache.memoryPool, (POINTER *)&fullKey, - sizeof (FULL_PRIVATE_KEY))) != 0) - return (status); - - /* Pre-zeroize and only copy in values that are not NULL. - */ - T_memset ((POINTER)fullKey, 0, sizeof (*fullKey)); - if (modulus != (ITEM *)NULL_PTR) - fullKey->modulus = *modulus; - if (publicExponent != (ITEM *)NULL_PTR) - fullKey->publicExponent = *publicExponent; - if (privateExponent != (ITEM *)NULL_PTR) - fullKey->privateExponent = *privateExponent; - if (primes != (ITEM *)NULL_PTR) { - fullKey->prime[0] = primes[0]; - fullKey->prime[1] = primes[1]; - } - if (primeExponents != (ITEM *)NULL_PTR) { - fullKey->primeExponent[0] = primeExponents[0]; - fullKey->primeExponent[1] = primeExponents[1]; - } - if (coefficient != (ITEM *)NULL_PTR) - fullKey->coefficient = *coefficient; - - return (B_InfoCacheAddInfo - (&key->infoCache, (POINTER)&KITFullPrivate, (POINTER)fullKey)); -} - -/* Select the key object's full private key and set all of the supplied - fields which are not (ITEM *)NULL_PTR. - primes and primeExponents point to a 2 entry ITEM array. - If one of the fields is not (ITEM *)NULL_PTR, but the full key's - field is null, return BE_WRONG_KEY_INFO. - */ -int GetFullPrivateKeyInfo - (modulus, publicExponent, privateExponent, primes, primeExponents, - coefficient, key) -ITEM *modulus; -ITEM *publicExponent; -ITEM *privateExponent; -ITEM *primes; -ITEM *primeExponents; -ITEM *coefficient; -B_Key *key; -{ - FULL_PRIVATE_KEY *fullKey; - int status; - - if ((status = B_KeyGetInfo - (key, (POINTER *)&fullKey, &KITFullPrivate)) != 0) - return (status); - - if (modulus != (ITEM *)NULL_PTR) { - if (fullKey->modulus.data == (unsigned char *)NULL_PTR) - return (BE_WRONG_KEY_INFO); - *modulus = fullKey->modulus; - } - if (publicExponent != (ITEM *)NULL_PTR) { - if (fullKey->publicExponent.data == (unsigned char *)NULL_PTR) - return (BE_WRONG_KEY_INFO); - *publicExponent = fullKey->publicExponent; - } - if (privateExponent != (ITEM *)NULL_PTR) { - if (fullKey->privateExponent.data == (unsigned char *)NULL_PTR) - return (BE_WRONG_KEY_INFO); - *privateExponent = fullKey->privateExponent; - } - if (primes != (ITEM *)NULL_PTR) { - if (fullKey->prime[0].data == (unsigned char *)NULL_PTR || - fullKey->prime[1].data == (unsigned char *)NULL_PTR) - return (BE_WRONG_KEY_INFO); - primes[0] = fullKey->prime[0]; - primes[1] = fullKey->prime[1]; - } - if (primeExponents != (ITEM *)NULL_PTR) { - if (fullKey->primeExponent[0].data == (unsigned char *)NULL_PTR || - fullKey->primeExponent[1].data == (unsigned char *)NULL_PTR) - return (BE_WRONG_KEY_INFO); - primeExponents[0] = fullKey->primeExponent[0]; - primeExponents[1] = fullKey->primeExponent[1]; - } - if (coefficient != (ITEM *)NULL_PTR) { - if (fullKey->coefficient.data == (unsigned char *)NULL_PTR) - return (BE_WRONG_KEY_INFO); - *coefficient = fullKey->coefficient; - } - - return (0); -} - -/* This is not intended to be called from B_SetKeyInfo. - Get returns BE_WRONG_KEY_INFO. - */ -static int KITFullPrivateKeyAddInfo (key, info) -B_Key *key; -POINTER info; -{ -UNUSED_ARG (key) -UNUSED_ARG (info) - return (BE_ALG_OPERATION_UNKNOWN); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/kifulprv.h b/usr/src/lib/libresolv2/common/dnssafe/kifulprv.h deleted file mode 100644 index 55cdd8c666..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/kifulprv.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -int CacheFullPrivateKey PROTO_LIST - ((B_Key *, ITEM *, ITEM *, ITEM *, ITEM *, ITEM *, ITEM *)); -int GetFullPrivateKeyInfo PROTO_LIST - ((ITEM *, ITEM *, ITEM *, ITEM *, ITEM *, ITEM *, B_Key *)); diff --git a/usr/src/lib/libresolv2/common/dnssafe/kiitem.c b/usr/src/lib/libresolv2/common/dnssafe/kiitem.c deleted file mode 100644 index 3aaa80f358..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/kiitem.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "kinfotyp.h" -#include "kiitem.h" -#include "port_after.h" - -int KITItemAddInfo PROTO_LIST ((B_Key *, POINTER)); - -B_KeyInfoType KITItem = {KITItemAddInfo, B_KeyInfoTypeMakeError}; - -int KI_Item (keyInfoType) -POINTER *keyInfoType; -{ - *keyInfoType = (POINTER)&KITItem; - - /* Return 1 to indicate a KeyInfoType, not an AlgorithmInfoType */ - return (1); -} - -/* info is an ITEM. The ITEM's data is copied into the object. - */ -int KITItemAddInfo (key, info) -B_Key *key; -POINTER info; -{ - unsigned char *newData; - int status; - - if ((status = B_MemoryPoolAllocAndCopy - (&key->infoCache.memoryPool, (POINTER *)&newData, - (POINTER)((ITEM *)info)->data, ((ITEM *)info)->len)) != 0) - return (status); - - return (B_KeyAddItemInfo (key, newData, ((ITEM *)info)->len)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/kiitem.h b/usr/src/lib/libresolv2/common/dnssafe/kiitem.h deleted file mode 100644 index ad0863722f..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/kiitem.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -extern B_KeyInfoType KITItem; diff --git a/usr/src/lib/libresolv2/common/dnssafe/kinfotyp.c b/usr/src/lib/libresolv2/common/dnssafe/kinfotyp.c deleted file mode 100644 index fba31dc2ba..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/kinfotyp.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "kinfotyp.h" -#include "port_after.h" - -/* This is the default routine which key info types can point MakeInfo to. - */ -int B_KeyInfoTypeMakeError (info, key) -POINTER *info; -B_Key *key; -{ -UNUSED_ARG (info) -UNUSED_ARG (key) - - /* Should already have been found in the cache. */ - return (BE_WRONG_KEY_INFO); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/kinfotyp.h b/usr/src/lib/libresolv2/common/dnssafe/kinfotyp.h deleted file mode 100644 index 8de4f5e883..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/kinfotyp.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -typedef int (*KIT_ADD_INFO) PROTO_LIST ((B_Key *, POINTER)); -typedef int (*KIT_MAKE_INFO) PROTO_LIST ((POINTER *, B_Key *)); - -/* The definition in C++ is: - class B_KeyInfoType { - public: - B_KeyInfoType (KIT_ADD_INFO AddInfo) { - _AddInfo = AddInfo; - _MakeInfo = KeyInfoType::makeError;} - B_KeyInfoType (KIT_ADD_INFO AddInfo, KIT_MAKE_INFO MakeInfo) { - _AddInfo = AddInfo; - _MakeInfo = MakeInfo;} - - int addInfo (B_Key *key, POINTER info) {return (*_AddInfo) (key, info);} - int makeInfo (POINTER *info, B_Key *key) {return (*_MakeInfo) (info, key);} - - static int makeError (POINTER *info, B_Key *key); - - private: - KIT_ADD_INFO _AddInfo; - KIT_MAKE_INFO _MakeInfo; - }; - - Note that a derived class simply calls one of the B_KeyInfoType constructors - which set the addInfo or both the addInfo and makeInfo callbacks. - There is no need for an extra level involving virtual functions because - each key class only has one instance, making a V table a waste of space. - An example of a derived class is: - - class KITItem : public B_KeyInfoType { - public: - // Set addInfo and leave makeInfo as B_KeyInfoType::makeError - KITItem () : B_KeyInfoType (KITItem::addInfo) {}; - - static int addInfo (B_Key *key, POINTER info); - }; - - - There is one global instance which is used by B_Key::setInfo, etc.: - - KITItem KITItem; - */ - -typedef struct B_KeyInfoType { - KIT_ADD_INFO AddInfo; - KIT_MAKE_INFO MakeInfo; -} B_KeyInfoType; - -int B_KeyInfoTypeMakeError PROTO_LIST ((POINTER *, B_Key *)); diff --git a/usr/src/lib/libresolv2/common/dnssafe/kipkcrpr.c b/usr/src/lib/libresolv2/common/dnssafe/kipkcrpr.c deleted file mode 100644 index e0d3ff523e..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/kipkcrpr.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "kinfotyp.h" -#include "intitem.h" -#include "kifulprv.h" -#include "kipkcrpr.h" -#include "port_after.h" - -B_KeyInfoType KIT_PKCS_RSAPrivate = - {KIT_PKCS_RSAPrivateAddInfo, KIT_PKCS_RSAPrivateMakeInfo}; - -static A_PKCS_RSA_PRIVATE_KEY STATIC_PKCS_RSA_PRIVATE_KEY; -static ITEM *PKCS_RSA_PRIVATE_KEY_ITEMS[] = { - &STATIC_PKCS_RSA_PRIVATE_KEY.modulus, - &STATIC_PKCS_RSA_PRIVATE_KEY.publicExponent, - &STATIC_PKCS_RSA_PRIVATE_KEY.privateExponent, - &STATIC_PKCS_RSA_PRIVATE_KEY.prime[0], - &STATIC_PKCS_RSA_PRIVATE_KEY.prime[1], - &STATIC_PKCS_RSA_PRIVATE_KEY.primeExponent[0], - &STATIC_PKCS_RSA_PRIVATE_KEY.primeExponent[1], - &STATIC_PKCS_RSA_PRIVATE_KEY.coefficient -}; - -int KI_PKCS_RSAPrivate (keyInfoType) -POINTER *keyInfoType; -{ - *keyInfoType = (POINTER)&KIT_PKCS_RSAPrivate; - - /* Return 1 to indicate a KeyInfoType, not an AlgorithmInfoType */ - return (1); -} - -int KIT_PKCS_RSAPrivateAddInfo (key, info) -B_Key *key; -POINTER info; -{ - A_PKCS_RSA_PRIVATE_KEY *newValue; - int status; - - /* Allocate memory for A_PKCS_RSA_PRIVATE_KEY struct and copy integers - from supplied value. - */ - if ((status = B_MemoryPoolAlloc - (&key->infoCache.memoryPool, (POINTER *)&newValue, - sizeof (A_PKCS_RSA_PRIVATE_KEY))) != 0) - return (status); - if ((status = AllocAndCopyIntegerItems - ((POINTER)newValue, info, (POINTER)&STATIC_PKCS_RSA_PRIVATE_KEY, - PKCS_RSA_PRIVATE_KEY_ITEMS, sizeof (PKCS_RSA_PRIVATE_KEY_ITEMS) / - sizeof (PKCS_RSA_PRIVATE_KEY_ITEMS[0]), &key->infoCache.memoryPool)) - != 0) - return (status); - - /* Cache the full private key info. - */ - if ((status = CacheFullPrivateKey - (key, &newValue->modulus, &newValue->publicExponent, - &newValue->privateExponent, newValue->prime, newValue->primeExponent, - &newValue->coefficient)) != 0) - return (status); - return (B_InfoCacheAddInfo - (&key->infoCache, (POINTER)&KIT_PKCS_RSAPrivate, (POINTER)newValue)); -} - -int KIT_PKCS_RSAPrivateMakeInfo (info, key) -POINTER *info; -B_Key *key; -{ - A_PKCS_RSA_PRIVATE_KEY keyValue; - int status; - - /* If not already found in the cache, try to get values from - a full private key info. - */ - if ((status = GetFullPrivateKeyInfo - (&keyValue.modulus, &keyValue.publicExponent, - &keyValue.privateExponent, keyValue.prime, keyValue.primeExponent, - &keyValue.coefficient, key)) != 0) - return (status); - - /* Got all the needed fields, so allocate memory for a new - A_PKCS_RSA_PRIVATE_KEY struct and copy the key value. - */ - if ((status = B_MemoryPoolAlloc - (&key->infoCache.memoryPool, info, sizeof (A_PKCS_RSA_PRIVATE_KEY))) - != 0) - return (status); - - **(A_PKCS_RSA_PRIVATE_KEY **)info = keyValue; - return (0); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/kipkcrpr.h b/usr/src/lib/libresolv2/common/dnssafe/kipkcrpr.h deleted file mode 100644 index f61de3ce97..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/kipkcrpr.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -extern B_KeyInfoType KIT_PKCS_RSAPrivate; - -int KIT_PKCS_RSAPrivateAddInfo PROTO_LIST ((B_Key *, POINTER)); -int KIT_PKCS_RSAPrivateMakeInfo PROTO_LIST ((POINTER *, B_Key *)); - diff --git a/usr/src/lib/libresolv2/common/dnssafe/kirsacrt.c b/usr/src/lib/libresolv2/common/dnssafe/kirsacrt.c deleted file mode 100644 index 269724d7e8..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/kirsacrt.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "kinfotyp.h" -#include "intitem.h" -#include "kifulprv.h" -#include "port_after.h" - -#define NULL_UCHAR_PTR ((unsigned char *)NULL_PTR) - -int KIT_RSA_CRTAddInfo PROTO_LIST ((B_Key *, POINTER)); -int KIT_RSA_CRTMakeInfo PROTO_LIST ((POINTER *, B_Key *)); - -B_KeyInfoType KIT_RSA_CRT = {KIT_RSA_CRTAddInfo, KIT_RSA_CRTMakeInfo}; - -static A_RSA_CRT_KEY STATIC_RSA_CRT_KEY; -static ITEM *RSA_CRT_KEY_ITEMS[] = { - &STATIC_RSA_CRT_KEY.modulus, &STATIC_RSA_CRT_KEY.prime[0], - &STATIC_RSA_CRT_KEY.prime[1], - &STATIC_RSA_CRT_KEY.primeExponent[0], - &STATIC_RSA_CRT_KEY.primeExponent[1], - &STATIC_RSA_CRT_KEY.coefficient -}; - -/* args points to A_RSA_CRT_KEY. - */ -int KI_RSA_CRT (keyInfoType) -POINTER *keyInfoType; -{ - *keyInfoType = (POINTER)&KIT_RSA_CRT; - - /* Return 1 to indicate a KeyInfoType, not an AlgorithmInfoType */ - return (1); -} - -int KIT_RSA_CRTAddInfo (key, info) -B_Key *key; -POINTER info; -{ - A_RSA_CRT_KEY *newValue; - int status; - - /* Allocate memory for A_RSA_CRT_KEY struct and copy integers - from supplied value. - */ - if ((status = B_MemoryPoolAlloc - (&key->infoCache.memoryPool, (POINTER *)&newValue, - sizeof (A_RSA_CRT_KEY))) != 0) - return (status); - if ((status = AllocAndCopyIntegerItems - ((POINTER)newValue, info, (POINTER)&STATIC_RSA_CRT_KEY, - RSA_CRT_KEY_ITEMS, - sizeof (RSA_CRT_KEY_ITEMS) / sizeof (RSA_CRT_KEY_ITEMS[0]), - &key->infoCache.memoryPool)) != 0) - return (status); - - /* Cache the full private key info, setting unused fields to NULL. - */ - if ((status = CacheFullPrivateKey - (key, &newValue->modulus, (ITEM *)NULL_PTR, (ITEM *)NULL_PTR, - newValue->prime, newValue->primeExponent, &newValue->coefficient)) - != 0) - return (status); - return (B_InfoCacheAddInfo - (&key->infoCache, (POINTER)&KIT_RSA_CRT, (POINTER)newValue)); -} - -int KIT_RSA_CRTMakeInfo (info, key) -POINTER *info; -B_Key *key; -{ - A_RSA_CRT_KEY keyValue; - int status; - - /* If not already found in the cache, try to get values from - a full private key info, setting unneeded entries to NULL. - */ - if ((status = GetFullPrivateKeyInfo - (&keyValue.modulus, (ITEM *)NULL_PTR, (ITEM *)NULL_PTR, - keyValue.prime, keyValue.primeExponent, &keyValue.coefficient, - key)) != 0) - return (status); - - /* Got all the needed fields, so allocate memory for a new - A_RSA_CRT_KEY struct and copy the key value. - */ - if ((status = B_MemoryPoolAlloc - (&key->infoCache.memoryPool, info, sizeof (A_RSA_CRT_KEY))) != 0) - return (status); - - **(A_RSA_CRT_KEY **)info = keyValue; - return (0); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/kirsapub.c b/usr/src/lib/libresolv2/common/dnssafe/kirsapub.c deleted file mode 100644 index 22baff948b..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/kirsapub.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "kinfotyp.h" -#include "intitem.h" -#include "kifulprv.h" -#include "kirsapub.h" -#include "port_after.h" - -B_KeyInfoType KIT_RSAPublic = - {KIT_RSAPublicAddInfo, KIT_RSAPublicMakeInfo}; - -static A_RSA_KEY STATIC_RSA_KEY; -static ITEM *RSA_KEY_ITEMS[] = - {&STATIC_RSA_KEY.modulus, &STATIC_RSA_KEY.exponent}; - -int KI_RSAPublic (keyInfoType) -POINTER *keyInfoType; -{ - *keyInfoType = (POINTER)&KIT_RSAPublic; - - /* Return 1 to indicate a KeyInfoType, not an AlgorithmInfoType */ - return (1); -} - -int KIT_RSAPublicAddInfo (key, info) -B_Key *key; -POINTER info; -{ - POINTER newValue; - int status; - - /* Allocate memory for A_RSA_KEY struct and copy integers - from supplied value. - */ - if ((status = B_MemoryPoolAlloc - (&key->infoCache.memoryPool, &newValue, sizeof (A_RSA_KEY))) != 0) - return (status); - if ((status = AllocAndCopyIntegerItems - (newValue, info, (POINTER)&STATIC_RSA_KEY, RSA_KEY_ITEMS, - sizeof (RSA_KEY_ITEMS) / sizeof (RSA_KEY_ITEMS[0]), - &key->infoCache.memoryPool)) != 0) - return (status); - - return (B_InfoCacheAddInfo - (&key->infoCache, (POINTER)&KIT_RSAPublic, newValue)); -} - -int KIT_RSAPublicMakeInfo (info, key) -POINTER *info; -B_Key *key; -{ - A_RSA_KEY keyValue; - int status; - - /* If not already found in the cache, try to get values from - a full private key info, setting unneeded entries to NULL. - */ - if ((status = GetFullPrivateKeyInfo - (&keyValue.modulus, &keyValue.exponent, (ITEM *)NULL_PTR, - (ITEM *)NULL_PTR, (ITEM *)NULL_PTR, (ITEM *)NULL_PTR, key)) != 0) - return (status); - - /* Got all the needed fields, so allocate memory for a new - A_RSA_KEY struct and copy the key value. - */ - if ((status = B_MemoryPoolAlloc - (&key->infoCache.memoryPool, info, sizeof (A_RSA_KEY))) != 0) - return (status); - - **(A_RSA_KEY **)info = keyValue; - return (0); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/kirsapub.h b/usr/src/lib/libresolv2/common/dnssafe/kirsapub.h deleted file mode 100644 index 0e26eb3666..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/kirsapub.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1993, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -extern B_KeyInfoType KIT_RSAPublic; - -int KIT_RSAPublicAddInfo PROTO_LIST ((B_Key *, POINTER)); -int KIT_RSAPublicMakeInfo PROTO_LIST ((POINTER *, B_Key *)); - diff --git a/usr/src/lib/libresolv2/common/dnssafe/md5.h b/usr/src/lib/libresolv2/common/dnssafe/md5.h deleted file mode 100644 index 1a1c963a61..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/md5.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1994, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _MD5_H_ -#define _MD5_H_ 1 - -#ifdef __cplusplus -extern "C" { -#endif - -#define A_MD5_DIGEST_LEN 16 - -#ifndef SUNW_LIBMD5 - -typedef struct { - UINT4 state[4]; /* state (ABCD) */ - UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ - unsigned char buffer[64]; /* input buffer */ -} A_MD5_CTX; - -void A_MD5Init PROTO_LIST ((A_MD5_CTX *)); -void A_MD5Update PROTO_LIST ((A_MD5_CTX *, const unsigned char *, unsigned int)); -void A_MD5Final PROTO_LIST ((A_MD5_CTX *, unsigned char *)); - -#else - -#include <sys/md5.h> -#define A_MD5_CTX MD5_CTX -#define A_MD5Init(c) MD5Init((c)) -#define A_MD5Update(c, d, l) MD5Update((c), (d), (l)) -#define A_MD5Final(c, d) MD5Final((d), (c)) - -#endif /* SUNW_LIBMD5 */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/md5rand.c b/usr/src/lib/libresolv2/common/dnssafe/md5rand.c deleted file mode 100644 index d8e910ec15..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/md5rand.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1994, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -/* Define this so that the type of the 'this' pointer in the - virtual functions will be correct for this derived class. - */ -struct A_MD5_RANDOM_CTX; -#define THIS_DIGEST_RANDOM struct A_MD5_RANDOM_CTX - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "md5rand.h" -#include "port_after.h" - -static void A_MD5RandomDigestUpdate PROTO_LIST - ((A_MD5_RANDOM_CTX *, unsigned char *, unsigned int)); -static void A_MD5RandomDigestFinal PROTO_LIST - ((A_MD5_RANDOM_CTX *, unsigned char *)); - -static A_DigestRandomVTable V_TABLE = - {A_MD5RandomDigestUpdate, A_MD5RandomDigestFinal}; - -void A_MD5RandomInit (context) -A_MD5_RANDOM_CTX *context; -{ - /* Initialize "base class" */ - A_DigestRandomInit - (&context->digestRandom, A_MD5_DIGEST_LEN, context->state); - - /* Initialize digest algorithm and set vTable. - */ - A_MD5Init (&context->md5Context); - context->digestRandom.vTable = &V_TABLE; -} - -void A_MD5RandomUpdate (context, input, inputLen) -A_MD5_RANDOM_CTX *context; -unsigned char *input; -unsigned int inputLen; -{ - A_DigestRandomUpdate (&context->digestRandom, input, inputLen); -} - -void A_MD5RandomGenerateBytes (context, output, outputLen) -A_MD5_RANDOM_CTX *context; -unsigned char *output; -unsigned int outputLen; -{ - A_DigestRandomGenerateBytes (&context->digestRandom, output, outputLen); -} - -static void A_MD5RandomDigestUpdate (context, input, inputLen) -A_MD5_RANDOM_CTX *context; -unsigned char *input; -unsigned int inputLen; -{ - A_MD5Update (&context->md5Context, input, inputLen); -} - -static void A_MD5RandomDigestFinal (context, digest) -A_MD5_RANDOM_CTX *context; -unsigned char *digest; -{ - A_MD5Final (&context->md5Context, digest); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/md5rand.h b/usr/src/lib/libresolv2/common/dnssafe/md5rand.h deleted file mode 100644 index a181e147d7..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/md5rand.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1994, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _MD5RAND_H_ -#define _MD5RAND_H_ 1 - -#include "digrand.h" -#include "md5.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct A_MD5_RANDOM_CTX { - A_DigestRandom digestRandom; /* "base class" */ - - unsigned char state[3 * A_MD5_DIGEST_LEN]; - A_MD5_CTX md5Context; -} A_MD5_RANDOM_CTX; - -void A_MD5RandomInit PROTO_LIST ((A_MD5_RANDOM_CTX *)); -void A_MD5RandomUpdate PROTO_LIST - ((A_MD5_RANDOM_CTX *, unsigned char *, unsigned int)); -void A_MD5RandomGenerateBytes PROTO_LIST - ((A_MD5_RANDOM_CTX *, unsigned char *, unsigned int)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/prime.c b/usr/src/lib/libresolv2/common/dnssafe/prime.c deleted file mode 100644 index a1819813f7..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/prime.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "bigmath.h" -#include "prime.h" -#include "port_after.h" - -static unsigned char SMALL_PRIME[]= {3, 5, 7, 11, 13, 17, 19, 23, 29, 31}; - -/* Prime finding routine. - Returns 0, AE_CANCEL, AE_NEED_RANDOM. - */ -int PrimeFind - (prime, primeSizeBits, primeWords, ee, modulusWords, randomBlock, - surrenderContext) -UINT2 *prime; -unsigned int primeSizeBits; -unsigned int primeWords; -UINT2 *ee; -unsigned int modulusWords; -unsigned char *randomBlock; -A_SURRENDER_CTX *surrenderContext; -{ - UINT2 t1[MAX_RSA_MODULUS_WORDS], u1[MAX_RSA_MODULUS_WORDS], - u2[MAX_RSA_MODULUS_WORDS], u3[MAX_RSA_MODULUS_WORDS], - u4[MAX_RSA_MODULUS_WORDS]; - char sieve[1000]; - int status = 0; - unsigned int i, r, s, testResult; - - do { - /* Create a starting point for the prime from the random block */ - for (i = 0; i < primeWords; i++) { - prime[i] = (UINT2)((UINT2)randomBlock[0] << 8) + randomBlock[1]; - randomBlock += 2; - } - - /* set high order two bits */ - BigSetbit (prime, primeSizeBits-2); - BigSetbit (prime, primeSizeBits-1); - for (i = primeSizeBits; i < (unsigned int)(16 * primeWords); i++) - BigClrbit (prime, i); - - /* force p to be even */ - BigClrbit (prime, 0); - - /* clear sieve and mark even positions */ - for (i = 0; i < 1000; i += 2) { - sieve[i] = 1; - sieve[i+1] = 0; - } - - /* sieve by all odd numbers (don't bother with primality checking) */ - for (s = 3; s < 9000; s += 2) { - /* increase likelihood that s is prime */ - for (i = 0; i < 5; i++) - if (s > SMALL_PRIME[i] && !(s % SMALL_PRIME[i])) - continue; - - /* sieve based on s */ - r = BigSmod (prime, s, primeWords); - - /* returns prime modulo s */ - if (r == 0) - r = s; - - for (i = s - r; i < 1000; i += s) - sieve[i] = 1; - } - - /* t1 = 1 */ - BigConst (t1, 1, modulusWords); - - /* now check for primality of values with unmarked sieve */ - testResult = 0; - for (i = 0; i < 1000; i++, BigInc (prime, primeWords)) { - if (sieve[i]) - continue; - - /* copy prime into big variable */ - BigZero (u4, modulusWords); - BigCopy (u4, prime, primeWords); - - /* set u4 = p - 1 */ - BigDec (u4, modulusWords); - BigPegcd (u1, u2, u3, ee, u4, modulusWords); - - /* Now u1 = gcd (E, t1). - Test (E, t1)==1 */ - if (BigCmp (t1, u1, modulusWords)) - continue; - - /* check for pseudo primality */ - if ((status = PseudoPrime - (&testResult, prime, primeWords, surrenderContext)) != 0) - break; - if (testResult) - /* testResult is set and will cause a break out of while (1) loop */ - break; - } - if (status) - break; - - if (!testResult) - /* Couldn't find a prime with the supplied random block, so ask - caller to generate another random block and try again. */ - status = AE_NEED_RANDOM; - } while (0); - - T_memset ((POINTER)u1, 0, sizeof (u1)); - T_memset ((POINTER)u2, 0, sizeof (u2)); - T_memset ((POINTER)u3, 0, sizeof (u3)); - T_memset ((POINTER)u4, 0, sizeof (u4)); - return (status); -} - -/* Pseudo-primality test. - If pseudo prime, *testResult = 1, else *testResult = 0. - Returns 0, AE_CANCEL. - */ -int PseudoPrime (testResult, prime, primeWords, surrenderContext) -unsigned int *testResult; -UINT2 *prime; -unsigned int primeWords; -A_SURRENDER_CTX *surrenderContext; -{ - UINT2 base[MAX_RSA_MODULUS_WORDS], remainder[MAX_RSA_MODULUS_WORDS]; - int status; - unsigned int i; - - /* Default testResult to false. */ - *testResult = 0; - - /* Prepare for setting base vector to the small prime. */ - T_memset ((POINTER)base, 0, sizeof (base)); - - for (i = 0; i < 4; i++) { - /* check to see if target is multiple of SMALL_PRIME */ - if (BigSmod (prime, (unsigned int)SMALL_PRIME[i], primeWords) == 0) - /* fail... */ - return (0); - - /* Fermat test. Compute remainder = base ^ prime mod prime - and compare the base to the remainder. - */ - base[0] = (UINT2)SMALL_PRIME[i]; - if ((status = BigModExp - (remainder, base, prime, prime, primeWords, surrenderContext)) != 0) - return (status); - if (BigCmp (remainder, base, primeWords) != 0) - /* fail... */ - return (0); - } - - *testResult = 1; - return (0); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/prime.h b/usr/src/lib/libresolv2/common/dnssafe/prime.h deleted file mode 100644 index 4d94667a3e..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/prime.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _PRIME_H_ -#define _PRIME_H_ 1 - -#ifdef __cplusplus -extern "C" { -#endif - -int PrimeFind PROTO_LIST - ((UINT2 *, unsigned int, unsigned int, UINT2 *, unsigned int, - unsigned char *, A_SURRENDER_CTX *)); -int PseudoPrime PROTO_LIST - ((unsigned int *, UINT2 *, unsigned int, A_SURRENDER_CTX *)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/random.c b/usr/src/lib/libresolv2/common/dnssafe/random.c deleted file mode 100644 index 8126b76926..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/random.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "bsafe2.h" -#include "bkey.h" -#include "balg.h" -#include "ainfotyp.h" -#include "algobj.h" -#include "port_after.h" - -int B_RandomInit - (algorithmObject, algorithmChooser, surrenderContext) -B_ALGORITHM_OBJ algorithmObject; -B_ALGORITHM_CHOOSER algorithmChooser; -A_SURRENDER_CTX *surrenderContext; -{ - if (AlgorithmWrapCheck (THE_ALG_WRAP) != 0) - /* Assume error is B_ALGORITHM_OBJ */ - return (BE_RANDOM_OBJ); - - return (B_AlgorithmRandomInit - (&THE_ALG_WRAP->algorithm, algorithmChooser, surrenderContext)); -} - -int B_RandomUpdate (algorithmObject, input, inputLen, surrenderContext) -B_ALGORITHM_OBJ algorithmObject; -unsigned char *input; -unsigned int inputLen; -A_SURRENDER_CTX *surrenderContext; -{ - if (AlgorithmWrapCheck (THE_ALG_WRAP) != 0) - /* Assume error is B_ALGORITHM_OBJ */ - return (BE_RANDOM_OBJ); - - return (B_AlgorithmRandomUpdate - (&THE_ALG_WRAP->algorithm, input, inputLen, surrenderContext)); -} - -int B_GenerateRandomBytes - (algorithmObject, output, outputLen, surrenderContext) -B_ALGORITHM_OBJ algorithmObject; -unsigned char *output; -unsigned int outputLen; -A_SURRENDER_CTX *surrenderContext; -{ - if (AlgorithmWrapCheck (THE_ALG_WRAP) != 0) - /* Assume error is B_ALGORITHM_OBJ */ - return (BE_RANDOM_OBJ); - - return (B_AlgorithmGenerateRandomBytes - (&THE_ALG_WRAP->algorithm, output, outputLen, surrenderContext)); -} - diff --git a/usr/src/lib/libresolv2/common/dnssafe/rsa.c b/usr/src/lib/libresolv2/common/dnssafe/rsa.c deleted file mode 100644 index 5aeea63ccb..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/rsa.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "rsa.h" -#include "bigmath.h" -#include "port_after.h" - -/* RSA encryption/decryption with full exponent. - */ - -#define GENERATE_BREAK(type) { \ - status = type; \ - break; \ - } - -static int RSA PROTO_LIST - ((A_RSA_CTX *, unsigned char *, unsigned int *, unsigned int, - const unsigned char *, A_SURRENDER_CTX *)); - -/* Returns 0, AE_MODULUS_LEN, AE_KEY_INFO. - */ -int A_RSAInit (context, key) -A_RSA_CTX *context; -A_RSA_KEY *key; -{ - if (A_IntegerBits (key->modulus.data, key->modulus.len) - > MAX_RSA_MODULUS_BITS) - /* Key size is too big to handle. */ - return (AE_MODULUS_LEN); - - /* Set the block update blockLen to be big enough to hold the modulus. */ - context->blockLen = - (A_IntegerBits (key->modulus.data, key->modulus.len) + 7) / 8; - - context->inputLen = 0; - - /* convert modulus to bignum representation */ - if (CanonicalToBig - (context->modulus, MAX_RSA_MODULUS_WORDS, key->modulus.data, - key->modulus.len)) - return (AE_KEY_INFO); - - /* compute significant length of modulus */ - context->modulusWords = BigLen - (context->modulus, MAX_RSA_MODULUS_WORDS) / 16 + 1; - - /* convert exponent to bignum representation */ - if (CanonicalToBig - (context->exponent, context->modulusWords, - key->exponent.data, key->exponent.len)) - return (AE_KEY_INFO); - - return (0); -} - -int A_RSAUpdate - (context, partOut, partOutLen, maxPartOutLen, partIn, partInLen, - surrenderContext) -A_RSA_CTX *context; -unsigned char *partOut; -unsigned int *partOutLen; -unsigned int maxPartOutLen; -const unsigned char *partIn; -unsigned int partInLen; -A_SURRENDER_CTX *surrenderContext; -{ - int status; - unsigned int partialLen, localPartOutLen; - - /* Initialize partOutLen to zero. */ - *partOutLen = 0; - - if (context->inputLen + partInLen < context->blockLen) { - /* Not enough to encrypt - just accumulate. - */ - T_memcpy - ((POINTER)(context->input + context->inputLen), (CPOINTER)partIn, - partInLen); - context->inputLen += partInLen; - return (0); - } - - if (context->inputLen > 0) { - /* Need to accumulate the rest of the block bytes into the input and - encrypt from there (otherwise it's OK to encrypt straight from - the partIn). - */ - partialLen = context->blockLen - context->inputLen; - T_memcpy - ((POINTER)(context->input + context->inputLen), (CPOINTER)partIn, - partialLen); - partIn += partialLen; - partInLen -= partialLen; - - if ((status = RSA - (context, partOut, &localPartOutLen, maxPartOutLen, context->input, - surrenderContext)) != 0) - return (status); - (*partOutLen) += localPartOutLen; - partOut += localPartOutLen; - maxPartOutLen -= localPartOutLen; - } - - /* Encrypt as many blocks of input as provided. - */ - while (partInLen >= context->blockLen) { - if ((status = RSA - (context, partOut, &localPartOutLen, maxPartOutLen, partIn, - surrenderContext)) != 0) - return (status); - - partIn += context->blockLen; - partInLen -= context->blockLen; - (*partOutLen) += localPartOutLen; - partOut += localPartOutLen; - maxPartOutLen -= localPartOutLen; - } - - /* Copy remaining input bytes to the context's input buffer. - */ - T_memcpy - ((POINTER)context->input, partIn, context->inputLen = partInLen); - return (0); -} - -int A_RSAFinal (context) -A_RSA_CTX *context; -{ - if (context->inputLen != 0) - return (AE_INPUT_LEN); - - /* Restart context to accumulate a new block. */ - context->inputLen = 0; - return (0); -} - -/* Assume input length is context->blockLen. - */ -static int RSA - (context, output, outputLen, maxOutputLen, input, surrenderContext) -A_RSA_CTX *context; -unsigned char *output; -unsigned int *outputLen; -unsigned int maxOutputLen; -const unsigned char *input; -A_SURRENDER_CTX *surrenderContext; -{ - struct ModExpFrame { - UINT2 bigInBuf[MAX_RSA_MODULUS_WORDS], bigOutBuf[MAX_RSA_MODULUS_WORDS]; - } *frame = (struct ModExpFrame *)NULL_PTR; -#if !USE_ALLOCED_FRAME - struct ModExpFrame stackFrame; -#endif - int status; - - status = 0; - do { - if ((*outputLen = context->blockLen) > maxOutputLen) - return (AE_OUTPUT_LEN); - -#if USE_ALLOCED_FRAME - if ((frame = (struct ModExpFrame *)T_malloc (sizeof (*frame))) - == (struct ModExpFrame *)NULL_PTR) { - status = AE_ALLOC; - break; - } -#else - /* Just use the buffers allocated on the stack. */ - frame = &stackFrame; -#endif - - /* Convert input to bignum representation. - This won't return AE_DATA since input length was checked at Update. - */ - CanonicalToBig - (frame->bigInBuf, context->modulusWords, input, context->blockLen); - - /* Check for overflow. */ - if (BigCmp (frame->bigInBuf, context->modulus, context->modulusWords) >= 0) - GENERATE_BREAK (AE_INPUT_DATA); - - /* Exponentiate. */ - if ((status = BigModExp - (frame->bigOutBuf, frame->bigInBuf, context->exponent, - context->modulus, context->modulusWords, surrenderContext)) != 0) - break; - - /* Convert output to canonical representation. - This won't return AE_DATA since outputLen was set above. - */ - BigToCanonical - (output, *outputLen, frame->bigOutBuf, context->modulusWords); - } while (0); - - if (frame != (struct ModExpFrame *)NULL_PTR) { - T_memset ((POINTER)frame, 0, sizeof (*frame)); -#if USE_ALLOCED_FRAME - T_free ((POINTER)frame); -#endif - } - - return (status); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/rsa.h b/usr/src/lib/libresolv2/common/dnssafe/rsa.h deleted file mode 100644 index 986af82afb..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/rsa.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1994, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _RSA_H_ -#define _RSA_H_ 1 - -#include "bigmaxes.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Note, these are only valid after a call to A_RSAInit. - */ -#define A_RSA_BLOCK_LEN(context) ((context)->blockLen) -#define A_RSA_MAX_OUTPUT_LEN(context, inputLen)\ - (inputLen) + (((inputLen) % (context)->blockLen) ?\ - (context)->blockLen - ((inputLen) % (context)->blockLen) : 0) - -typedef struct { - unsigned int blockLen; /* total size for the block to be computed */ - unsigned char input[MAX_RSA_MODULUS_LEN]; - unsigned int inputLen; - unsigned int modulusWords; - UINT2 modulus[MAX_RSA_MODULUS_WORDS]; - UINT2 exponent[MAX_RSA_MODULUS_WORDS]; -} A_RSA_CTX; - -int A_RSAInit PROTO_LIST ((A_RSA_CTX *, A_RSA_KEY *)); -int A_RSAUpdate PROTO_LIST - ((A_RSA_CTX *, unsigned char *, unsigned int *, unsigned int, - const unsigned char *, unsigned int, A_SURRENDER_CTX *)); -int A_RSAFinal PROTO_LIST ((A_RSA_CTX *)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/rsakeygn.c b/usr/src/lib/libresolv2/common/dnssafe/rsakeygn.c deleted file mode 100644 index 010c1e2414..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/rsakeygn.c +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "bigmath.h" -#include "surrendr.h" -#include "prime.h" -#include "rsakeygn.h" -#include "port_after.h" - -#define GENERATE_BREAK(type) { \ - status = type; \ - break; \ - } - -static int RSAParameters PROTO_LIST - ((UINT2 *, UINT2 *, UINT2 *, UINT2 *, UINT2 *, UINT2 *, UINT2 *, UINT2 *, - unsigned int, unsigned int, A_SURRENDER_CTX *)); -static void SetRSAKeyGenResult PROTO_LIST - ((A_PKCS_RSA_PRIVATE_KEY *, A_RSA_KEY_GEN_CTX *, UINT2 *, UINT2 *)); - -int A_RSAKeyGenInit (context, params) -A_RSA_KEY_GEN_CTX *context; -A_RSA_KEY_GEN_PARAMS *params; -{ - context->modulusBits = params->modulusBits; - - /* Prezeroize big public exponent vector. */ - T_memset - ((POINTER)context->bigPublicExponent, 0, - sizeof (context->bigPublicExponent)); - - /* Copy public exponent into big vector */ - if (CanonicalToBig - (context->bigPublicExponent, MAX_RSA_MODULUS_WORDS, - params->publicExponent.data, params->publicExponent.len) != 0) - /* could not copy exponent into MAX_RSA_MODULUS_WORDS */ - return (AE_EXPONENT_LEN); - - /* Check that public exponent is in bounds and odd. - */ - if (BigLen (context->bigPublicExponent, MAX_RSA_MODULUS_WORDS) >= - context->modulusBits) - return (AE_EXPONENT_LEN); - if (!(context->bigPublicExponent[0] & 1)) - return (AE_EXPONENT_EVEN); - - return (0); -} - -/* This generates an RSA keypair of size modulusBits with the fixed - publicExponent, pointing result to the resulting integers. The - resulting integer data is in the context, so that the values must be - copied before the context is zeroized. - All integers are unsigned canonical bytes arrays with the most significant - byte first. - The randomBlock is of length randomBlockLen returned by RSAKeyGenQuery. - This assumes that the modulusBits size was checked by RSAKeyGenQuery. - */ -int A_RSAKeyGen (context, result, randomBlock, surrenderContext) -A_RSA_KEY_GEN_CTX *context; -A_PKCS_RSA_PRIVATE_KEY **result; -unsigned char *randomBlock; -A_SURRENDER_CTX *surrenderContext; -{ - UINT2 *bigPrimeP, *bigPrimeQ; - int status; - unsigned int modulusWords, primeSizeBits, primeWords; - - /* Prezeroize all big word vectors. */ - T_memset ((POINTER)context->bigModulus, 0, sizeof (context->bigModulus)); - T_memset - ((POINTER)context->bigPrivateExponent, 0, - sizeof (context->bigPrivateExponent)); - T_memset ((POINTER)context->bigPrime1, 0, sizeof (context->bigPrime1)); - T_memset ((POINTER)context->bigPrime2, 0, sizeof (context->bigPrime2)); - T_memset ((POINTER)context->bigExponentP, 0, sizeof (context->bigExponentP)); - T_memset ((POINTER)context->bigExponentQ, 0, sizeof (context->bigExponentQ)); - T_memset - ((POINTER)context->bigCoefficient, 0, sizeof (context->bigCoefficient)); - - /* prime size is half modulus size */ - modulusWords = BITS_TO_WORDS (context->modulusBits); - primeSizeBits = RSA_PRIME_BITS (context->modulusBits); - primeWords = BITS_TO_WORDS (RSA_PRIME_BITS (context->modulusBits)); - - /* Fish for bigPrime1 and bigPrime2 that are compatible with supplied - publicExponent. - The randomBlock holds random bytes for two primes. - */ - if ((status = PrimeFind - (context->bigPrime1, primeSizeBits, primeWords, - context->bigPublicExponent, modulusWords, randomBlock, - surrenderContext)) != 0) - return (status); - if ((status = PrimeFind - (context->bigPrime2, context->modulusBits - primeSizeBits, - primeWords, context->bigPublicExponent, modulusWords, - randomBlock + (2 * primeWords), surrenderContext)) != 0) - return (status); - - /* Set bigPrimeP to the larger of bigPrime1 and bigPrime2 and set - bigPrimeQ to the smaller. - */ - if (BigCmp (context->bigPrime1, context->bigPrime2, primeWords) == 1) { - bigPrimeP = context->bigPrime1; - bigPrimeQ = context->bigPrime2; - } - else { - bigPrimeP = context->bigPrime2; - bigPrimeQ = context->bigPrime1; - } - - /* Calculate the rest of the key components */ - if ((status = RSAParameters - (context->bigModulus, context->bigCoefficient, - context->bigExponentP, context->bigExponentQ, - context->bigPrivateExponent, context->bigPublicExponent, - bigPrimeP, bigPrimeQ, primeWords, modulusWords, surrenderContext)) != 0) - return (status); - - /* Copy key components into canonical buffers which are at the - end of the context. */ - *result = &context->result; - SetRSAKeyGenResult (*result, context, bigPrimeP, bigPrimeQ); - - return (0); -} - -/* Assumes ee, pp, qq are given, calculates other parameters. - Returns 0, AE_CANCEL. - */ -static int RSAParameters - (nn, cr, dp, dq, dd, ee, pp, qq, primeWords, modulusWords, surrenderContext) -UINT2 *nn, *cr, *dp, *dq, *dd, *ee, *pp, *qq; -unsigned int primeWords, modulusWords; -A_SURRENDER_CTX *surrenderContext; -{ - UINT2 t1[2 * MAX_RSA_PRIME_WORDS], t2[MAX_RSA_PRIME_WORDS], - t3[MAX_RSA_MODULUS_WORDS], u1[MAX_RSA_MODULUS_WORDS], - u3[MAX_RSA_MODULUS_WORDS], pm1[MAX_RSA_PRIME_WORDS], - qm1[MAX_RSA_PRIME_WORDS]; - int status; - - do { - /* N=P*Q */ - BigMpy (t1, pp, qq, primeWords); - if ((status = CheckSurrender (surrenderContext)) != 0) - break; - BigCopy (nn, t1, modulusWords); - - /* qm1=q-1 & pm1=p-1 */ - BigConst (t1, 1, primeWords); - BigSub (qm1, qq, t1, primeWords); - BigSub (pm1, pp, t1, primeWords); - - /* t3=1 */ - BigConst (t3, 1, modulusWords); - - /*t1=phi (N) */ - BigMpy (t1, pm1, qm1, primeWords); - if ((status = CheckSurrender (surrenderContext)) != 0) - break; - - /* compute decryption exponent */ - BigPegcd (u1, dd, u3, ee, t1, modulusWords); - if ((status = CheckSurrender (surrenderContext)) != 0) - break; - - /* calc DP=inv (E)[mod (P-1)] & DQ=inv (e)[mod (Q-1)] */ - BigPdiv (t1, dp, dd, pm1, modulusWords, primeWords); - if ((status = CheckSurrender (surrenderContext)) != 0) - break; - BigPdiv (t1, dq, dd, qm1, modulusWords, primeWords); - if ((status = CheckSurrender (surrenderContext)) != 0) - break; - - /* calc CR = (inv (Q)[modP]) */ - BigPegcd (t1, t2, cr, pp, qq, primeWords); - } while (0); - - T_memset ((POINTER)t1, 0, sizeof (t1)); - T_memset ((POINTER)t2, 0, sizeof (t2)); - T_memset ((POINTER)t3, 0, sizeof (t3)); - T_memset ((POINTER)u1, 0, sizeof (u1)); - T_memset ((POINTER)u3, 0, sizeof (u3)); - T_memset ((POINTER)pm1, 0, sizeof (pm1)); - T_memset ((POINTER)qm1, 0, sizeof (qm1)); - return (status); -} - -static void SetRSAKeyGenResult (result, context, bigPrimeP, bigPrimeQ) -A_PKCS_RSA_PRIVATE_KEY *result; -A_RSA_KEY_GEN_CTX *context; -UINT2 *bigPrimeP; -UINT2 *bigPrimeQ; -{ - unsigned int primeLen, modulusLen; - - modulusLen = result->modulus.len = result->publicExponent.len = - result->privateExponent.len = BITS_TO_LEN (context->modulusBits); - primeLen = result->prime[0].len = result->prime[1].len = - result->primeExponent[0].len = result->primeExponent[1].len = - result->coefficient.len = RSA_PRIME_LEN (context->modulusBits); - - result->modulus.data = context->resultBuffer; - result->publicExponent.data = result->modulus.data + modulusLen; - result->privateExponent.data = result->publicExponent.data + modulusLen; - result->prime[0].data = result->privateExponent.data + modulusLen; - result->prime[1].data = result->prime[0].data + primeLen; - result->primeExponent[0].data = result->prime[1].data + primeLen; - result->primeExponent[1].data = result->primeExponent[0].data + primeLen; - result->coefficient.data = result->primeExponent[1].data + primeLen; - - BigToCanonical - (result->modulus.data, modulusLen, context->bigModulus, - MAX_RSA_MODULUS_WORDS); - BigToCanonical - (result->publicExponent.data, modulusLen, - context->bigPublicExponent, MAX_RSA_MODULUS_WORDS); - BigToCanonical - (result->privateExponent.data, modulusLen, - context->bigPrivateExponent, MAX_RSA_MODULUS_WORDS); - BigToCanonical - (result->prime[0].data, primeLen, bigPrimeP, MAX_RSA_PRIME_WORDS); - BigToCanonical - (result->prime[1].data, primeLen, bigPrimeQ, MAX_RSA_PRIME_WORDS); - BigToCanonical - (result->primeExponent[0].data, primeLen, context->bigExponentP, - MAX_RSA_PRIME_WORDS); - BigToCanonical - (result->primeExponent[1].data, primeLen, context->bigExponentQ, - MAX_RSA_PRIME_WORDS); - BigToCanonical - (result->coefficient.data, primeLen, context->bigCoefficient, - MAX_RSA_PRIME_WORDS); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/rsakeygn.h b/usr/src/lib/libresolv2/common/dnssafe/rsakeygn.h deleted file mode 100644 index 714bcea412..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/rsakeygn.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1994, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _RSAKEYGN_H_ -#define _RSAKEYGN_H_ 1 - -#include "bigmaxes.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MIN_RSA_MODULUS_BITS 256 - -/* Need randomBlock to hold bytes for two UINT2 prime number arrays each, - of length primeWords = BITS_TO_WORDS (RSA_PRIME_BITS (modulusBits)). */ -#define A_RSA_KEY_GEN_RANDOM_BLOCK_LEN(modulusBits) \ - (4 * BITS_TO_WORDS (RSA_PRIME_BITS (modulusBits))) - -/* Note that the scratch area for the output integers is allocated - in the context after the RSA_KEY_GEN_CTX. - */ -typedef struct { - unsigned int modulusBits; - UINT2 bigModulus[MAX_RSA_MODULUS_WORDS]; - UINT2 bigPublicExponent[MAX_RSA_MODULUS_WORDS]; - UINT2 bigPrivateExponent[MAX_RSA_MODULUS_WORDS]; - UINT2 bigPrime1[MAX_RSA_PRIME_WORDS]; - UINT2 bigPrime2[MAX_RSA_PRIME_WORDS]; - UINT2 bigExponentP[MAX_RSA_PRIME_WORDS]; - UINT2 bigExponentQ[MAX_RSA_PRIME_WORDS]; - UINT2 bigCoefficient[MAX_RSA_PRIME_WORDS]; - A_PKCS_RSA_PRIVATE_KEY result; - unsigned char resultBuffer - [3 * BITS_TO_LEN (MAX_RSA_MODULUS_BITS) + - 5 * RSA_PRIME_LEN (MAX_RSA_MODULUS_BITS)]; -} A_RSA_KEY_GEN_CTX; - -int A_RSAKeyGenInit PROTO_LIST ((A_RSA_KEY_GEN_CTX *, A_RSA_KEY_GEN_PARAMS *)); -int A_RSAKeyGen PROTO_LIST - ((A_RSA_KEY_GEN_CTX *, A_PKCS_RSA_PRIVATE_KEY **, unsigned char *, - A_SURRENDER_CTX *)); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/usr/src/lib/libresolv2/common/dnssafe/seccbcd.c b/usr/src/lib/libresolv2/common/dnssafe/seccbcd.c deleted file mode 100644 index b88d6f9438..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/seccbcd.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "secrcbc.h" -#include "port_after.h" - -static void SecretCBCDecryptBlock PROTO_LIST - ((POINTER, unsigned char *, SECRET_CRYPT, unsigned char *, - unsigned char *)); - -/* On first call, it is assumed that *remainderLen is zero. - This assumes remainder buffer is at least 16 bytes is size. - Returns AE_OUTPUT_LEN, 0. - */ -int SecretCBCDecryptUpdate - (context, xorBlock, remainder, remainderLen, SecretDecrypt, output, - outputLen, maxOutputLen, input, inputLen) -POINTER context; -unsigned char *xorBlock; -unsigned char *remainder; -unsigned int *remainderLen; -SECRET_CRYPT SecretDecrypt; -unsigned char *output; -unsigned int *outputLen; -unsigned int maxOutputLen; -unsigned char *input; -unsigned int inputLen; -{ - unsigned int partialLen; - - if (*remainderLen + inputLen <= 16) { - /* Not enough to decrypt, just accumulate into remainder. - */ - *outputLen = 0; - T_memcpy ((POINTER)remainder + *remainderLen, (POINTER)input, inputLen); - *remainderLen += inputLen; - return (0); - } - - /* Fill up the rest of the remainder with bytes from input. - */ - T_memcpy - ((POINTER)remainder + *remainderLen, (POINTER)input, - partialLen = 16 - *remainderLen); - input += partialLen; - inputLen -= partialLen; - - /* remainder is full and inputLen is at least 1. Compute outputLen - as the size needed to keep remainder as full as possible. - */ - if ((*outputLen = 8 * ((inputLen + 7) / 8)) > maxOutputLen) - return (AE_OUTPUT_LEN); - - SecretCBCDecryptBlock - (context, xorBlock, SecretDecrypt, output, remainder); - output += 8; - - if (inputLen <= 8) { - /* Shift remaining input bytes into remainder */ - T_memmove ((POINTER)remainder, (POINTER)(remainder + 8), 8); - T_memcpy ((POINTER)(remainder + 8), (POINTER)input, inputLen); - *remainderLen = 8 + inputLen; - return (0); - } - - /* Decrypt the rest of the remainder. - */ - SecretCBCDecryptBlock - (context, xorBlock, SecretDecrypt, output, remainder + 8); - output += 8; - - /* Now decrypt the bulk of the input. - */ - while (inputLen > 16) { - SecretCBCDecryptBlock (context, xorBlock, SecretDecrypt, output, input); - output += 8; - input += 8; - inputLen -= 8; - } - - /* inputLen is now <= 16, so copy input to remainder. - */ - T_memcpy ((POINTER)remainder, (POINTER)input, inputLen); - *remainderLen = inputLen; - return (0); -} - -/* The caller must restart the context (setting remainderLen to zero). - Returns AE_INPUT_LEN, AE_OUTPUT_LEN, 0. - */ -int SecretCBCDecryptFinal - (context, xorBlock, remainder, remainderLen, SecretDecrypt, output, - outputLen, maxOutputLen) -POINTER context; -unsigned char *xorBlock; -unsigned char *remainder; -unsigned int remainderLen; -SECRET_CRYPT SecretDecrypt; -unsigned char *output; -unsigned int *outputLen; -unsigned int maxOutputLen; -{ - if ((*outputLen = remainderLen) == 0) - /* There was never any data. */ - return (0); - - if (remainderLen != 8 && remainderLen != 16) - return (AE_INPUT_LEN); - - if (*outputLen > maxOutputLen) - return (AE_OUTPUT_LEN); - - SecretCBCDecryptBlock - (context, xorBlock, SecretDecrypt, output, remainder); - output += 8; - if (remainderLen == 16) - SecretCBCDecryptBlock - (context, xorBlock, SecretDecrypt, output, remainder + 8); - return (0); -} - -static void SecretCBCDecryptBlock (context, xorBlock, SecretDecrypt, out, in) -POINTER context; -unsigned char *xorBlock; -SECRET_CRYPT SecretDecrypt; -unsigned char *out; -unsigned char *in; -{ - unsigned char tempBuffer[8]; - unsigned int i; - - /* Save input to be copied to the xor block. */ - T_memcpy ((POINTER)tempBuffer, (POINTER)in, 8); - (*SecretDecrypt) (context, out, in); - for (i = 0; i < 8; i++) - out[i] ^= xorBlock[i]; - T_memcpy ((POINTER)xorBlock, (POINTER)tempBuffer, 8); - - T_memset ((POINTER)tempBuffer, 0, sizeof (tempBuffer)); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/seccbce.c b/usr/src/lib/libresolv2/common/dnssafe/seccbce.c deleted file mode 100644 index e388bd9c4b..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/seccbce.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "secrcbc.h" -#include "port_after.h" - -/* On first call, it is assumed that *remainderLen is zero. - Returns AE_OUTPUT_LEN, 0. - */ -int SecretCBCEncryptUpdate - (context, xorBlock, remainder, remainderLen, SecretEncrypt, output, - outputLen, maxOutputLen, input, inputLen) -POINTER context; -unsigned char *xorBlock; -unsigned char *remainder; -unsigned int *remainderLen; -SECRET_CRYPT SecretEncrypt; -unsigned char *output; -unsigned int *outputLen; -unsigned int maxOutputLen; -unsigned char *input; -unsigned int inputLen; -{ - unsigned int partialLen, totalLen, i; - - totalLen = *remainderLen + inputLen; - - /* Output length will be all available 8-byte blocks. - */ - if ((*outputLen = 8 * (totalLen / 8)) > maxOutputLen) - return (AE_OUTPUT_LEN); - - if (totalLen < 8) { - /* Not enough to encrypt, just accumulate into remainder. - */ - T_memcpy - ((POINTER)remainder + *remainderLen, (POINTER)input, inputLen); - *remainderLen = totalLen; - - return (0); - } - - /* Accumulate enough bytes from input into remainder to encrypt the - remainder. - */ - T_memcpy - ((POINTER)remainder + *remainderLen, (POINTER)input, - partialLen = 8 - *remainderLen); - - for (i = 0; i < 8; i++) - output[i] = remainder[i] ^ xorBlock[i]; - /* Encrypt in place */ - (*SecretEncrypt) (context, output, output); - - T_memcpy ((POINTER)xorBlock, (POINTER)output, 8); - input += partialLen; - inputLen -= partialLen; - output += 8; - - /* Now encrypt the bulk of the input. - */ - while (inputLen >= 8) { - for (i = 0; i < 8; i++) - output[i] = *(input++) ^ xorBlock[i]; - /* Encrypt in place */ - (*SecretEncrypt) (context, output, output); - T_memcpy ((POINTER)xorBlock, (POINTER)output, 8); - output += 8; - inputLen -= 8; - } - - /* inputLen is now < 8, so copy input to remainder. - */ - T_memcpy ((POINTER)remainder, (POINTER)input, inputLen); - *remainderLen = inputLen; - - return (0); -} - -/* This just ensures that *remainderLen is zero. - The caller must restart the context (setting remainderLen to zero). - Returns AE_INPUT_LEN, 0. - */ -int SecretCBCEncryptFinal (remainderLen) -unsigned int remainderLen; -{ - if (remainderLen != 0) - return (AE_INPUT_LEN); - - return (0); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/secrcbc.h b/usr/src/lib/libresolv2/common/dnssafe/secrcbc.h deleted file mode 100644 index 3eab2d5fe6..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/secrcbc.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1990, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _SECRCBC_H_ -#define _SECRCBC_H_ 1 - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void (*SECRET_CRYPT) PROTO_LIST - ((POINTER, unsigned char *, unsigned char *)); - -int SecretCBCEncryptUpdate PROTO_LIST - ((POINTER, unsigned char *, unsigned char *, unsigned int *, SECRET_CRYPT, - unsigned char *, unsigned int *, unsigned int, unsigned char *, - unsigned int)); -int SecretCBCEncryptFinal PROTO_LIST ((unsigned int)); -int SecretCBCDecryptUpdate PROTO_LIST - ((POINTER, unsigned char *, unsigned char *, unsigned int *, SECRET_CRYPT, - unsigned char *, unsigned int *, unsigned int, unsigned char *, - unsigned int)); -int SecretCBCDecryptFinal PROTO_LIST - ((POINTER, unsigned char *, unsigned char *, unsigned int, SECRET_CRYPT, - unsigned char *, unsigned int *, unsigned int)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/src/lib/libresolv2/common/dnssafe/surrendr.c b/usr/src/lib/libresolv2/common/dnssafe/surrendr.c deleted file mode 100644 index d353ee8de6..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/surrendr.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1992, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#include "port_before.h" -#include "global.h" -#include "algae.h" -#include "surrendr.h" -#include "port_after.h" - -/* Returns 0, AE_CANCEL. - */ -int CheckSurrender (surrenderContext) -A_SURRENDER_CTX *surrenderContext; -{ - if (surrenderContext == (A_SURRENDER_CTX *)NULL_PTR) - return (0); - - if ((*surrenderContext->Surrender) (surrenderContext->handle)) - return (AE_CANCEL); - return (0); -} diff --git a/usr/src/lib/libresolv2/common/dnssafe/surrendr.h b/usr/src/lib/libresolv2/common/dnssafe/surrendr.h deleted file mode 100644 index 4c18f1c543..0000000000 --- a/usr/src/lib/libresolv2/common/dnssafe/surrendr.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* Copyright (C) RSA Data Security, Inc. created 1992, 1996. This is an - unpublished work protected as such under copyright law. This work - contains proprietary, confidential, and trade secret information of - RSA Data Security, Inc. Use, disclosure or reproduction without the - express written authorization of RSA Data Security, Inc. is - prohibited. - */ - -#ifndef _SURRENDR_H_ -#define _SURRENDR_H_ 1 - -#ifdef __cplusplus -extern "C" { -#endif - -int CheckSurrender PROTO_LIST ((A_SURRENDER_CTX *)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/src/lib/libresolv2/common/dst/bsafe_link.c b/usr/src/lib/libresolv2/common/dst/bsafe_link.c deleted file mode 100644 index 8a9fbdf312..0000000000 --- a/usr/src/lib/libresolv2/common/dst/bsafe_link.c +++ /dev/null @@ -1,1128 +0,0 @@ -/* - * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#if defined(BSAFE) || defined(DNSSAFE) -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/bsafe_link.c,v 1.15 2001/09/25 04:50:28 marka Exp $"; - -/* - * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. - * - * Permission to use, copy modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND TRUSTED INFORMATION SYSTEMS - * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL - * TRUSTED INFORMATION SYSTEMS BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THE SOFTWARE. - */ -/* - * This file contains two components - * 1. Interface to the BSAFE library to allow compilation of Bind - * with TIS/DNSSEC when BSAFE is not available - * all calls to BSAFE are contained inside this file. - * 2. The glue to connvert RSA KEYS to and from external formats - */ -#include "port_before.h" - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#include <memory.h> -#include <sys/param.h> -#include <sys/time.h> -#include <netinet/in.h> -#include <arpa/nameser.h> -#include "dst_internal.h" - -# ifdef __STDC__ -# define PROTOTYPES 1 -# else -# define PROTOTYPES 0 -# endif - -# ifdef BSAFE -# include <aglobal.h> -# include <bsafe.h> -# else -# include <global.h> -# include <bsafe2.h> -# include <bigmaxes.h> -# endif - -#include "port_after.h" - -typedef struct bsafekey { - char *rk_signer; - B_KEY_OBJ rk_Private_Key; - B_KEY_OBJ rk_Public_Key; -} RSA_Key; - -#ifndef MAX_RSA_MODULUS_BITS -#define MAX_RSA_MODULUS_BITS 4096 -#define MAX_RSA_MODULUS_LEN (MAX_RSA_MODULUS_BITS/8) -#define MAX_RSA_PRIME_LEN (MAX_RSA_MODULUS_LEN/2) -#endif - -#define NULL_SURRENDER (A_SURRENDER_CTX *)NULL_PTR -#define NULL_RANDOM (B_ALGORITHM_OBJ)NULL_PTR - -B_ALGORITHM_METHOD *CHOOSER[] = -{ - &AM_MD5, - &AM_MD5_RANDOM, - &AM_RSA_KEY_GEN, - &AM_RSA_ENCRYPT, - &AM_RSA_DECRYPT, - &AM_RSA_CRT_ENCRYPT, - &AM_RSA_CRT_DECRYPT, - (B_ALGORITHM_METHOD *) NULL_PTR -}; - -static u_char pkcs1[] = -{ - 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, - 0x48, 0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, - 0x04, 0x10 -}; - -static int dst_bsafe_md5digest(const int mode, B_ALGORITHM_OBJ *digest_obj, - const u_char *data, const int len, - u_char *digest, const int digest_len); - -static int dst_bsafe_key_size(RSA_Key *r_key); - -static int dst_bsafe_sign(const int mode, DST_KEY *dkey, void **context, - const u_char *data, const int len, - u_char *signature, const int sig_len); -static int dst_bsafe_verify(const int mode, DST_KEY *dkey, void **context, - const u_char *data, const int len, - const u_char *signature, const int sig_len); -static int dst_bsafe_to_dns_key(const DST_KEY *in_key, u_char *out_str, - const int out_len); -static int dst_bsafe_from_dns_key(DST_KEY *s_key, const u_char *key, - const int len); -static int dst_bsafe_key_to_file_format(const DST_KEY *key, char *buff, - const int buff_len); -static int dst_bsafe_key_from_file_format(DST_KEY *d_key, - const char *buff, - const int buff_len); -static int dst_bsafe_generate_keypair(DST_KEY *key, int exp); -static int dst_bsafe_compare_keys(const DST_KEY *key1, const DST_KEY *key2); -static void *dst_bsafe_free_key_structure(void *key); - -/* - * dst_bsafe_init() Function to answer set up function pointers for - * BSAFE/DNSSAFE related functions - */ -int -dst_bsafe_init(void) -{ - if (dst_t_func[KEY_RSA] != NULL) - return (1); - dst_t_func[KEY_RSA] = malloc(sizeof(struct dst_func)); - if (dst_t_func[KEY_RSA] == NULL) - return (0); - memset(dst_t_func[KEY_RSA], 0, sizeof(struct dst_func)); - dst_t_func[KEY_RSA]->sign = dst_bsafe_sign; - dst_t_func[KEY_RSA]->verify = dst_bsafe_verify; - dst_t_func[KEY_RSA]->compare = dst_bsafe_compare_keys; - dst_t_func[KEY_RSA]->generate = dst_bsafe_generate_keypair; - dst_t_func[KEY_RSA]->destroy = dst_bsafe_free_key_structure; - dst_t_func[KEY_RSA]->from_dns_key = dst_bsafe_from_dns_key; - dst_t_func[KEY_RSA]->to_dns_key = dst_bsafe_to_dns_key; - dst_t_func[KEY_RSA]->from_file_fmt = dst_bsafe_key_from_file_format; - dst_t_func[KEY_RSA]->to_file_fmt = dst_bsafe_key_to_file_format; - return (1); -} - -/* - * dst_bsafe_sign - * Call BSAFE signing functions to sign a block of data. - * There are three steps to signing, INIT (initialize structures), - * UPDATE (hash (more) data), FINAL (generate a signature). This - * routine performs one or more of these steps. - * Parameters - * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL. - * dkey structure holds context for a sign done in multiple calls. - * context the context to use for this computation - * data data to be signed. - * len length in bytes of data. - * priv_key key to use for signing. - * signature location to store signature. - * sig_len size in bytes of signature field. - * returns - * N Success on SIG_MODE_FINAL = returns signature length in bytes - * 0 Success on SIG_MODE_INIT and UPDATE - * <0 Failure - */ - -static int -dst_bsafe_sign(const int mode, DST_KEY *dkey, void **context, - const u_char *data, const int len, - u_char *signature, const int sig_len) -{ - u_int sign_len = 0; - int status = 0; - B_ALGORITHM_OBJ *md5_ctx = NULL; - int w_bytes = 0; - u_int u_bytes = 0; - u_char work_area[NS_MD5RSA_MAX_SIZE]; - - if (mode & SIG_MODE_INIT) { - md5_ctx = (B_ALGORITHM_OBJ *) malloc(sizeof(B_ALGORITHM_OBJ)); - if ((status = B_CreateAlgorithmObject(md5_ctx))) - return (-1); - if ((status = B_SetAlgorithmInfo(*md5_ctx, AI_MD5, NULL))) - return (-1); - } - else if (context) - md5_ctx = (B_ALGORITHM_OBJ *) *context; - if (md5_ctx == NULL) - return (-1); - - w_bytes = dst_bsafe_md5digest(mode, md5_ctx, - data, len,work_area, sizeof(work_area)); - if (w_bytes < 0 || (mode & SIG_MODE_FINAL)) { - B_DestroyAlgorithmObject(md5_ctx); - SAFE_FREE(md5_ctx); - if (w_bytes < 0) - return (w_bytes); - } - - if (mode & SIG_MODE_FINAL) { - RSA_Key *key; - int ret = 0; - B_ALGORITHM_OBJ rsaEncryptor = (B_ALGORITHM_OBJ) NULL_PTR; - - if (dkey == NULL || dkey->dk_KEY_struct == NULL) - return (-1); - key = (RSA_Key *) dkey->dk_KEY_struct; - if (key == NULL || key->rk_Private_Key == NULL) - return (-1); - - if ((status = B_CreateAlgorithmObject(&rsaEncryptor))) - return (SIGN_FINAL_FAILURE); - if ((status = B_SetAlgorithmInfo(rsaEncryptor, - AI_PKCS_RSAPrivate, - NULL_PTR))) - - ret = SIGN_FINAL_FAILURE; - if (ret == 0 && - (status = B_EncryptInit(rsaEncryptor, - key->rk_Private_Key, - CHOOSER, NULL_SURRENDER))) - ret = SIGN_FINAL_FAILURE; - if (ret == 0 && - (status = B_EncryptUpdate(rsaEncryptor, signature, - &u_bytes, sig_len, pkcs1, - sizeof(pkcs1), NULL_PTR, - NULL_SURRENDER))) - ret = SIGN_FINAL_FAILURE; - if (ret == 0 && - (status = B_EncryptUpdate(rsaEncryptor, signature, - &u_bytes, sig_len, work_area, - w_bytes, NULL_PTR, - NULL_SURRENDER))) - ret = SIGN_FINAL_FAILURE; - - if (ret == 0 && - (status = B_EncryptFinal(rsaEncryptor, signature + u_bytes, - &sign_len, sig_len - u_bytes, - NULL_PTR, NULL_SURRENDER))) - ret = SIGN_FINAL_FAILURE; - B_DestroyAlgorithmObject(&rsaEncryptor); - if (ret != 0) - return (ret); - - } - else { - if (context == NULL) - return (-1); - *context = (void *) md5_ctx; - } - return (sign_len); -} - - -/* - * Dst_bsafe_verify - * Calls BSAFE verification routines. There are three steps to - * verification, INIT (initialize structures), UPDATE (hash (more) data), - * FINAL (generate a signature). This routine performs one or more of - * these steps. - * Parameters - * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL. - * dkey structure holds context for a verify done in multiple calls. - * context the context to use for this computation - * data data signed. - * len length in bytes of data. - * pub_key key to use for verify. - * signature signature. - * sig_len length in bytes of signature. - * returns - * 0 Success - * <0 Failure - */ - -static int -dst_bsafe_verify(const int mode, DST_KEY *dkey, void **context, - const u_char *data, const int len, - const u_char *signature, const int sig_len) -{ - B_ALGORITHM_OBJ *md5_ctx = NULL; - u_char digest[DST_HASH_SIZE]; - u_char work_area[DST_HASH_SIZE + sizeof(pkcs1)]; - int status = 0, w_bytes = 0; - u_int u_bytes = 0; - - if (mode & SIG_MODE_INIT) { - md5_ctx = (B_ALGORITHM_OBJ *) malloc(sizeof(B_ALGORITHM_OBJ)); - if ((status = B_CreateAlgorithmObject(md5_ctx))) - return (-1); - if ((status = B_SetAlgorithmInfo(*md5_ctx, AI_MD5, NULL))) - return (-1); - } - else if (context) - md5_ctx = (B_ALGORITHM_OBJ *) *context; - if (md5_ctx == NULL) - return (-1); - - w_bytes = dst_bsafe_md5digest(mode, md5_ctx, data, len, - digest, sizeof(digest)); - - if (w_bytes < 0 || (mode & SIG_MODE_FINAL)) { - B_DestroyAlgorithmObject(md5_ctx); - SAFE_FREE(md5_ctx); - if (w_bytes < 0) - return (-1); - } - - if (mode & SIG_MODE_FINAL) { - RSA_Key *key; - int ret = 0; - B_ALGORITHM_OBJ rsaEncryptor = (B_ALGORITHM_OBJ) NULL_PTR; - - if (dkey == NULL || dkey->dk_KEY_struct == NULL) - return (-1); - key = (RSA_Key *) dkey->dk_KEY_struct; - if (key->rk_Public_Key == NULL) - return (-2); - if (rsaEncryptor == NULL_PTR) { - if ((status = B_CreateAlgorithmObject(&rsaEncryptor))) - ret = SIGN_FINAL_FAILURE; - if (ret == 0 && - (status = B_SetAlgorithmInfo(rsaEncryptor, - AI_PKCS_RSAPublic, - NULL_PTR))) - ret = VERIFY_FINAL_FAILURE; - } - if (ret == 0 && - (status = B_DecryptInit(rsaEncryptor, key->rk_Public_Key, - CHOOSER, NULL_SURRENDER))) - ret = VERIFY_FINAL_FAILURE; - - if (ret == 0 && - (status = B_DecryptUpdate(rsaEncryptor, work_area, - &u_bytes, 0, - (const u_char *) signature, - sig_len, - NULL_PTR, NULL_SURRENDER))) - ret = VERIFY_FINAL_FAILURE; - - if (ret == 0 && - (status = B_DecryptFinal(rsaEncryptor, work_area + u_bytes, - &u_bytes, - sizeof(work_area) - u_bytes, - NULL_PTR, NULL_SURRENDER))) - ret = VERIFY_FINAL_FAILURE; - B_DestroyAlgorithmObject(&rsaEncryptor); - /* skip PKCS#1 header in output from Decrypt function */ - if (ret) - return (ret); - ret = memcmp(digest, &work_area[sizeof(pkcs1)], w_bytes); - if (ret == 0) - return(0); - else - return(VERIFY_FINAL_FAILURE); - } - else { - if (context == NULL) - return (-1); - *context = (void *) md5_ctx; - } - return (0); -} - - -/* - * dst_bsafe_to_dns_key - * Converts key from RSA to DNS distribution format - * This function gets in a pointer to the public key and a work area - * to write the key into. - * Parameters - * public KEY structure - * out_str buffer to write encoded key into - * out_len size of out_str - * Return - * N >= 0 length of encoded key - * n < 0 error - */ - -static int -dst_bsafe_to_dns_key(const DST_KEY *in_key, u_char *out_str, - const int out_len) -{ - B_KEY_OBJ public; - A_RSA_KEY *pub = NULL; - u_char *op = out_str; - int n = 0; - - if (in_key == NULL || in_key->dk_KEY_struct == NULL || - out_len <= 0 || out_str == NULL) - return (-1); - public = (B_KEY_OBJ)((RSA_Key *) in_key->dk_KEY_struct)->rk_Public_Key; - - n = B_GetKeyInfo((POINTER *) &pub, public, KI_RSAPublic); - if (n != 0) - return (-1); - - if (pub->exponent.len < 256) { /* key exponent is <= 2040 bits */ - if ((unsigned int)out_len < pub->exponent.len + 1) - return (-1); - *op++ = (u_int8_t) pub->exponent.len; - } else { /* key exponent is > 2040 bits */ - u_int16_t e = (u_int16_t) pub->exponent.len; - if ((unsigned int)out_len < pub->exponent.len + 3) - return (-1); - *op++ = 0; /* 3 byte length field */ - dst_s_put_int16(op, e); - op += sizeof(e); - n = 2; - } - n++; - memcpy(op, pub->exponent.data, pub->exponent.len); - op += pub->exponent.len; - n += pub->exponent.len; - - if ((unsigned int)(out_len - n) >= pub->modulus.len) { - /*copy exponent */ - memcpy(op, pub->modulus.data, pub->modulus.len); - n += pub->modulus.len; - } - else - n = -1; - return (n); -} - - -/* - * dst_bsafe_from_dns_key - * Converts from a DNS KEY RR format to an RSA KEY. - * Parameters - * len Length in bytes of DNS key - * key DNS key - * name Key name - * s_key DST structure that will point to the RSA key this routine - * will build. - * Return - * 0 The input key, s_key or name was null. - * 1 Success - */ -static int -dst_bsafe_from_dns_key(DST_KEY *s_key, const u_char *key, const int len) -{ - int bytes; - const u_char *key_ptr; - RSA_Key *r_key; - A_RSA_KEY *public; - - if (s_key == NULL || len < 0 || key == NULL) - return (0); - - r_key = (RSA_Key *) s_key->dk_KEY_struct; - if (r_key != NULL) /* do not reuse */ - s_key->dk_func->destroy(r_key); - - if (len == 0) - return (1); - - if ((r_key = (RSA_Key *) malloc(sizeof(RSA_Key))) == NULL) { - EREPORT(("dst_bsafe_from_dns_key(): Memory allocation error 1")); - return (0); - } - memset(r_key, 0, sizeof(RSA_Key)); - s_key->dk_KEY_struct = (void *) r_key; - r_key->rk_signer = strdup(s_key->dk_key_name); - - if (B_CreateKeyObject(&r_key->rk_Public_Key) != 0) { - EREPORT(("dst_bsafe_from_dns_key(): Memory allocation error 3")); - s_key->dk_func->destroy(r_key); - return (0); - } - key_ptr = key; - bytes = (int) *key_ptr++; /* length of exponent in bytes */ - if (bytes == 0) { /* special case for long exponents */ - bytes = (int) dst_s_get_int16(key_ptr); - key_ptr += sizeof(u_int16_t); - } - if (bytes > MAX_RSA_MODULUS_LEN) { - dst_bsafe_free_key_structure(r_key); - return (-1); - } - if ((public = (A_RSA_KEY *) malloc(sizeof(A_RSA_KEY))) == NULL) - return (0); - memset(public, 0, sizeof(*public)); - public->exponent.len = bytes; - if ((public->exponent.data = (u_char *) malloc(bytes)) == NULL) - return (0); - memcpy(public->exponent.data, key_ptr, bytes); - - key_ptr += bytes; /* beginning of modulus */ - bytes = len - bytes - 1; /* length of modulus */ - - if (bytes > MAX_RSA_MODULUS_LEN) { - dst_bsafe_free_key_structure(r_key); - return (-1); - } - public->modulus.len = bytes; - if ((public->modulus.data = (u_char *) malloc(bytes)) == NULL) - return (0); - memcpy(public->modulus.data, key_ptr, bytes); - - B_SetKeyInfo(r_key->rk_Public_Key, KI_RSAPublic, (POINTER) public); - - s_key->dk_key_size = dst_bsafe_key_size(r_key); - SAFE_FREE(public->modulus.data); - SAFE_FREE(public->exponent.data); - SAFE_FREE(public); - return (1); -} - - -/* - * dst_bsafe_key_to_file_format - * Encodes an RSA Key into the portable file format. - * Parameters - * rkey RSA KEY structure - * buff output buffer - * buff_len size of output buffer - * Return - * 0 Failure - null input rkey - * -1 Failure - not enough space in output area - * N Success - Length of data returned in buff - */ - -static int -dst_bsafe_key_to_file_format(const DST_KEY *key, char *buff, - const int buff_len) -{ - char *bp; - int len, b_len; - B_KEY_OBJ rkey; - A_PKCS_RSA_PRIVATE_KEY *private = NULL; - - if (key == NULL || key->dk_KEY_struct == NULL) /* no output */ - return (0); - if (buff == NULL || buff_len <= (int) strlen(key_file_fmt_str)) - return (-1); /* no OR not enough space in output area */ - - rkey = (B_KEY_OBJ)((RSA_Key *) key->dk_KEY_struct)->rk_Private_Key; - - B_GetKeyInfo((POINTER *) &private, rkey, KI_PKCS_RSAPrivate); - - memset(buff, 0, buff_len); /* just in case */ - /* write file header */ - sprintf(buff, key_file_fmt_str, KEY_FILE_FORMAT, KEY_RSA, "RSA"); - - bp = strchr(buff, '\0'); - b_len = buff_len - (bp - buff); - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Modulus: ", - private->modulus.data, - private->modulus.len)) <= 0) - return (-1); - - bp += len; - b_len -= len; - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "PublicExponent: ", - private->publicExponent.data, - private->publicExponent.len)) <= 0) - return (-2); - - bp += len; - b_len -= len; - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "PrivateExponent: ", - private->privateExponent.data, - private->privateExponent.len)) <= 0) - return (-3); - bp += len; - b_len -= len; - - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Prime1: ", - private->prime[0].data, - private->prime[0].len)) < 0) - return (-4); - bp += len; - b_len -= len; - - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Prime2: ", - private->prime[1].data, - private->prime[1].len)) < 0) - return (-5); - bp += len; - b_len -= len; - - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Exponent1: ", - private->primeExponent[0].data, - private->primeExponent[0].len)) < 0) - return (-6); - bp += len; - b_len -= len; - - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Exponent2: ", - private->primeExponent[1].data, - private->primeExponent[1].len)) < 0) - return (-7); - bp += len; - b_len -= len; - - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Coefficient: ", - private->coefficient.data, - private->coefficient.len)) < 0) - return (-8); - bp += len; - b_len -= len; - return (buff_len - b_len); -} - - -/* - * dst_bsafe_key_from_file_format - * Converts contents of a private key file into a private RSA key. - * Parameters - * RSA_Key structure to put key into - * buff buffer containing the encoded key - * buff_len the length of the buffer - * Return - * n >= 0 Foot print of the key converted - * n < 0 Error in conversion - */ - -static int -dst_bsafe_key_from_file_format(DST_KEY *d_key, const char *buff, - const int buff_len) -{ - int status; - char s[RAW_KEY_SIZE]; - int len, s_len = sizeof(s); - const char *p = buff; - RSA_Key *b_key; - A_RSA_KEY *public; - A_PKCS_RSA_PRIVATE_KEY *private; - - if (d_key == NULL || buff == NULL || buff_len <= 0) - return (-1); - - b_key = (RSA_Key *) malloc(sizeof(RSA_Key)); - public = (A_RSA_KEY *) malloc(sizeof(A_RSA_KEY)); - private = (A_PKCS_RSA_PRIVATE_KEY *) - malloc(sizeof(A_PKCS_RSA_PRIVATE_KEY)); - if (b_key == NULL || private == NULL || public == NULL) { - SAFE_FREE(b_key); - SAFE_FREE(public); - SAFE_FREE(private); - return (-2); - } - memset(b_key, 0, sizeof(*b_key)); - memset(public, 0, sizeof(A_RSA_KEY)); - memset(private, 0, sizeof(A_PKCS_RSA_PRIVATE_KEY)); - d_key->dk_KEY_struct = (void *) b_key; - if (!dst_s_verify_str(&p, "Modulus: ")) - return (-3); - memset(s, 0, s_len); - if ((len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s, s_len)) == 0) - return (-4); - - private->modulus.len = len; - if ((private->modulus.data = malloc(len)) == NULL) - return (-5); - memcpy(private->modulus.data, s + s_len - len, len); - - while (*(++p) && p < (const char *) &buff[buff_len]) { - if (dst_s_verify_str(&p, "PublicExponent: ")) { - if (!(len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s, s_len))) - return (-5); - private->publicExponent.len = len; - if ((private->publicExponent.data = malloc(len)) - == NULL) - return (-6); - memcpy(private->publicExponent.data, - s + s_len - len, len); - } else if (dst_s_verify_str(&p, "PrivateExponent: ")) { - if (!(len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s, s_len))) - return (-6); - private->privateExponent.len = len; - if ((private->privateExponent.data = malloc(len)) - == NULL) - return (-7); - memcpy(private->privateExponent.data, s + s_len - len, - len); - } else if (dst_s_verify_str(&p, "Prime1: ")) { - if (!(len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s, - MAX_RSA_PRIME_LEN))) - return (-7); - private->prime[0].len = len; - if ((private->prime[0].data = malloc(len)) == NULL) - return (-8); - memcpy(private->prime[0].data, - s + MAX_RSA_PRIME_LEN - len, len); - } else if (dst_s_verify_str(&p, "Prime2: ")) { - if (!(len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s, - MAX_RSA_PRIME_LEN))) - return (-8); - private->prime[1].len = len; - if ((private->prime[1].data = malloc(len)) == NULL) - return (-9); - memcpy(private->prime[1].data, - s + MAX_RSA_PRIME_LEN - len, len); - } else if (dst_s_verify_str(&p, "Exponent1: ")) { - if (!(len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s, - MAX_RSA_PRIME_LEN))) - return (-9); - private->primeExponent[0].len = len; - if ((private->primeExponent[0].data = malloc(len)) - == NULL) - return (-10); - memcpy(private->primeExponent[0].data, - s + MAX_RSA_PRIME_LEN - len, len); - } else if (dst_s_verify_str(&p, "Exponent2: ")) { - if (!(len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s, - MAX_RSA_PRIME_LEN))) - return (-10); - private->primeExponent[1].len = len; - if ((private->primeExponent[1].data = malloc(len)) - == NULL) - return (-11); - memcpy(private->primeExponent[1].data, - s + MAX_RSA_PRIME_LEN - len, len); - } else if (dst_s_verify_str(&p, "Coefficient: ")) { - if (!(len = dst_s_conv_bignum_b64_to_u8(&p, (u_char *)s, - MAX_RSA_PRIME_LEN))) - return (-11); - private->coefficient.len = len; - if ((private->coefficient.data = malloc(len)) == NULL) - return (-12); - memcpy(private->coefficient.data, - s + MAX_RSA_PRIME_LEN - len, len); - } else { - EREPORT(("Decode_RSAKey(): Bad keyword %s\n", p)); - return (-12); - } - } /* while p */ - - public->modulus.len = private->modulus.len; - if ((public->modulus.data = (u_char *) malloc(public->modulus.len)) == - NULL) - return (-13); - memcpy(public->modulus.data, private->modulus.data, - private->modulus.len); - - public->exponent.len = private->publicExponent.len; - if ((public->exponent.data = (u_char *) malloc(public->exponent.len)) - == NULL) - return (-14); - memcpy(public->exponent.data, private->publicExponent.data, - private->publicExponent.len); - - status = B_CreateKeyObject(&(b_key->rk_Public_Key)); - if (status) - return (-1); - status = B_SetKeyInfo(b_key->rk_Public_Key, KI_RSAPublic, - (POINTER) public); - if (status) - return (-1); - - status = B_CreateKeyObject(&b_key->rk_Private_Key); - if (status) - return (-1); - status = B_SetKeyInfo(b_key->rk_Private_Key, KI_PKCS_RSAPrivate, - (POINTER) private); - if (status) - return (-1); - - d_key->dk_key_size = dst_bsafe_key_size(b_key); - - SAFE_FREE(private->modulus.data); - SAFE_FREE(private->publicExponent.data); - SAFE_FREE(private->privateExponent.data); - SAFE_FREE(private->prime[0].data); - SAFE_FREE(private->prime[1].data); - SAFE_FREE(private->primeExponent[0].data); - SAFE_FREE(private->primeExponent[1].data); - SAFE_FREE(private->coefficient.data); - SAFE_FREE(private); /* is this the right thing to do ??? XXXX */ - SAFE_FREE(public->modulus.data); - SAFE_FREE(public->exponent.data); - SAFE_FREE(public); - return (0); -} - - -/* - * dst_bsafe_free_key_structure - * Frees all dynamicly allocated structures in RSA_Key. - */ - -static void * -dst_bsafe_free_key_structure(void *key) -{ - RSA_Key *r_key = (RSA_Key *) key; - if (r_key != NULL) { - if (r_key->rk_Private_Key) - B_DestroyKeyObject(&r_key->rk_Private_Key); - if (r_key->rk_Public_Key) - B_DestroyKeyObject(&r_key->rk_Public_Key); - SAFE_FREE2(r_key->rk_signer, strlen(r_key->rk_signer)); - SAFE_FREE(r_key); - } - return (NULL); -} - - -/* - * dst_bsafe_generate_keypair - * Generates unique keys that are hard to predict. - * Parameters - * key generic Key structure - * exp the public exponent - * Return - * 0 Failure - * 1 Success - */ - -static int -dst_bsafe_generate_keypair(DST_KEY *key, int exp) -{ - int i, status; - B_KEY_OBJ private; - B_KEY_OBJ public; - B_ALGORITHM_OBJ keypairGenerator; - B_ALGORITHM_OBJ randomAlgorithm; - A_RSA_KEY_GEN_PARAMS keygenParams; - char exponent[4]; - int exponent_len; - RSA_Key *rsa; - POINTER randomSeed = NULL_PTR; - int randomSeedLen; - A_RSA_KEY *pk_access = NULL; - - if (key == NULL || key->dk_alg != KEY_RSA) - return (0); - - if ((rsa = (RSA_Key *) malloc(sizeof(RSA_Key))) == NULL) { - EREPORT(("dst_bsafe_generate_keypair: Memory allocation error 3")); - return (0); - } - memset(rsa, 0, sizeof(*rsa)); - - if ((status = B_CreateAlgorithmObject(&keypairGenerator)) != 0) - return (0); - - keygenParams.modulusBits = key->dk_key_size; - - /* exp = 0 or 1 are special (mean 3 or F4) */ - if (exp == 0) - exp = 3; - else if (exp == 1) - exp = 65537; - - /* Now encode the exponent and its length */ - if (exp < 256) { - exponent_len = 1; - exponent[0] = exp; - } else if (exp < (1 << 16)) { - exponent_len = 2; - exponent[0] = exp >> 8; - exponent[1] = exp; - } else if (exp < (1 << 24)) { - exponent_len = 3; - exponent[0] = exp >> 16; - exponent[1] = exp >> 8; - exponent[2] = exp; - } else { - exponent_len = 4; - exponent[0] = exp >> 24; - exponent[1] = exp >> 16; - exponent[2] = exp >> 8; - exponent[3] = exp; - } - - if ((keygenParams.publicExponent.data = (u_char *) malloc(exponent_len)) - == NULL) - return (0); - memcpy(keygenParams.publicExponent.data, exponent, exponent_len); - keygenParams.publicExponent.len = exponent_len; - if ((status = B_SetAlgorithmInfo - (keypairGenerator, AI_RSAKeyGen, (POINTER) &keygenParams)) != 0) - return (0); - - if ((status = B_GenerateInit(keypairGenerator, CHOOSER, - NULL_SURRENDER)) != 0) - return (0); - - if ((status = B_CreateKeyObject(&public)) != 0) - return (0); - - if ((status = B_CreateKeyObject(&private)) != 0) - return (0); - - if ((status = B_CreateAlgorithmObject(&randomAlgorithm)) != 0) - return (0); - - if ((status = B_SetAlgorithmInfo(randomAlgorithm, AI_MD5Random, - NULL_PTR)) - != 0) - return (0); - - if ((status = B_RandomInit(randomAlgorithm, CHOOSER, - NULL_SURRENDER)) != 0) - return (0); - - randomSeedLen = 256; - if ((randomSeed = malloc(randomSeedLen)) == NULL) - return (0); - if ((status = (randomSeed == NULL_PTR)) != 0) - return (0); - - /* gets random seed from /dev/random if present, generates random - * values if it is not present. - * first fill the buffer with semi random data - * then fill as much as possible with good random data - */ - i = dst_random(DST_RAND_SEMI, randomSeedLen, randomSeed); - i += dst_random(DST_RAND_KEY, randomSeedLen, randomSeed); - - if (i <= randomSeedLen) { - SAFE_FREE(rsa); - return(0); - } - if ((status = B_RandomUpdate(randomAlgorithm, randomSeed, - randomSeedLen, NULL_SURRENDER)) != 0) { - SAFE_FREE(rsa); - return (0); - } - SAFE_FREE2(randomSeed, randomSeedLen); - if ((status = B_GenerateKeypair(keypairGenerator, public, private, - randomAlgorithm, NULL_SURRENDER)) - != 0) { - SAFE_FREE(rsa); - return (0); - } - rsa->rk_signer = strdup(key->dk_key_name); - rsa->rk_Private_Key = private; - rsa->rk_Public_Key = public; - key->dk_KEY_struct = (void *) rsa; - - B_GetKeyInfo((POINTER *) &pk_access, public, KI_RSAPublic); - return (1); -} - - -/************************************************************************** - * dst_bsafe_compare_keys - * Compare two keys for equality. - * Return - * 0 The keys are equal - * NON-ZERO The keys are not equal - */ - -static int -dst_s_bsafe_itemcmp(ITEM i1, ITEM i2) -{ - if (i1.len != i2.len || memcmp (i1.data, i2.data, i1.len)) - return (1); - else - return (0); -} - -static int -dst_bsafe_compare_keys(const DST_KEY *key1, const DST_KEY *key2) -{ - int status, s1 = 0, s2 = 0; - RSA_Key *rkey1 = (RSA_Key *) key1->dk_KEY_struct; - RSA_Key *rkey2 = (RSA_Key *) key2->dk_KEY_struct; - A_RSA_KEY *public1 = NULL, *public2 = NULL; - A_PKCS_RSA_PRIVATE_KEY *p1 = NULL, *p2 = NULL; - - if (rkey1 == NULL && rkey2 == NULL) - return(0); - else if (rkey1 == NULL) - return (1); - else if (rkey2 == NULL) - return (2); - - if (rkey1->rk_Public_Key) - B_GetKeyInfo((POINTER *) &public1, rkey1->rk_Public_Key, - KI_RSAPublic); - if (rkey2->rk_Public_Key) - B_GetKeyInfo((POINTER *) &public2, rkey2->rk_Public_Key, - KI_RSAPublic); - if (public1 == NULL && public2 == NULL) - return (0); - else if (public1 == NULL || public2 == NULL) - return (1); - - status = dst_s_bsafe_itemcmp(public1->modulus, public2->modulus) || - dst_s_bsafe_itemcmp(public1->exponent, public2->exponent); - - if (status) - return (status); - - if (rkey1->rk_Private_Key == NULL || rkey2->rk_Private_Key == NULL) - /* if neither or only one is private key consider identical */ - return (status); - if (rkey1->rk_Private_Key) - s1 = B_GetKeyInfo((POINTER *) &p1, rkey1->rk_Private_Key, - KI_PKCS_RSAPrivate); - if (rkey2->rk_Private_Key) - s2 = B_GetKeyInfo((POINTER *) &p2, rkey2->rk_Private_Key, - KI_PKCS_RSAPrivate); - if (p1 == NULL || p2 == NULL) - return (0); - - status = dst_s_bsafe_itemcmp(p1->modulus, p2->modulus) || - dst_s_bsafe_itemcmp (p1->publicExponent, - p2->publicExponent) || - dst_s_bsafe_itemcmp (p1->privateExponent, - p2->privateExponent) || - dst_s_bsafe_itemcmp (p1->prime[0], p2->prime[0]) || - dst_s_bsafe_itemcmp (p1->prime[1], p2->prime[1]) || - dst_s_bsafe_itemcmp (p1->primeExponent[0], - p2->primeExponent[0])|| - dst_s_bsafe_itemcmp (p1->primeExponent[1], - p2->primeExponent[1])|| - dst_s_bsafe_itemcmp (p1->coefficient, p2->coefficient); - return (status); -} - - -/* - * dst_bsafe_key_size() - * Function to calculate how the size of the key in bits - */ -static int -dst_bsafe_key_size(RSA_Key *r_key) -{ - int size; - A_PKCS_RSA_PRIVATE_KEY *private = NULL; - - if (r_key == NULL) - return (-1); - if (r_key->rk_Private_Key) - B_GetKeyInfo((POINTER *) &private, r_key->rk_Private_Key, - KI_PKCS_RSAPrivate); - else if (r_key->rk_Public_Key) - B_GetKeyInfo((POINTER *) &private, r_key->rk_Public_Key, - KI_RSAPublic); - size = dst_s_calculate_bits(private->modulus.data, - private->modulus.len * 8); - return (size); -} - -/* - * dst_bsafe_md5digest(): function to digest data using MD5 digest function - * if needed - */ -static int -dst_bsafe_md5digest(const int mode, B_ALGORITHM_OBJ *digest_obj, - const u_char *data, const int len, - u_char *digest, const int digest_len) -{ - int status = 0; - u_int work_size = 0; - - if (digest_obj == NULL || *digest_obj == NULL) { - printf("NO digest obj\n"); - exit(33); - } - - if ((mode & SIG_MODE_INIT) && - (status = B_DigestInit(*digest_obj, (B_KEY_OBJ) NULL, - CHOOSER, NULL_SURRENDER))) - return (SIGN_INIT_FAILURE); - - if ((mode & SIG_MODE_UPDATE) && data && (len > 0) && - (status = B_DigestUpdate(*digest_obj, data, len, NULL_SURRENDER))) - return (SIGN_UPDATE_FAILURE); - - if (mode & SIG_MODE_FINAL) { - if (digest == NULL || - (status = B_DigestFinal(*digest_obj, digest, &work_size, - digest_len, NULL_SURRENDER))) - return (SIGN_FINAL_FAILURE); - return (work_size); - } - return (0); -} - -/* - * just use the standard memory functions for bsafe - */ -void -T_free(POINTER block) -{ - free(block); -} - -POINTER -T_malloc(unsigned int len) -{ - return (malloc(len)); -} - -int -T_memcmp(CPOINTER firstBlock, CPOINTER secondBlock, unsigned int len) -{ - return (memcmp(firstBlock, secondBlock, len)); -} - -void -T_memcpy(POINTER output, CPOINTER input, unsigned int len) -{ - memcpy(output, input, len); -} - -void -T_memmove(POINTER output, POINTER input, unsigned int len) -{ - memmove(output, input, len); -} - -void -T_memset(POINTER output, int value, unsigned int len) -{ - memset(output, value, len); -} - -POINTER -T_realloc(POINTER block, unsigned int len) -{ - return (realloc(block, len)); -} - -#else /* BSAFE NOT available */ -int -dst_bsafe_init() -{ - return (0); -} -#endif /* BSAFE */ diff --git a/usr/src/lib/libresolv2/common/dst/cylink_link.c b/usr/src/lib/libresolv2/common/dst/cylink_link.c deleted file mode 100644 index d7ee3a8af4..0000000000 --- a/usr/src/lib/libresolv2/common/dst/cylink_link.c +++ /dev/null @@ -1,677 +0,0 @@ -/* - * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef CYLINK_DSS -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/cylink_link.c,v 1.9 2001/05/29 05:48:05 marka Exp $"; - -/* - * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. - * - * Permission to use, copy modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND TRUSTED INFORMATION SYSTEMS - * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL - * TRUSTED INFORMATION SYSTEMS BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THE SOFTWARE. - */ -/* - * This file contains two components - * 1. Interface to the CYLINK library to allow compilation of Bind - * with TIS/DNSSEC when CYLINK is not available - * all calls to CYLINK are contained inside this file. - * 2. The glue to connvert DSA KEYS to and from external formats - */ -#include "port_before.h" - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#include <memory.h> -#include <sys/param.h> -#include <sys/time.h> -#include <netinet/in.h> - -#include "dst_internal.h" -#include <toolkit.h> - -#include "port_after.h" - -typedef struct cylinkkey { - char *dk_signer; - uchar *dk_p; - uchar *dk_q; - uchar *dk_g; - uchar *dk_x; - uchar *dk_y; - ushort dk_p_bytes; -} DSA_Key; - -#define NULL_PRIV_KEY(k)(k == NULL || k->dk_p == NULL || k->dk_q == NULL || \ - k->dk_g == NULL || k->dk_x == NULL) -#define NULL_PUB_KEY(k)(k == NULL || k->dk_p == NULL || k->dk_q == NULL || \ - k->dk_g == NULL || k->dk_y == NULL) - -static int dst_cylink_sign(const int mode, DST_KEY *dkey, void **context, - const u_char *data, const int len, - u_char *signature, const int sig_len); - -static int dst_cylink_verify(const int mode, DST_KEY *dkey, void **context, - const u_char *data, const int len, - const u_char *signature, const int sig_len); - -static int dst_cylink_to_dns_key(const DST_KEY *in_key, u_char *out_str, - const int out_len); -static int dst_cylink_from_dns_key(DST_KEY *s_key, const u_char *key, - const int len); -static int dst_cylink_key_to_file_format(const DST_KEY *key, char *buff, - const int buff_len); -static int dst_cylink_key_from_file_format(DST_KEY *d_key, - const char *buff, - const int buff_len); -static void *dst_cylink_free_key_structure(void *key); - -static int dst_cylink_generate_keypair(DST_KEY *key, int exp); -static int dst_cylink_compare_keys(const DST_KEY *key1, const DST_KEY *key2); - -static void *memcpyend(void *dest, const void *src, size_t n, size_t size); - -/* - * dst_cylink_init() Function to answer set up function pointers for - * CYLINK related functions - */ -int -dst_cylink_init() -{ - if (dst_t_func[KEY_DSA] != NULL) - return (1); - dst_t_func[KEY_DSA] = malloc(sizeof(struct dst_func)); - if (dst_t_func[KEY_DSA] == NULL) - return (0); - memset(dst_t_func[KEY_DSA], 0, sizeof(struct dst_func)); - dst_t_func[KEY_DSA]->sign = dst_cylink_sign; - dst_t_func[KEY_DSA]->verify = dst_cylink_verify; - dst_t_func[KEY_DSA]->compare = dst_cylink_compare_keys; - dst_t_func[KEY_DSA]->generate = dst_cylink_generate_keypair; - dst_t_func[KEY_DSA]->destroy = dst_cylink_free_key_structure; - dst_t_func[KEY_DSA]->from_dns_key = dst_cylink_from_dns_key; - dst_t_func[KEY_DSA]->to_dns_key = dst_cylink_to_dns_key; - dst_t_func[KEY_DSA]->from_file_fmt = dst_cylink_key_from_file_format; - dst_t_func[KEY_DSA]->to_file_fmt = dst_cylink_key_to_file_format; - SetDataOrder(1); - return (1); -} - -/* - * dst_cylink_sign - * Call CYLINK signing functions to sign a block of data. - * There are three steps to signing, INIT (initialize structures), - * UPDATE (hash (more) data), FINAL (generate a signature). This - * routine performs one or more of these steps. - * Parameters - * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL. - * algobj structure holds context for a sign done in multiple calls. - * context the context to use for this computation - * data data to be signed. - * len length in bytes of data. - * priv_key key to use for signing. - * signature location to store signature. - * sig_len size in bytes of signature field. - * returns - * N Success on SIG_MODE_FINAL = returns signature length in bytes - * N is 41 for DNS - * 0 Success on SIG_MODE_INIT and UPDATE - * <0 Failure - */ - -static int -dst_cylink_sign(const int mode, DST_KEY *dkey, void **context, - const u_char *data, const int len, - u_char *signature, const int sig_len) -{ - int sign_len = 0; - int status; - SHA_context *ctx = NULL; - - if (mode & SIG_MODE_INIT) - ctx = (SHA_context *) malloc(sizeof(SHA_context)); - else if (context) - ctx = (SHA_context *) *context; - if (ctx == NULL) - return (-1); - - if (mode & SIG_MODE_INIT) - SHAInit(ctx); - - if ((mode & SIG_MODE_UPDATE) && (data && len > 0)) { - status = SHAUpdate(ctx, data, len); - if (status != SUCCESS) - return (SIGN_UPDATE_FAILURE); - } - if (mode & SIG_MODE_FINAL) { - DSA_Key *key; - uchar digest[SHA_LENGTH]; - uchar rand[SHA_LENGTH]; - uchar r[SHA_LENGTH], s[SHA_LENGTH]; - - if (signature == NULL || sig_len < 2 * SHA_LENGTH) - return (SIGN_FINAL_FAILURE); - if ((status = SHAFinal(ctx, digest)) != SUCCESS) - return (SIGN_FINAL_FAILURE); - SAFE_FREE(ctx); - if (dkey == NULL || dkey->dk_KEY_struct == NULL) - return (-1); - key = (DSA_Key *) dkey->dk_KEY_struct; - if (NULL_PRIV_KEY(key)) - return (-2); - dst_random(DST_RAND_STD, sizeof(rand), rand); - status = GenDSSSignature(key->dk_p_bytes, key->dk_p, - key->dk_q, key->dk_g, key->dk_x, - rand, r, s, digest); - if (status != SUCCESS) - return (SIGN_FINAL_FAILURE); - *signature = (dkey->dk_key_size - 512)/64; - sign_len = 1; - memcpy(signature + sign_len, r, SHA_LENGTH); - sign_len += SHA_LENGTH; - memcpy(signature + sign_len, s, SHA_LENGTH); - sign_len += SHA_LENGTH; - } - else { - if (context == NULL) - return (-1); - *context = (void *) ctx; - } - return (sign_len); -} - - -/* - * Dst_cylink_verify - * Calls CYLINK verification routines. There are three steps to - * verification, INIT (initialize structures), UPDATE (hash (more) data), - * FINAL (generate a signature). This routine performs one or more of - * these steps. - * Parameters - * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL. - * dkey structure holds context for a verify done in multiple calls. - * context algorithm specific context for the current context processing - * data data signed. - * len length in bytes of data. - * pub_key key to use for verify. - * signature signature. - * sig_len length in bytes of signature. - * returns - * 0 Success - * <0 Failure - */ - -static int -dst_cylink_verify(const int mode, DST_KEY *dkey, void **context, - const u_char *data, const int len, - const u_char *signature, const int sig_len) -{ - int status; - SHA_context *ctx = NULL; - - if (mode & SIG_MODE_INIT) - ctx = (SHA_context *) malloc(sizeof(SHA_context)); - else if (context) - ctx = (SHA_context *) *context; - if (ctx == NULL) - return (-1); - - if (mode & SIG_MODE_INIT) - SHAInit(ctx); - - if ((mode & SIG_MODE_UPDATE) && (data && len > 0)) { - status = SHAUpdate(ctx, data, len); - if (status != SUCCESS) - return (VERIFY_UPDATE_FAILURE); - } - if (mode & SIG_MODE_FINAL) { - DSA_Key *key; - uchar digest[SHA_LENGTH]; - uchar r[SHA_LENGTH], s[SHA_LENGTH]; - - if (dkey == NULL || dkey->dk_KEY_struct == NULL) - return (-1); - key = (DSA_Key *) dkey->dk_KEY_struct; - if (NULL_PUB_KEY(key)) - return (-2); - if (signature == NULL || sig_len != (2 * SHA_LENGTH +1)) - return (SIGN_FINAL_FAILURE); - status = SHAFinal(ctx, digest); - SAFE_FREE(ctx); - if (status != SUCCESS) - return (SIGN_FINAL_FAILURE); - if (((int)*signature) != ((key->dk_p_bytes -64)/8)) - return(VERIFY_FINAL_FAILURE); - - memcpy(r, signature +1, SHA_LENGTH); - memcpy(s, signature + SHA_LENGTH +1, SHA_LENGTH); - status = VerDSSSignature(key->dk_p_bytes, key->dk_p, - key->dk_q, key->dk_g, key->dk_y, - r, s, digest); - if (status != SUCCESS) - return (VERIFY_FINAL_FAILURE); - } - else { - if (context == NULL) - return (-1); - *context = (void *) ctx; - } - return (0); -} - - -/* - * dst_cylink_to_dns_key - * Converts key from DSA to DNS distribution format - * This function gets in a pointer to the public key and a work area - * to write the key into. - * Parameters - * public KEY structure - * out_str buffer to write encoded key into - * out_len size of out_str - * Return - * N >= 0 length of encoded key - * n < 0 error - */ - -static int -dst_cylink_to_dns_key(const DST_KEY *in_key, u_char *out_str, - const int out_len) -{ - u_char *op = out_str; - int t; - DSA_Key *key; - - if (in_key == NULL || in_key->dk_KEY_struct == NULL || - out_len <= 0 || out_str == NULL) - return (-1); - key = (DSA_Key *) in_key->dk_KEY_struct; - - t = (key->dk_p_bytes - 64) / 8; - - *op++ = t; - memcpy(op, key->dk_q, SHA_LENGTH); - op += SHA_LENGTH; - memcpy(op, key->dk_p, key->dk_p_bytes); - op += key->dk_p_bytes; - memcpy(op, key->dk_g, key->dk_p_bytes); - op += key->dk_p_bytes; - memcpy(op, key->dk_y, key->dk_p_bytes); - op += key->dk_p_bytes; - - return (op - out_str); -} - - -/* - * dst_cylink_from_dns_key - * Converts from a DNS KEY RR format to an RSA KEY. - * Parameters - * len Length in bytes of DNS key - * key DNS key - * name Key name - * s_key DST structure that will point to the RSA key this routine - * will build. - * Return - * 0 The input key, s_key or name was null. - * 1 Success - */ -static int -dst_cylink_from_dns_key(DST_KEY *s_key, const u_char *key, const int len) -{ - int t; - const u_char *key_ptr = key; - DSA_Key *d_key; - - if (s_key == NULL || len < 0 || key == NULL) - return (0); - - if (len == 0) /* process null key */ - return (1); - - if (key_ptr == NULL) - return (0); - t = (int) *key_ptr++; /* length of exponent in bytes */ - - if ((3 * (t * 8 + 64) + SHA_LENGTH + 1) != len) - return (0); - - if ((d_key = (DSA_Key *) malloc(sizeof(DSA_Key))) == NULL) { - EREPORT(("dst_cylink_from_dns_key(): Memory allocation error 1")); - return (0); - } - memset(d_key, 0, sizeof(DSA_Key)); - s_key->dk_KEY_struct = (void *) d_key; - d_key->dk_signer = strdup(s_key->dk_key_name); - d_key->dk_p_bytes = 64 + 8 * t; - - if ((d_key->dk_q = (uchar *) malloc(SHA_LENGTH)) == NULL) - return (0); - memcpy(d_key->dk_q, key_ptr, SHA_LENGTH); - key_ptr += SHA_LENGTH; - - if ((d_key->dk_p = (uchar *) malloc(d_key->dk_p_bytes)) == NULL) - return (0); - memcpy(d_key->dk_p, key_ptr, d_key->dk_p_bytes); - key_ptr += d_key->dk_p_bytes; - - if ((d_key->dk_g = (uchar *) malloc(d_key->dk_p_bytes)) == NULL) - return (0); - memcpy(d_key->dk_g, key_ptr, d_key->dk_p_bytes); - key_ptr += d_key->dk_p_bytes; - - if ((d_key->dk_y = (uchar *) malloc(d_key->dk_p_bytes)) == NULL) - return (0); - memcpy(d_key->dk_y, key_ptr, d_key->dk_p_bytes); - key_ptr += d_key->dk_p_bytes; - - s_key->dk_key_size = d_key->dk_p_bytes * 8; - return (1); -} - - -/************************************************************************** - * dst_cylink_key_to_file_format - * Encodes an DSA Key into the portable file format. - * Parameters - * key DSA KEY structure - * buff output buffer - * buff_len size of output buffer - * Return - * 0 Failure - null input rkey - * -1 Failure - not enough space in output area - * N Success - Length of data returned in buff - */ - -static int -dst_cylink_key_to_file_format(const DST_KEY *key, char *buff, - const int buff_len) -{ - char *bp; - int len, b_len; - DSA_Key *dkey; - u_char num[256]; /* More than long enough for DSA keys */ - - if (key == NULL || key->dk_KEY_struct == NULL) /* no output */ - return (0); - if (buff == NULL || buff_len <= (int) strlen(key_file_fmt_str)) - return (-1); /* no OR not enough space in output area */ - - dkey = (DSA_Key *) key->dk_KEY_struct; - - memset(buff, 0, buff_len); /* just in case */ - /* write file header */ - sprintf(buff, key_file_fmt_str, KEY_FILE_FORMAT, KEY_DSA, "DSA"); - - bp = (char *) strchr(buff, '\0'); - b_len = buff_len - (bp - buff); - memcpy(num, dkey->dk_p, dkey->dk_p_bytes); - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Prime(p): ", - num, dkey->dk_p_bytes)) <= 0) - return (-1); - - bp = (char *) strchr(buff, '\0'); - b_len = buff_len - (bp - buff); - memcpy(num, dkey->dk_q, dkey->dk_p_bytes); - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Subprime(q): ", - num, SHA_LENGTH)) <= 0) - return (-2); - - bp = (char *) strchr(buff, '\0'); - b_len = buff_len - (bp - buff); - memcpy(num, dkey->dk_g, dkey->dk_p_bytes); - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Base(g): ", - num, dkey->dk_p_bytes)) <= 0) - return (-3); - - bp = (char *) strchr(buff, '\0'); - b_len = buff_len - (bp - buff); - memcpy(num, dkey->dk_x, dkey->dk_p_bytes); - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Private_value(x): ", - num, SHA_LENGTH)) <= 0) - return (-4); - - bp = (char *) strchr(buff, '\0'); - b_len = buff_len - (bp - buff); - memcpy(num, dkey->dk_y, dkey->dk_p_bytes); - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Public_value(y): ", - num, dkey->dk_p_bytes)) <= 0) - return (-4); - - bp += len; - b_len -= len; - return (buff_len - b_len); -} - - -/************************************************************************** - * dst_cylink_key_from_file_format - * Converts contents of a private key file into a private DSA key. - * Parameters - * DSA_Key structure to put key into - * buff buffer containing the encoded key - * buff_len the length of the buffer - * Return - * n >= 0 Foot print of the key converted - * n < 0 Error in conversion - */ - -static int -dst_cylink_key_from_file_format(DST_KEY *d_key, const char *buff, - const int buff_len) -{ - u_char s[DSS_LENGTH_MAX]; - int len, s_len = sizeof(s); - const char *p = buff; - DSA_Key *dsa_key; - - if (d_key == NULL || buff == NULL || buff_len <= 0) - return (-1); - - dsa_key = (DSA_Key *) malloc(sizeof(DSA_Key)); - if (dsa_key == NULL) { - return (-2); - } - memset(dsa_key, 0, sizeof(*dsa_key)); - d_key->dk_KEY_struct = (void *) dsa_key; - - if (!dst_s_verify_str(&p, "Prime(p): ")) - return (-3); - memset(s, 0, s_len); - if ((len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len)) == 0) - return (-4); - dsa_key->dk_p_bytes = len; - if ((dsa_key->dk_p = malloc(len)) == NULL) - return (-5); - memcpy(dsa_key->dk_p, s + s_len - len, len); - - while (*++p && p < (const char *) &buff[buff_len]) { - if (dst_s_verify_str(&p, "Subprime(q): ")) { - if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len))) - return (-6); - if ((dsa_key->dk_q = malloc(SHA_LENGTH)) == NULL) - return (-7); - memcpyend(dsa_key->dk_q, s + s_len - len, len, - SHA_LENGTH); - } else if (dst_s_verify_str(&p, "Base(g): ")) { - if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len))) - return (-8); - if ((dsa_key->dk_g = malloc(dsa_key->dk_p_bytes)) - == NULL) - return (-9); - memcpyend(dsa_key->dk_g, s + s_len - len, len, - dsa_key->dk_p_bytes); - } else if (dst_s_verify_str(&p, "Private_value(x): ")) { - if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len))) - return (-10); - if ((dsa_key->dk_x = malloc(SHA_LENGTH)) == NULL) - return (-11); - memcpyend(dsa_key->dk_x, s + s_len - len, len, - SHA_LENGTH); - } else if (dst_s_verify_str(&p, "Public_value(y): ")) { - if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len))) - return (-10); - if ((dsa_key->dk_y = malloc(dsa_key->dk_p_bytes)) - == NULL) - return (-11); - memcpyend(dsa_key->dk_y, s + s_len - len, len, - dsa_key->dk_p_bytes); - } else { - EREPORT(("Decode_DSAKey(): Bad keyword %s\n", p)); - return (-12); - } - } /* while p */ - - d_key->dk_key_size = dsa_key->dk_p_bytes * 8; - - return (0); -} - - -/************************************************************************** - * dst_cylink_free_key_structure - * Frees all dynamicly allocated structures in DSA_Key. - */ - -static void * -dst_cylink_free_key_structure(void *key) -{ - DSA_Key *d_key = (DSA_Key *) key; - if (d_key != NULL) { - SAFE_FREE(d_key->dk_signer); - SAFE_FREE(d_key->dk_p); - SAFE_FREE(d_key->dk_q); - SAFE_FREE(d_key->dk_g); - SAFE_FREE(d_key->dk_x); - SAFE_FREE(d_key->dk_y); - SAFE_FREE(d_key); - } - return (NULL); -} - - -/************************************************************************** - * dst_cylink_generate_keypair - * Generates unique keys that are hard to predict. - * Parameters - * key generic Key structure - * exp the public exponent - * Return - * 0 Failure - * 1 Success - */ - -static int -dst_cylink_generate_keypair(DST_KEY *key, int nothing) -{ - int status, n; - DSA_Key *dsa; - u_char rand[SHA_LENGTH]; - - UNUSED(nothing); - - if (key == NULL || key->dk_alg != KEY_DSA) - return (0); - - if ((dsa = (DSA_Key *) malloc(sizeof(DSA_Key))) == NULL) { - EREPORT(("dst_cylink_generate_keypair: Memory allocation error 3")); - return (0); - } - memset(dsa, 0, sizeof(*dsa)); - - dsa->dk_p_bytes = key->dk_key_size / 8; - dsa->dk_p = (uchar *) malloc(dsa->dk_p_bytes); - dsa->dk_q = (uchar *) malloc(SHA_LENGTH); - dsa->dk_g = (uchar *) malloc(dsa->dk_p_bytes); - dsa->dk_x = (uchar *) malloc(SHA_LENGTH); - dsa->dk_y = (uchar *) malloc(dsa->dk_p_bytes); - if (!dsa->dk_p || !dsa->dk_q || !dsa->dk_g || !dsa->dk_x || !dsa->dk_y) { - EREPORT(("dst_cylink_generate_keypair: Memory allocation error 4")); - return (0); - } - n = dst_random(DST_RAND_KEY, sizeof(rand), rand); - if (n != sizeof(rand)) - return (0); - status = GenDSSParameters(dsa->dk_p_bytes, dsa->dk_p, dsa->dk_q, - dsa->dk_g, rand, NULL); - if (status != SUCCESS) - return (0); - - status = GenDSSKey(dsa->dk_p_bytes, dsa->dk_p, dsa->dk_q, dsa->dk_g, - dsa->dk_x, dsa->dk_y, rand); - if (status != SUCCESS) - return (0); - memset(rand, 0, sizeof(rand)); - key->dk_KEY_struct = (void *) dsa; - return (1); -} - - -/* - * dst_cylink_compare_keys - * Compare two keys for equality. - * Return - * 0 The keys are equal - * NON-ZERO The keys are not equal - */ - -static int -dst_cylink_compare_keys(const DST_KEY *key1, const DST_KEY *key2) -{ - int status; - DSA_Key *dkey1 = (DSA_Key *) key1->dk_KEY_struct; - DSA_Key *dkey2 = (DSA_Key *) key2->dk_KEY_struct; - - if (dkey1 == NULL && dkey2 == NULL) - return (0); - else if (dkey1 == NULL) - return (2); - else if (dkey2 == NULL) - return(1); - - if (dkey1->dk_p_bytes != dkey2->dk_p_bytes) - return (201); - status = memcmp(dkey1->dk_p, dkey2->dk_p, dkey1->dk_p_bytes) || - memcmp(dkey1->dk_q, dkey2->dk_q, SHA_LENGTH) || - memcmp(dkey1->dk_g, dkey2->dk_g, dkey1->dk_p_bytes) || - memcmp(dkey1->dk_y, dkey2->dk_y, dkey1->dk_p_bytes); - if (status) - return (status); - if (dkey1->dk_x || dkey2->dk_x) { - if (dkey1->dk_x == NULL || dkey2->dk_x == NULL) - return (202); - return (memcmp(dkey1->dk_x, dkey2->dk_x, dkey1->dk_p_bytes)); - } else - return (0); -} - -static void * -memcpyend(void *dest, const void *src, size_t n, size_t size) { - if (n < size) - memset(dest, 0, size - n); - memcpy((char *)dest + size - n, src, n); - return dest; -} - -#else -int -dst_cylink_init() -{ - return (0); -} -#endif /* CYLINK */ diff --git a/usr/src/lib/libresolv2/common/dst/dst_api.c b/usr/src/lib/libresolv2/common/dst/dst_api.c index f074b4a2a0..931af41a88 100644 --- a/usr/src/lib/libresolv2/common/dst/dst_api.c +++ b/usr/src/lib/libresolv2/common/dst/dst_api.c @@ -1,15 +1,8 @@ #ifndef LINT -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/dst_api.c,v 1.21 2002/06/28 06:58:19 marka Exp $"; +static const char rcsid[] = "$Header: /proj/cvs/prod/libbind/dst/dst_api.c,v 1.17 2007/09/24 17:18:25 each Exp $"; #endif /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. * * Permission to use, copy modify, and distribute this software for any @@ -85,7 +78,7 @@ static DST_KEY *dst_s_get_key_struct(const char *name, const int alg, const int flags, const int protocol, const int bits); -/* +/*% * dst_init * This function initializes the Digital Signature Toolkit. * Right now, it just checks the DSTKEYPATH environment variable. @@ -128,14 +121,10 @@ dst_init() } memset(dst_t_func, 0, sizeof(dst_t_func)); /* first one is selected */ - dst_bsafe_init(); - dst_rsaref_init(); dst_hmac_md5_init(); - dst_eay_dss_init(); - dst_cylink_init(); } -/* +/*% * dst_check_algorithm * This function determines if the crypto system for the specified * algorithm is present. @@ -154,7 +143,7 @@ dst_check_algorithm(const int alg) return (dst_t_func[alg] != NULL); } -/* +/*% * dst_s_get_key_struct * This function allocates key structure and fills in some of the * fields of the structure. @@ -174,13 +163,17 @@ dst_s_get_key_struct(const char *name, const int alg, const int flags, { DST_KEY *new_key = NULL; - if (dst_check_algorithm(alg)) /* make sure alg is available */ + if (dst_check_algorithm(alg)) /*%< make sure alg is available */ new_key = (DST_KEY *) malloc(sizeof(*new_key)); if (new_key == NULL) return (NULL); memset(new_key, 0, sizeof(*new_key)); new_key->dk_key_name = strdup(name); + if (new_key->dk_key_name == NULL) { + free(new_key); + return (NULL); + } new_key->dk_alg = alg; new_key->dk_flags = flags; new_key->dk_proto = protocol; @@ -190,7 +183,7 @@ dst_s_get_key_struct(const char *name, const int alg, const int flags, return (new_key); } -/* +/*% * dst_compare_keys * Compares two keys for equality. * Parameters @@ -216,15 +209,13 @@ dst_compare_keys(const DST_KEY *key1, const DST_KEY *key2) return (key1->dk_func->compare(key1, key2)); } - -/* +/*% * dst_sign_data * An incremental signing function. Data is signed in steps. * First the context must be initialized (SIG_MODE_INIT). * Then data is hashed (SIG_MODE_UPDATE). Finally the signature * itself is created (SIG_MODE_FINAL). This function can be called * once with INIT, UPDATE and FINAL modes all set, or it can be - * called separately with a different mode set for each step. The * UPDATE step can be repeated. * Parameters @@ -244,8 +235,8 @@ dst_compare_keys(const DST_KEY *key1, const DST_KEY *key2) * sig_len Length of the signature field in bytes. * Return * 0 Successfull INIT or Update operation - * >0 success FINAL (sign) operation - * <0 failure + * >0 success FINAL (sign) operation + * <0 failure */ int @@ -265,8 +256,7 @@ dst_sign_data(const int mode, DST_KEY *in_key, void **context, return (UNKNOWN_KEYALG); } - -/* +/*% * dst_verify_data * An incremental verify function. Data is verified in steps. * First the context must be initialized (SIG_MODE_INIT). @@ -308,8 +298,7 @@ dst_verify_data(const int mode, DST_KEY *in_key, void **context, signature, sig_len)); } - -/* +/*% * dst_read_private_key * Access a private key. First the list of private keys that have * already been read in is searched, then the key accessed on disk. @@ -338,7 +327,7 @@ dst_read_key(const char *in_keyname, const u_int16_t in_id, char keyname[PATH_MAX]; DST_KEY *dg_key = NULL, *pubkey = NULL; - if (!dst_check_algorithm(in_alg)) { /* make sure alg is available */ + if (!dst_check_algorithm(in_alg)) { /*%< make sure alg is available */ EREPORT(("dst_read_private_key(): Algorithm %d not suppored\n", in_alg)); return (NULL); @@ -348,7 +337,10 @@ dst_read_key(const char *in_keyname, const u_int16_t in_id, if (in_keyname == NULL) { EREPORT(("dst_read_private_key(): Null key name passed in\n")); return (NULL); - } else + } else if (strlen(in_keyname) >= sizeof(keyname)) { + EREPORT(("dst_read_private_key(): keyname too big\n")); + return (NULL); + } else strcpy(keyname, in_keyname); /* before I read in the public key, check if it is allowed to sign */ @@ -359,7 +351,7 @@ dst_read_key(const char *in_keyname, const u_int16_t in_id, return pubkey; if (!(dg_key = dst_s_get_key_struct(keyname, pubkey->dk_alg, - pubkey->dk_flags, pubkey->dk_proto, + pubkey->dk_flags, pubkey->dk_proto, 0))) return (dg_key); /* Fill in private key and some fields in the general key structure */ @@ -367,7 +359,7 @@ dst_read_key(const char *in_keyname, const u_int16_t in_id, pubkey->dk_alg) == 0) dg_key = dst_free_key(dg_key); - pubkey = dst_free_key(pubkey); + (void)dst_free_key(pubkey); return (dg_key); } @@ -378,7 +370,7 @@ dst_write_key(const DST_KEY *key, const int type) if (key == NULL) return (0); - if (!dst_check_algorithm(key->dk_alg)) { /* make sure alg is available */ + if (!dst_check_algorithm(key->dk_alg)) { /*%< make sure alg is available */ EREPORT(("dst_write_key(): Algorithm %d not suppored\n", key->dk_alg)); return (UNSUPPORTED_KEYALG); @@ -395,19 +387,19 @@ dst_write_key(const DST_KEY *key, const int type) return (priv+pub); } -/* +/*% * dst_write_private_key * Write a private key to disk. The filename will be of the form: - * K<key->dk_name>+<key->dk_alg>+<key->dk_id>.<private key suffix>. + * K<key->dk_name>+<key->dk_alg+><key-d>k_id.><private key suffix>. * If there is already a file with this name, an error is returned. * * Parameters * key A DST managed key structure that contains * all information needed about a key. * Return - * >= 0 Correct behavior. Returns length of encoded key value + * >= 0 Correct behavior. Returns length of encoded key value * written to disk. - * < 0 error. + * < 0 error. */ static int @@ -422,8 +414,7 @@ dst_s_write_private_key(const DST_KEY *key) if (key == NULL) return (-1); if (key->dk_KEY_struct == NULL) - return (0); /* null key has no private key */ - + return (0); /*%< null key has no private key */ if (key->dk_func == NULL || key->dk_func->to_file_fmt == NULL) { EREPORT(("dst_write_private_key(): Unsupported operation %d\n", key->dk_alg)); @@ -443,6 +434,7 @@ dst_s_write_private_key(const DST_KEY *key) if ((nn = fwrite(encoded_block, 1, len, fp)) != len) { EREPORT(("dst_write_private_key(): Write failure on %s %d != %d errno=%d\n", file, len, nn, errno)); + fclose(fp); return (-5); } fclose(fp); @@ -455,12 +447,12 @@ dst_s_write_private_key(const DST_KEY *key) return (len); } -/* +/*% * * dst_read_public_key * Read a public key from disk and store in a DST key structure. * Parameters - * in_name K<in_name><in_id>.<public key suffix> is the + * in_name K<in_name><in_id>.<public key suffix> is the * filename of the key file to be read. * Returns * NULL If the key does not exist or no name is supplied. @@ -489,7 +481,7 @@ dst_s_read_public_key(const char *in_name, const u_int16_t in_id, int in_alg) /* * Open the file and read it's formatted contents up to key * File format: - * domain.name [ttl] [IN] KEY <flags> <protocol> <algorithm> <key> + * domain.name [ttl] [IN] KEY <flags> <protocol> <algorithm> <key> * flags, proto, alg stored as decimal (or hex numbers FIXME). * (FIXME: handle parentheses for line continuation.) */ @@ -536,7 +528,7 @@ dst_s_read_public_key(const char *in_name, const u_int16_t in_id, int in_alg) while ((c = getc(fp)) != EOF) if (!isspace(c)) break; - ungetc(c, fp); /* return the charcter to the input field */ + ungetc(c, fp); /*%< return the charcter to the input field */ /* Handle hex!! FIXME. */ if (fscanf(fp, "%d %d %d", &flags, &proto, &alg) != 3) { @@ -579,8 +571,7 @@ dst_s_read_public_key(const char *in_name, const u_int16_t in_id, int in_alg) return dst_buffer_to_key(in_name, alg, flags, proto, deckey, dlen); } - -/* +/*% * dst_write_public_key * Write a key to disk in DNS format. * Parameters @@ -634,8 +625,7 @@ dst_s_write_public_key(const DST_KEY *key) return (1); } - -/* +/*% * dst_dnskey_to_public_key * This function converts the contents of a DNS KEY RR into a DST * key structure. @@ -656,19 +646,21 @@ dst_dnskey_to_key(const char *in_name, const u_char *rdata, const int len) int alg ; int start = DST_KEY_START; - if (rdata == NULL || len <= DST_KEY_ALG) /* no data */ + if (rdata == NULL || len <= DST_KEY_ALG) /*%< no data */ return (NULL); alg = (u_int8_t) rdata[DST_KEY_ALG]; - if (!dst_check_algorithm(alg)) { /* make sure alg is available */ + if (!dst_check_algorithm(alg)) { /*%< make sure alg is available */ EREPORT(("dst_dnskey_to_key(): Algorithm %d not suppored\n", alg)); return (NULL); } - if ((key_st = dst_s_get_key_struct(in_name, alg, 0, 0, 0)) == NULL) - return (NULL); if (in_name == NULL) return (NULL); + + if ((key_st = dst_s_get_key_struct(in_name, alg, 0, 0, 0)) == NULL) + return (NULL); + key_st->dk_id = dst_s_dns_key_id(rdata, len); key_st->dk_flags = dst_s_get_int16(rdata); key_st->dk_proto = (u_int16_t) rdata[DST_KEY_PROT]; @@ -694,8 +686,7 @@ dst_dnskey_to_key(const char *in_name, const u_char *rdata, const int len) return (key_st); } - -/* +/*% * dst_public_key_to_dnskey * Function to encode a public key into DNS KEY wire format * Parameters @@ -717,7 +708,7 @@ dst_key_to_dnskey(const DST_KEY *key, u_char *out_storage, if (key == NULL) return (-1); - if (!dst_check_algorithm(key->dk_alg)) { /* make sure alg is available */ + if (!dst_check_algorithm(key->dk_alg)) { /*%< make sure alg is available */ EREPORT(("dst_key_to_dnskey(): Algorithm %d not suppored\n", key->dk_alg)); return (UNSUPPORTED_KEYALG); @@ -730,7 +721,7 @@ dst_key_to_dnskey(const DST_KEY *key, u_char *out_storage, out_storage[loc++] = (u_char) key->dk_proto; out_storage[loc++] = (u_char) key->dk_alg; - if (key->dk_flags > 0xffff) { /* Extended flags */ + if (key->dk_flags > 0xffff) { /*%< Extended flags */ val = (u_int16_t)((key->dk_flags >> 16) & 0xffff); dst_s_put_int16(&out_storage[loc], val); loc += 2; @@ -751,8 +742,7 @@ dst_key_to_dnskey(const DST_KEY *key, u_char *out_storage, return (-1); } - -/* +/*% * dst_buffer_to_key * Function to encode a string of raw data into a DST key * Parameters @@ -764,30 +754,28 @@ dst_key_to_dnskey(const DST_KEY *key, u_char *out_storage, * NON-NULL the DST key */ DST_KEY * -dst_buffer_to_key(const char *key_name, /* name of the key */ - const int alg, /* algorithm */ - const int flags, /* dns flags */ - const int protocol, /* dns protocol */ - const u_char *key_buf, /* key in dns wire fmt */ - const int key_len) /* size of key */ +dst_buffer_to_key(const char *key_name, /*!< name of the key */ + const int alg, /*!< algorithm */ + const int flags, /*!< dns flags */ + const int protocol, /*!< dns protocol */ + const u_char *key_buf, /*!< key in dns wire fmt */ + const int key_len) /*!< size of key */ { DST_KEY *dkey = NULL; int dnslen; u_char dns[2048]; - if (!dst_check_algorithm(alg)) { /* make sure alg is available */ + if (!dst_check_algorithm(alg)) { /*%< make sure alg is available */ EREPORT(("dst_buffer_to_key(): Algorithm %d not suppored\n", alg)); return (NULL); } - dkey = dst_s_get_key_struct(key_name, alg, flags, - protocol, -1); + dkey = dst_s_get_key_struct(key_name, alg, flags, protocol, -1); - if (dkey == NULL) - return (NULL); - if (dkey->dk_func == NULL || dkey->dk_func->from_dns_key == NULL) - return NULL; + if (dkey == NULL || dkey->dk_func == NULL || + dkey->dk_func->from_dns_key == NULL) + return (dst_free_key(dkey)); if (dkey->dk_func->from_dns_key(dkey, key_buf, key_len) < 0) { EREPORT(("dst_buffer_to_key(): dst_buffer_to_hmac failed\n")); @@ -815,8 +803,7 @@ dst_key_to_buffer(DST_KEY *key, u_char *out_buff, int buf_len) return (0); } - -/* +/*% * dst_s_read_private_key_file * Function reads in private key from a file. * Fills out the KEY structure. @@ -873,7 +860,8 @@ dst_s_read_private_key_file(char *name, DST_KEY *pk_key, u_int16_t in_id, len = cnt; p = in_buff; - if (!dst_s_verify_str((const char **) &p, "Private-key-format: v")) { + if (!dst_s_verify_str((const char **) (void *)&p, + "Private-key-format: v")) { EREPORT(("dst_s_read_private_key_file(): Not a Key file/Decrypt failed %s\n", name)); goto fail; } @@ -889,14 +877,14 @@ dst_s_read_private_key_file(char *name, DST_KEY *pk_key, u_int16_t in_id, "dst_s_read_private_key_file(): Keyfile %s version higher than mine %d.%d MAY FAIL\n", name, file_major, file_minor)); - while (*p++ != '\n') ; /* skip to end of line */ + while (*p++ != '\n') ; /*%< skip to end of line */ - if (!dst_s_verify_str((const char **) &p, "Algorithm: ")) + if (!dst_s_verify_str((const char **) (void *)&p, "Algorithm: ")) goto fail; if (sscanf((char *)p, "%d", &alg) != 1) goto fail; - while (*p++ != '\n') ; /* skip to end of line */ + while (*p++ != '\n') ; /*%< skip to end of line */ if (pk_key->dk_key_name && !strcmp(pk_key->dk_key_name, name)) SAFE_FREE2(pk_key->dk_key_name, strlen(pk_key->dk_key_name)); @@ -929,34 +917,34 @@ dst_s_read_private_key_file(char *name, DST_KEY *pk_key, u_int16_t in_id, return (0); } - -/* - * dst_generate_key +/*% * Generate and store a public/private keypair. * Keys will be stored in formatted files. + * * Parameters - * name Name of the new key. Used to create key files - * K<name>+<alg>+<id>.public and K<name>+<alg>+<id>.private. - * bits Size of the new key in bits. - * exp What exponent to use: - * 0 use exponent 3 - * non-zero use Fermant4 - * flags The default value of the DNS Key flags. - * The DNS Key RR Flag field is defined in RFC 2065, + & + *\par name Name of the new key. Used to create key files + *\li K<name>+<alg>+<id>.public and K<name>+<alg>+<id>.private. + *\par bits Size of the new key in bits. + *\par exp What exponent to use: + *\li 0 use exponent 3 + *\li non-zero use Fermant4 + *\par flags The default value of the DNS Key flags. + *\li The DNS Key RR Flag field is defined in RFC2065, * section 3.3. The field has 16 bits. - * protocol - * Default value of the DNS Key protocol field. - * The DNS Key protocol field is defined in RFC 2065, + *\par protocol + *\li Default value of the DNS Key protocol field. + *\li The DNS Key protocol field is defined in RFC2065, * section 3.4. The field has 8 bits. - * alg What algorithm to use. Currently defined: - * KEY_RSA 1 - * KEY_DSA 3 - * KEY_HMAC 157 - * out_id The key tag is returned. + *\par alg What algorithm to use. Currently defined: + *\li KEY_RSA 1 + *\li KEY_DSA 3 + *\li KEY_HMAC 157 + *\par out_id The key tag is returned. * * Return - * NULL Failure - * non-NULL the generated key pair + *\li NULL Failure + *\li non-NULL the generated key pair * Caller frees the result, and its dk_name pointer. */ DST_KEY * @@ -964,14 +952,13 @@ dst_generate_key(const char *name, const int bits, const int exp, const int flags, const int protocol, const int alg) { DST_KEY *new_key = NULL; - int res; int dnslen; u_char dns[2048]; if (name == NULL) return (NULL); - if (!dst_check_algorithm(alg)) { /* make sure alg is available */ + if (!dst_check_algorithm(alg)) { /*%< make sure alg is available */ EREPORT(("dst_generate_key(): Algorithm %d not suppored\n", alg)); return (NULL); } @@ -979,14 +966,14 @@ dst_generate_key(const char *name, const int bits, const int exp, new_key = dst_s_get_key_struct(name, alg, flags, protocol, bits); if (new_key == NULL) return (NULL); - if (bits == 0) /* null key we are done */ + if (bits == 0) /*%< null key we are done */ return (new_key); if (new_key->dk_func == NULL || new_key->dk_func->generate == NULL) { EREPORT(("dst_generate_key_pair():Unsupported algorithm %d\n", alg)); return (dst_free_key(new_key)); } - if ((res = new_key->dk_func->generate(new_key, exp)) <= 0) { + if (new_key->dk_func->generate(new_key, exp) <= 0) { EREPORT(("dst_generate_key_pair(): Key generation failure %s %d %d %d\n", new_key->dk_key_name, new_key->dk_alg, new_key->dk_key_size, exp)); @@ -1002,12 +989,11 @@ dst_generate_key(const char *name, const int bits, const int exp, return (new_key); } - -/* - * dst_free_key +/*% * Release all data structures pointed to by a key structure. + * * Parameters - * f_key Key structure to be freed. + *\li f_key Key structure to be freed. */ DST_KEY * @@ -1022,7 +1008,6 @@ dst_free_key(DST_KEY *f_key) else { EREPORT(("dst_free_key(): Unknown key alg %d\n", f_key->dk_alg)); - free(f_key->dk_KEY_struct); /* SHOULD NOT happen */ } if (f_key->dk_KEY_struct) { free(f_key->dk_KEY_struct); @@ -1034,13 +1019,14 @@ dst_free_key(DST_KEY *f_key) return (NULL); } -/* - * dst_sig_size +/*% * Return the maximim size of signature from the key specified in bytes + * * Parameters - * key + *\li key + * * Returns - * bytes + * \li bytes */ int dst_sig_size(DST_KEY *key) { @@ -1059,42 +1045,4 @@ dst_sig_size(DST_KEY *key) { } } -/* - * dst_random - * function that multiplexes number of random number generators - * Parameters - * mode: select the random number generator - * wanted is how many bytes of random data are requested - * outran is a buffer of size at least wanted for the output data - * - * Returns - * number of bytes written to outran - */ -int -dst_random(const int mode, int wanted, u_char *outran) -{ - u_int32_t *buff = NULL, *bp = NULL; - int i; - if (wanted <= 0 || outran == NULL) - return (0); - - switch (mode) { - case DST_RAND_SEMI: - bp = buff = (u_int32_t *) malloc(wanted+sizeof(u_int32_t)); - for (i = 0; i < wanted; i+= sizeof(u_int32_t), bp++) { - *bp = dst_s_quick_random(i); - } - memcpy(outran, buff, wanted); - SAFE_FREE(buff); - return (wanted); - case DST_RAND_STD: - return (dst_s_semi_random(outran, wanted)); - case DST_RAND_KEY: - return (dst_s_random(outran, wanted)); - case DST_RAND_DSS: - default: - /* need error case here XXX OG */ - return (0); - } -} - +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/dst/dst_internal.h b/usr/src/lib/libresolv2/common/dst/dst_internal.h index 05f2c48bbc..e9bc6fc08d 100644 --- a/usr/src/lib/libresolv2/common/dst/dst_internal.h +++ b/usr/src/lib/libresolv2/common/dst/dst_internal.h @@ -1,10 +1,3 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #ifndef DST_INTERNAL_H #define DST_INTERNAL_H @@ -36,19 +29,19 @@ # ifdef POSIX_PATH_MAX # define PATH_MAX POSIX_PATH_MAX # else -# define PATH_MAX 255 /* this is the value of POSIX_PATH_MAX */ +# define PATH_MAX 255 /*%< this is the value of POSIX_PATH_MAX */ # endif #endif typedef struct dst_key { - char *dk_key_name; /* name of the key */ - int dk_key_size; /* this is the size of the key in bits */ - int dk_proto; /* what protocols this key can be used for */ - int dk_alg; /* algorithm number from key record */ - u_int32_t dk_flags; /* and the flags of the public key */ - u_int16_t dk_id; /* identifier of the key */ - void *dk_KEY_struct; /* pointer to key in crypto pkg fmt */ - struct dst_func *dk_func; /* point to cryptto pgk specific function table */ + char *dk_key_name; /*%< name of the key */ + int dk_key_size; /*%< this is the size of the key in bits */ + int dk_proto; /*%< what protocols this key can be used for */ + int dk_alg; /*%< algorithm number from key record */ + u_int32_t dk_flags; /*%< and the flags of the public key */ + u_int16_t dk_id; /*%< identifier of the key */ + void *dk_KEY_struct; /*%< pointer to key in crypto pkg fmt */ + struct dst_func *dk_func; /*%< point to cryptto pgk specific function table */ } DST_KEY; #define HAS_DST_KEY @@ -80,7 +73,7 @@ typedef struct dst_key { #ifndef SAFE_FREE #define SAFE_FREE(a) \ do{if(a != NULL){memset(a,0, sizeof(*a)); free(a); a=NULL;}} while (0) -#define SAFE_FREE2(a,s) if (a != NULL && s > 0){memset(a,0, s);free(a); a=NULL;} +#define SAFE_FREE2(a,s) if (a != NULL && (long)s > 0){memset(a,0, s);free(a); a=NULL;} #endif typedef struct dst_func { @@ -110,7 +103,7 @@ extern const char *key_file_fmt_str; extern const char *dst_path; #ifndef DST_HASH_SIZE -#define DST_HASH_SIZE 20 /* RIPEMD160 and SHA-1 are 20 bytes MD5 is 16 */ +#define DST_HASH_SIZE 20 /*%< RIPEMD160 and SHA-1 are 20 bytes MD5 is 16 */ #endif int dst_bsafe_init(void); @@ -123,14 +116,6 @@ int dst_cylink_init(void); int dst_eay_dss_init(void); -/* support functions */ -/* base64 to bignum conversion routines */ -int dst_s_conv_bignum_u8_to_b64( char *out_buf, const int out_len, - const char *header, - const u_int8_t *bin_data, - const int bin_len); -int dst_s_conv_bignum_b64_to_u8( const char **buf, u_int8_t *loc, - const int loclen) ; /* from higher level support routines */ int dst_s_calculate_bits( const u_int8_t *str, const int max_bits); int dst_s_verify_str( const char **buf, const char *str); @@ -144,13 +129,7 @@ int dst_s_build_filename( char *filename, const char *name, FILE *dst_s_fopen (const char *filename, const char *mode, int perm); -/* from file prandom.c */ -int dst_s_random( u_int8_t *output, int size); -int dst_s_semi_random( u_int8_t *output, int size); -u_int32_t dst_s_quick_random( int inc); -void dst_s_quick_random_set( u_int32_t val, u_int32_t cnt); - -/* +/*% * read and write network byte order into u_int?_t * all of these should be retired */ @@ -173,3 +152,4 @@ dst_s_dump(const int mode, const u_char *data, const int size, #endif /* DST_INTERNAL_H */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/dst/eay_dss_link.c b/usr/src/lib/libresolv2/common/dst/eay_dss_link.c deleted file mode 100644 index 5216010cd2..0000000000 --- a/usr/src/lib/libresolv2/common/dst/eay_dss_link.c +++ /dev/null @@ -1,637 +0,0 @@ -/* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef EAY_DSS -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/eay_dss_link.c,v 1.6 2001/05/29 05:48:09 marka Exp $"; - -/* - * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. - * - * Permission to use, copy modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND TRUSTED INFORMATION SYSTEMS - * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL - * TRUSTED INFORMATION SYSTEMS BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THE SOFTWARE. - */ -/* - * This file contains two components - * 1. Interface to the EAY libcrypto library to allow compilation of Bind - * with TIS/DNSSEC when EAY libcrypto is not available - * all calls to libcrypto are contained inside this file. - * 2. The glue to connvert DSA KEYS to and from external formats - */ -#include "port_before.h" - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#include <memory.h> -#include <sys/param.h> -#include <sys/time.h> -#include <netinet/in.h> - -#include "dst_internal.h" - -#include "crypto.h" -#include "bn.h" -#include "dsa.h" -#include "sha.h" - -#include "port_after.h" - - -static int dst_eay_dss_sign(const int mode, DST_KEY *dkey, void **context, - const u_char *data, const int len, - u_char *signature, const int sig_len); - -static int dst_eay_dss_verify(const int mode, DST_KEY *dkey, void **context, - const u_char *data, const int len, - const u_char *signature, const int sig_len); - -static int dst_eay_dss_to_dns_key(const DST_KEY *in_key, u_char *out_str, - const int out_len); -static int dst_eay_dss_from_dns_key(DST_KEY *s_key, const u_char *key, - const int len); -static int dst_eay_dss_key_to_file_format(const DST_KEY *key, u_char *buff, - const int buff_len); -static int dst_eay_dss_key_from_file_format(DST_KEY *d_key, - const u_char *buff, - const int buff_len); -static void *dst_eay_dss_free_key_structure(void *key); - -static int dst_eay_dss_generate_keypair(DST_KEY *key, int exp); -static int dst_eay_dss_compare_keys(const DST_KEY *key1, const DST_KEY *key2); - -/* - * dst_eay_dss_init() Function to answer set up function pointers for - * EAY DSS related functions - */ -int -dst_eay_dss_init(void) -{ - if (dst_t_func[KEY_DSA] != NULL) - return (1); - dst_t_func[KEY_DSA] = malloc(sizeof(struct dst_func)); - if (dst_t_func[KEY_DSA] == NULL) - return (0); - memset(dst_t_func[KEY_DSA], 0, sizeof(struct dst_func)); - dst_t_func[KEY_DSA]->sign = dst_eay_dss_sign; - dst_t_func[KEY_DSA]->verify = dst_eay_dss_verify; - dst_t_func[KEY_DSA]->compare = dst_eay_dss_compare_keys; - dst_t_func[KEY_DSA]->generate = dst_eay_dss_generate_keypair; - dst_t_func[KEY_DSA]->destroy = dst_eay_dss_free_key_structure; - dst_t_func[KEY_DSA]->from_dns_key = dst_eay_dss_from_dns_key; - dst_t_func[KEY_DSA]->to_dns_key = dst_eay_dss_to_dns_key; - dst_t_func[KEY_DSA]->from_file_fmt = dst_eay_dss_key_from_file_format; - dst_t_func[KEY_DSA]->to_file_fmt = dst_eay_dss_key_to_file_format; - return (1); -} - -/* - * dst_eay_dss_sign - * Call EAY DSS signing functions to sign a block of data. - * There are three steps to signing, INIT (initialize structures), - * UPDATE (hash (more) data), FINAL (generate a signature). This - * routine performs one or more of these steps. - * Parameters - * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL. - * algobj structure holds context for a sign done in multiple calls. - * context the context to use for this computation - * data data to be signed. - * len length in bytes of data. - * priv_key key to use for signing. - * signature location to store signature. - * sig_len size in bytes of signature field. - * returns - * N Success on SIG_MODE_FINAL = returns signature length in bytes - * N is 41 for DNS - * 0 Success on SIG_MODE_INIT and UPDATE - * <0 Failure - */ - -static int -dst_eay_dss_sign(const int mode, DST_KEY *dkey, void **context, - const u_char *data, const int len, - u_char *signature, const int sig_len) -{ - int sign_len = 0; - int status; - SHA_CTX *ctx = NULL; - - if (mode & SIG_MODE_INIT) - ctx = (SHA_CTX *) malloc(sizeof(SHA_CTX)); - else if (context) - ctx = (SHA_CTX *) *context; - if (ctx == NULL) - return (-1); - - if (mode & SIG_MODE_INIT) - SHA1_Init(ctx); - - if ((mode & SIG_MODE_UPDATE) && (data && len > 0)) { - SHA1_Update(ctx, (u_char *) data, len); - } - if (mode & SIG_MODE_FINAL) { - DSA *key; - u_char digest[SHA_DIGEST_LENGTH]; - u_char rand[SHA_DIGEST_LENGTH]; - u_char r[SHA_DIGEST_LENGTH], s[SHA_DIGEST_LENGTH]; - - if (dkey == NULL || dkey->dk_KEY_struct == NULL) - return (-1); - key = dkey->dk_KEY_struct; - if (key == NULL) - return(-2); - SHA1_Final(digest, ctx); - status = DSA_sign(0, digest, SHA_DIGEST_LENGTH, - signature, &sign_len, key); - if (status != 0) - return (SIGN_FINAL_FAILURE); - - *signature = (dkey->dk_key_size - 512)/64; - sign_len = 1; - memcpy(signature + sign_len, r, SHA_DIGEST_LENGTH); - sign_len += SHA_DIGEST_LENGTH; - memcpy(signature + sign_len, s, SHA_DIGEST_LENGTH); - sign_len += SHA_DIGEST_LENGTH; - } - else { - if (context == NULL) - return (-1); - *context = (void *) ctx; - } - return (sign_len); -} - - -/* - * dst_eay_dss_verify - * Calls EAY DSS verification routines. There are three steps to - * verification, INIT (initialize structures), UPDATE (hash (more) data), - * FINAL (generate a signature). This routine performs one or more of - * these steps. - * Parameters - * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL. - * dkey structure holds context for a verify done in multiple calls. - * context algorithm specific context for the current context processing - * data data signed. - * len length in bytes of data. - * pub_key key to use for verify. - * signature signature. - * sig_len length in bytes of signature. - * returns - * 0 Success - * <0 Failure - */ - -static int -dst_eay_dss_verify(const int mode, DST_KEY *dkey, void **context, - const u_char *data, const int len, - const u_char *signature, const int sig_len) -{ - int status; - SHA_CTX *ctx = NULL; - - if (mode & SIG_MODE_INIT) - ctx = (SHA_CTX *) malloc(sizeof(SHA_CTX)); - else if (context) - ctx = (SHA_CTX *) *context; - if (ctx == NULL) - return (-1); - - if (mode & SIG_MODE_INIT) - SHA1_Init(ctx); - - if ((mode & SIG_MODE_UPDATE) && (data && len > 0)) { - SHA1_Update(ctx, (u_char *) data, len); - } - if (mode & SIG_MODE_FINAL) { - DSA *key; - u_char digest[SHA_DIGEST_LENGTH]; - u_char r[SHA_DIGEST_LENGTH], s[SHA_DIGEST_LENGTH]; - - if (dkey == NULL || dkey->dk_KEY_struct == NULL) - return (-1); - key = (DSA *) dkey->dk_KEY_struct; - if (key = NULL) - return (-2); - if (signature == NULL || sig_len != (2 * SHA_DIGEST_LENGTH +1)) - return (SIGN_FINAL_FAILURE); - SHA1_Final(digest, ctx); - SAFE_FREE(ctx); - if (status != 0) - return (SIGN_FINAL_FAILURE); - if (((int)*signature) != ((BN_num_bytes(key->p) -64)/8)) - return(VERIFY_FINAL_FAILURE); - - memcpy(r, signature +1, SHA_DIGEST_LENGTH); - memcpy(s, signature + SHA_DIGEST_LENGTH +1, SHA_DIGEST_LENGTH); - status = DSA_verify(0, digest, SHA_DIGEST_LENGTH, - (u_char *)signature, sig_len, key); - if (status != 0) - return (VERIFY_FINAL_FAILURE); - } - else { - if (context == NULL) - return (-1); - *context = (void *) ctx; - } - return (0); -} - - -/* - * dst_eay_dss_to_dns_key - * Converts key from DSA to DNS distribution format - * This function gets in a pointer to the public key and a work area - * to write the key into. - * Parameters - * public KEY structure - * out_str buffer to write encoded key into - * out_len size of out_str - * Return - * N >= 0 length of encoded key - * n < 0 error - */ - -static int -dst_eay_dss_to_dns_key(const DST_KEY *in_key, u_char *out_str, - const int out_len) -{ - u_char *op = out_str; - int t; - DSA *key; - - if (in_key == NULL || in_key->dk_KEY_struct == NULL || - out_len <= 0 || out_str == NULL) - return (-1); - key = (DSA *) in_key->dk_KEY_struct; - - t = (BN_num_bytes(key->p) - 64) / 8; - - *op++ = t; - BN_bn2bin(key->q, op); - op += BN_num_bytes(key->q); - BN_bn2bin(key->p, op); - op += BN_num_bytes(key->p); - BN_bn2bin(key->g, op); - op += BN_num_bytes(key->g); - BN_bn2bin(key->pub_key, op); - op += BN_num_bytes(key->pub_key); - - return (op - out_str); -} - - -/* - * dst_eay_dss_from_dns_key - * Converts from a DNS KEY RR format to an RSA KEY. - * Parameters - * len Length in bytes of DNS key - * key DNS key - * name Key name - * s_key DST structure that will point to the RSA key this routine - * will build. - * Return - * 0 The input key, s_key or name was null. - * 1 Success - */ -static int -dst_eay_dss_from_dns_key(DST_KEY *s_key, const u_char *key, const int len) -{ - int t; - u_char *key_ptr = (u_char *)key; - DSA *d_key; - int p_bytes; - - if (s_key == NULL || len < 0 || key == NULL) - return (0); - - if (len == 0) /* process null key */ - return (1); - - if (key_ptr == NULL) - return (0); - t = (int) *key_ptr++; /* length of exponent in bytes */ - p_bytes = 64 + 8 * t; - - if ((3 * (t * 8 + 64) + SHA_DIGEST_LENGTH + 1) != len) - return (0); - - if ((d_key = (DSA *) malloc(sizeof(DSA))) == NULL) { - EREPORT(("dst_eay_dss_from_dns_key(): Memory allocation error 1")); - return (0); - } - memset(d_key, 0, sizeof(DSA)); - s_key->dk_KEY_struct = (void *) d_key; - - d_key->q = BN_bin2bn(key_ptr, SHA_DIGEST_LENGTH, NULL); - key_ptr += SHA_DIGEST_LENGTH; - - d_key->p = BN_bin2bn(key_ptr, p_bytes, NULL); - key_ptr += p_bytes; - - d_key->g = BN_bin2bn(key_ptr, p_bytes, NULL); - key_ptr += p_bytes; - - d_key->pub_key = BN_bin2bn(key_ptr, p_bytes, NULL); - key_ptr += p_bytes; - - s_key->dk_key_size = p_bytes * 8; - return (1); -} - - -/************************************************************************** - * dst_eay_dss_key_to_file_format - * Encodes an DSA Key into the portable file format. - * Parameters - * key DSA KEY structure - * buff output buffer - * buff_len size of output buffer - * Return - * 0 Failure - null input rkey - * -1 Failure - not enough space in output area - * N Success - Length of data returned in buff - */ - -static int -dst_eay_dss_key_to_file_format(const DST_KEY *key, u_char *buff, - const int buff_len) -{ - u_char *bp; - int len, b_len; - DSA *dkey; - char num[256]; /* More than long enough for DSA keys */ - - if (key == NULL || key->dk_KEY_struct == NULL) /* no output */ - return (0); - if (buff == NULL || buff_len <= (int) strlen(key_file_fmt_str)) - return (-1); /* no OR not enough space in output area */ - - dkey = (DSA *) key->dk_KEY_struct; - - memset(buff, 0, buff_len); /* just in case */ - /* write file header */ - sprintf(buff, key_file_fmt_str, KEY_FILE_FORMAT, KEY_DSA, "DSA"); - - bp = (char *) strchr(buff, '\0'); - b_len = buff_len - (bp - buff); - memcpy(num, dkey->p, BN_num_bytes(dkey->p)); - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Prime(p): ", num, - BN_num_bytes(dkey->p))) <= 0) - return (-1); - - bp = (char *) strchr(buff, '\0'); - b_len = buff_len - (bp - buff); - memcpy(num, dkey->q, BN_num_bytes(dkey->q)); - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Subprime(q): ", num, - BN_num_bytes(dkey->q))) <= 0) - return (-2); - - bp = (char *) strchr(buff, '\0'); - b_len = buff_len - (bp - buff); - memcpy(num, dkey->g, BN_num_bytes(dkey->g)); - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Base(g): ", num, - BN_num_bytes(dkey->g))) <= 0) - return (-3); - - bp = (char *) strchr(buff, '\0'); - b_len = buff_len - (bp - buff); - memcpy(num, dkey->priv_key, BN_num_bytes(dkey->priv_key)); - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Private_value(x): ", - num, - BN_num_bytes(dkey->priv_key))) - <= 0) - return (-4); - - bp = (char *) strchr(buff, '\0'); - b_len = buff_len - (bp - buff); - memcpy(num, dkey->pub_key, BN_num_bytes(dkey->pub_key)); - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Public_value(y): ", - num, - BN_num_bytes(dkey->pub_key))) - <= 0) - return (-5); - - bp += len; - b_len -= len; - return (buff_len - b_len); -} - - -/************************************************************************** - * dst_eay_dss_key_from_file_format - * Converts contents of a private key file into a private DSA key. - * Parameters - * d_key structure to put key into - * buff buffer containing the encoded key - * buff_len the length of the buffer - * Return - * n >= 0 Foot print of the key converted - * n < 0 Error in conversion - */ - -static int -dst_eay_dss_key_from_file_format(DST_KEY *d_key, const u_char *buff, - const int buff_len) -{ - char s[128]; - int len, s_len = sizeof(s); - const char *p = buff; - DSA *dsa_key; - - if (d_key == NULL || buff == NULL || buff_len <= 0) - return (-1); - - dsa_key = (DSA *) malloc(sizeof(DSA)); - if (dsa_key == NULL) { - return (-2); - } - memset(dsa_key, 0, sizeof(*dsa_key)); - d_key->dk_KEY_struct = (void *) dsa_key; - - if (!dst_s_verify_str(&p, "Prime(p): ")) - return (-3); - memset(s, 0, s_len); - if ((len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len)) == 0) - return (-4); - dsa_key->p = BN_bin2bn (s, len, NULL); - if (dsa_key->p == NULL) - return(-5); - - while (*++p && p < (const char *) &buff[buff_len]) { - if (dst_s_verify_str(&p, "Subprime(q): ")) { - if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len))) - return (-6); - dsa_key->q = BN_bin2bn (s, len, NULL); - if (dsa_key->q == NULL) - return (-7); - } else if (dst_s_verify_str(&p, "Base(g): ")) { - if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len))) - return (-8); - dsa_key->g = BN_bin2bn (s, len, NULL); - if (dsa_key->g == NULL) - return (-9); - } else if (dst_s_verify_str(&p, "Private_value(x): ")) { - if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len))) - return (-10); - dsa_key->priv_key = BN_bin2bn (s, len, NULL); - if (dsa_key->priv_key == NULL) - return (-11); - } else if (dst_s_verify_str(&p, "Public_value(y): ")) { - if (!(len = dst_s_conv_bignum_b64_to_u8(&p, s, s_len))) - return (-12); - dsa_key->pub_key = BN_bin2bn (s, len, NULL); - if (dsa_key->pub_key == NULL) - return (-13); - } else { - EREPORT(("Decode_DSAKey(): Bad keyword %s\n", p)); - return (-14); - } - } /* while p */ - - d_key->dk_key_size = BN_num_bytes(dsa_key->p); - - return (0); -} - - -/************************************************************************** - * dst_eay_dss_free_key_structure - * Frees all dynamicly allocated structures in DSA. - */ - -static void * -dst_eay_dss_free_key_structure(void *key) -{ - DSA *d_key = (DSA *) key; - if (d_key != NULL) { - BN_free(d_key->p); - BN_free(d_key->q); - BN_free(d_key->g); - if (d_key->pub_key) - BN_free(d_key->pub_key); - if (d_key->priv_key) - BN_free(d_key->priv_key); - SAFE_FREE(d_key); - } - return (NULL); -} - - -/************************************************************************** - * dst_eay_dss_generate_keypair - * Generates unique keys that are hard to predict. - * Parameters - * key generic Key structure - * exp the public exponent - * Return - * 0 Failure - * 1 Success - */ - -static int -dst_eay_dss_generate_keypair(DST_KEY *key, int nothing) -{ - int status, n; - DSA *dsa; - u_char rand[SHA_DIGEST_LENGTH]; - - if (key == NULL || key->dk_alg != KEY_DSA) - return (0); - - if ((dsa = (DSA *) malloc(sizeof(DSA))) == NULL) { - EREPORT(("dst_eay_dss_generate_keypair: Memory allocation error 3")); - return (0); - } - memset(dsa, 0, sizeof(*dsa)); - - n = dst_random(DST_RAND_KEY, sizeof(rand), rand); - if (n != sizeof(rand)) - return (0); - dsa = DSA_generate_parameters(key->dk_key_size, rand, 20, NULL, NULL, - NULL, NULL); - - if (!dsa) { - EREPORT(("dst_eay_dss_generate_keypair: Generate Parameters failed")); - return (0); - } - if (DSA_generate_key(dsa) == 0) { - EREPORT(("dst_eay_dss_generate_keypair: Generate Key failed")); - return(0); - } - key->dk_KEY_struct = (void *) dsa; - return (1); -} - - -/* - * dst_eay_dss_compare_keys - * Compare two keys for equality. - * Return - * 0 The keys are equal - * NON-ZERO The keys are not equal - */ - -static int -dst_eay_dss_compare_keys(const DST_KEY *key1, const DST_KEY *key2) -{ - int status; - DSA *dkey1 = (DSA *) key1->dk_KEY_struct; - DSA *dkey2 = (DSA *) key2->dk_KEY_struct; - - if (dkey1 == NULL && dkey2 == NULL) - return (0); - else if (dkey1 == NULL) - return (2); - else if (dkey2 == NULL) - return(1); - - status = BN_cmp(dkey1->p, dkey2->p) || - BN_cmp(dkey1->q, dkey2->q) || - BN_cmp(dkey1->g, dkey2->g) || - BN_cmp(dkey1->pub_key, dkey2->pub_key); - - if (status) - return (status); - - if (dkey1->priv_key || dkey2->priv_key) { - if (dkey1->priv_key == NULL || dkey2->priv_key == NULL) - return (202); - return (BN_cmp(dkey1->priv_key, dkey2->priv_key)); - } else - return (0); -} -#else -#include "port_before.h" - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#include <memory.h> -#include <sys/param.h> -#include <sys/time.h> -#include <netinet/in.h> - -#include "dst_internal.h" -#include "port_after.h" -int -dst_eay_dss_init(void) -{ - return (0); -} -#endif /* EAY_DSS */ diff --git a/usr/src/lib/libresolv2/common/dst/hmac_link.c b/usr/src/lib/libresolv2/common/dst/hmac_link.c index 77269667c2..071e8d2aad 100644 --- a/usr/src/lib/libresolv2/common/dst/hmac_link.c +++ b/usr/src/lib/libresolv2/common/dst/hmac_link.c @@ -1,13 +1,12 @@ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" #ifdef HMAC_MD5 #ifndef LINT -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/hmac_link.c,v 1.9 2001/05/29 05:48:10 marka Exp $"; +static const char rcsid[] = "$Header: /proj/cvs/prod/libbind/dst/hmac_link.c,v 1.8 2007/09/24 17:18:25 each Exp $"; #endif /* * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. @@ -26,7 +25,7 @@ static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/hmac_link. * WITH THE USE OR PERFORMANCE OF THE SOFTWARE. */ -/* +/*% * This file contains an implementation of the HMAC-MD5 algorithm. */ #include "port_before.h" @@ -43,14 +42,17 @@ static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/hmac_link. #include <resolv.h> #include "dst_internal.h" + #ifdef USE_MD5 -#ifndef SUNW_LIBMD5 -# include "md5.h" -#else -#include <sys/md5.h> -#endif +# ifndef HAVE_MD5 +# include "md5.h" +# else +# ifdef SOLARIS2 +# include <sys/md5.h> +# endif +# endif # ifndef _MD5_H_ -# define _MD5_H_ 1 /* make sure we do not include rsaref md5.h file */ +# define _MD5_H_ 1 /*%< make sure we do not include rsaref md5.h file */ # endif #endif @@ -97,6 +99,9 @@ dst_hmac_md5_sign(const int mode, DST_KEY *d_key, void **context, int sign_len = 0; MD5_CTX *ctx = NULL; + if (d_key == NULL || d_key->dk_KEY_struct == NULL) + return (-1); + if (mode & SIG_MODE_INIT) ctx = (MD5_CTX *) malloc(sizeof(*ctx)); else if (context) @@ -104,8 +109,6 @@ dst_hmac_md5_sign(const int mode, DST_KEY *d_key, void **context, if (ctx == NULL) return (-1); - if (d_key == NULL || d_key->dk_KEY_struct == NULL) - return (-1); key = (HMAC_Key *) d_key->dk_KEY_struct; if (mode & SIG_MODE_INIT) { @@ -164,6 +167,9 @@ dst_hmac_md5_verify(const int mode, DST_KEY *d_key, void **context, HMAC_Key *key; MD5_CTX *ctx = NULL; + if (d_key == NULL || d_key->dk_KEY_struct == NULL) + return (-1); + if (mode & SIG_MODE_INIT) ctx = (MD5_CTX *) malloc(sizeof(*ctx)); else if (context) @@ -171,9 +177,6 @@ dst_hmac_md5_verify(const int mode, DST_KEY *d_key, void **context, if (ctx == NULL) return (-1); - if (d_key == NULL || d_key->dk_KEY_struct == NULL) - return (-1); - key = (HMAC_Key *) d_key->dk_KEY_struct; if (mode & SIG_MODE_INIT) { MD5Init(ctx); @@ -226,6 +229,7 @@ dst_buffer_to_hmac_md5(DST_KEY *dkey, const u_char *key, const int keylen) HMAC_Key *hkey = NULL; MD5_CTX ctx; int local_keylen = keylen; + u_char tk[MD5_LEN]; if (dkey == NULL || key == NULL || keylen < 0) return (-1); @@ -238,7 +242,6 @@ dst_buffer_to_hmac_md5(DST_KEY *dkey, const u_char *key, const int keylen) /* if key is longer than HMAC_LEN bytes reset it to key=MD5(key) */ if (keylen > HMAC_LEN) { - u_char tk[MD5_LEN]; MD5Init(&ctx); MD5Update(&ctx, key, keylen); MD5Final(tk, &ctx); @@ -276,25 +279,28 @@ dst_buffer_to_hmac_md5(DST_KEY *dkey, const u_char *key, const int keylen) static int dst_hmac_md5_key_to_file_format(const DST_KEY *dkey, char *buff, - const int buff_len) + const int buff_len) { char *bp; - int len, b_len, i, key_len; + int len, i, key_len; u_char key[HMAC_LEN]; HMAC_Key *hkey; if (dkey == NULL || dkey->dk_KEY_struct == NULL) return (0); - if (buff == NULL || buff_len <= (int) strlen(key_file_fmt_str)) - return (-1); /* no OR not enough space in output area */ - + /* + * Using snprintf() would be so much simpler here. + */ + if (buff == NULL || + buff_len <= (int)(strlen(key_file_fmt_str) + + strlen(KEY_FILE_FORMAT) + 4)) + return (-1); /*%< no OR not enough space in output area */ hkey = (HMAC_Key *) dkey->dk_KEY_struct; - memset(buff, 0, buff_len); /* just in case */ + memset(buff, 0, buff_len); /*%< just in case */ /* write file header */ sprintf(buff, key_file_fmt_str, KEY_FILE_FORMAT, KEY_HMAC_MD5, "HMAC"); - bp = (char *) strchr(buff, '\0'); - b_len = buff_len - (bp - buff); + bp = buff + strlen(buff); memset(key, 0, HMAC_LEN); for (i = 0; i < HMAC_LEN; i++) @@ -304,19 +310,21 @@ dst_hmac_md5_key_to_file_format(const DST_KEY *dkey, char *buff, break; key_len = i + 1; + if (buff_len - (bp - buff) < 6) + return (-1); strcat(bp, "Key: "); bp += strlen("Key: "); - b_len = buff_len - (bp - buff); - len = b64_ntop(key, key_len, bp, b_len); + len = b64_ntop(key, key_len, bp, buff_len - (bp - buff)); if (len < 0) return (-1); bp += len; + if (buff_len - (bp - buff) < 2) + return (-1); *(bp++) = '\n'; *bp = '\0'; - b_len = buff_len - (bp - buff); - return (buff_len - b_len); + return (bp - buff); } @@ -338,9 +346,9 @@ dst_hmac_md5_key_from_file_format(DST_KEY *dkey, const char *buff, { const char *p = buff, *eol; u_char key[HMAC_LEN+1]; /* b64_pton needs more than 64 bytes do decode - * it should probably be fixed rather than doing - * this - */ + * it should probably be fixed rather than doing + * this + */ u_char *tmp; int key_len, len; @@ -359,9 +367,11 @@ dst_hmac_md5_key_from_file_format(DST_KEY *dkey, const char *buff, return (-4); len = eol - p; tmp = malloc(len + 2); + if (tmp == NULL) + return (-5); memcpy(tmp, p, len); *(tmp + len) = 0x0; - key_len = b64_pton((char *)tmp, key, HMAC_LEN+1); /* see above */ + key_len = b64_pton((char *)tmp, key, HMAC_LEN+1); /*%< see above */ SAFE_FREE2(tmp, len + 2); if (dst_buffer_to_hmac_md5(dkey, key, key_len) < 0) { @@ -370,7 +380,7 @@ dst_hmac_md5_key_from_file_format(DST_KEY *dkey, const char *buff, return (0); } -/* +/*% * dst_hmac_md5_to_dns_key() * function to extract hmac key from DST_KEY structure * intput: @@ -439,43 +449,17 @@ dst_hmac_md5_free_key_structure(void *key) static int dst_hmac_md5_generate_key(DST_KEY *key, const int nothing) { - u_char *buff; - int i, n, size; - - i = nothing; - - if (key == NULL || key->dk_alg != KEY_HMAC_MD5) - return (0); - size = (key->dk_key_size + 7) / 8; /* convert to bytes */ - if (size <= 0) - return(0); - - i = size > 64 ? 64 : size; - buff = malloc(i+8); - - n = dst_random(DST_RAND_SEMI, i, buff); - n += dst_random(DST_RAND_KEY, i, buff); - if (n <= i) { /* failed getting anything */ - SAFE_FREE2(buff, i); - return (-1); - } - n = dst_buffer_to_hmac_md5(key, buff, i); - SAFE_FREE2(buff, i); - if (n <= 0) - return (n); - return (1); + (void)key; + (void)nothing; + return (-1); } -/* +/*% * dst_hmac_md5_init() Function to answer set up function pointers for HMAC * related functions */ int -#ifdef ORIGINAL_ISC_CODE dst_hmac_md5_init() -#else -dst_md5_hmac_init() -#endif { if (dst_t_func[KEY_HMAC_MD5] != NULL) return (1); @@ -496,15 +480,12 @@ dst_md5_hmac_init() } #else +#define dst_hmac_md5_init __dst_hmac_md5_init + int dst_hmac_md5_init(){ return (0); } #endif - - - - - - +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/dst/prandom.c b/usr/src/lib/libresolv2/common/dst/prandom.c deleted file mode 100644 index 0a4fd7d79e..0000000000 --- a/usr/src/lib/libresolv2/common/dst/prandom.c +++ /dev/null @@ -1,860 +0,0 @@ -#ifndef LINT -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/prandom.c,v 1.12 2001/07/26 01:20:09 marka Exp $"; -#endif -/* - * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. - * - * Permission to use, copy modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND TRUSTED INFORMATION SYSTEMS - * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL - * TRUSTED INFORMATION SYSTEMS BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THE SOFTWARE. - */ - -#include "port_before.h" - -#include <assert.h> -#include <stdio.h> -#include <sys/types.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <time.h> -#include <dirent.h> -#include <sys/param.h> -#include <sys/stat.h> -#include <sys/time.h> - -#include "dst_internal.h" -#include "prand_conf.h" - -#include "port_after.h" - -#ifndef DST_NUM_HASHES -#define DST_NUM_HASHES 4 -#endif -#ifndef DST_NUMBER_OF_COUNTERS -#define DST_NUMBER_OF_COUNTERS 5 /* 32 * 5 == 160 == SHA(1) > MD5 */ -#endif - -/* - * the constant below is a prime number to make fixed data structues like - * stat and time wrap over blocks. This adds certain uncertanty to what is - * in each digested block. - * The prime number 2879 has the special property that when - * divided by 2,4 and 6 the result is also a prime numbers - */ - -#ifndef DST_RANDOM_BLOCK_SIZE -#define DST_RANDOM_BLOCK_SIZE 2879 -#endif - -/* - * This constant dictatates how many bits we shift to the right before using a - */ -#ifndef DST_SHIFT -#define DST_SHIFT 9 -#endif - -/* - * An initalizer that is as bad as any other with half the bits set - */ -#ifndef DST_RANDOM_PATTERN -#define DST_RANDOM_PATTERN 0x8765CA93 -#endif -/* - * things must have changed in the last 3600 seconds to be used - */ -#define MAX_OLD 3600 - - -/* - * these two data structure are used to process input data into digests, - * - * The first structure is containts a pointer to a DST HMAC key - * the variables accompanying are used for - * step : select every step byte from input data for the hash - * block: number of data elements going into each hash - * digested: number of data elements digested so far - * curr: offset into the next input data for the first byte. - */ -typedef struct hash { - DST_KEY *key; - void *ctx; - int digested, block, step, curr; -} prand_hash; - -/* - * This data structure controlls number of hashes and keeps track of - * overall progress in generating correct number of bytes of output. - * output : array to store the output data in - * needed : how many bytes of output are needed - * filled : number of bytes in output so far. - * bytes : total number of bytes processed by this structure - * file_digest : the HMAC key used to digest files. - */ -typedef struct work { - int needed, filled, bytes; - u_char *output; - prand_hash *hash[DST_NUM_HASHES]; - DST_KEY *file_digest; -} dst_work; - - -/* - * forward function declarations - */ -static int get_dev_random(u_char *output, int size); -static int do_time(dst_work *work); -static int do_ls(dst_work *work); -static int unix_cmd(dst_work *work); -static int digest_file(dst_work *work); - -static void force_hash(dst_work *work, prand_hash *hash); -static int do_hash(dst_work *work, prand_hash *hash, const u_char *input, - int size); -static int my_digest(dst_work *tmp, const u_char *input, int size); -static prand_hash *get_hmac_key(int step, int block); - -static int own_random(dst_work *work); - - -/* - * variables used in the quick random number generator - */ -static u_int32_t ran_val = DST_RANDOM_PATTERN; -static u_int32_t ran_cnt = (DST_RANDOM_PATTERN >> 10); - -/* - * setting the quick_random generator to particular values or if both - * input parameters are 0 then set it to initial vlaues - */ - -void -dst_s_quick_random_set(u_int32_t val, u_int32_t cnt) -{ - ran_val = (val == 0) ? DST_RANDOM_PATTERN : val; - ran_cnt = (cnt == 0) ? (DST_RANDOM_PATTERN >> 10) : cnt; -} - -/* - * this is a quick and random number generator that seems to generate quite - * good distribution of data - */ -u_int32_t -dst_s_quick_random(int inc) -{ - ran_val = ((ran_val >> 13) ^ (ran_val << 19)) ^ - ((ran_val >> 7) ^ (ran_val << 25)); - if (inc > 0) /* only increasing values accepted */ - ran_cnt += inc; - ran_val += ran_cnt++; - return (ran_val); -} - -/* - * get_dev_random: Function to read /dev/random reliably - * this function returns how many bytes where read from the device. - * port_after.h should set the control variable HAVE_DEV_RANDOM - */ -static int -get_dev_random(u_char *output, int size) -{ -#ifdef HAVE_DEV_RANDOM - struct stat st; - int n = 0, fd = -1, s; - - s = stat("/dev/random", &st); - if (s == 0 && S_ISCHR(st.st_mode)) { - if ((fd = open("/dev/random", O_RDONLY | O_NONBLOCK)) != -1) { - if ((n = read(fd, output, size)) < 0) - n = 0; - close(fd); - } - return (n); - } -#endif - return (0); -} - -/* - * Portable way of getting the time values if gettimeofday is missing - * then compile with -DMISSING_GETTIMEOFDAY time() is POSIX compliant but - * gettimeofday() is not. - * Time of day is predictable, we are looking for the randomness that comes - * the last few bits in the microseconds in the timer are hard to predict when - * this is invoked at the end of other operations - */ -struct timeval *mtime; -static int -do_time(dst_work *work) -{ - int cnt = 0; - static u_char tmp[sizeof(struct timeval) + sizeof(struct timezone)]; - struct timezone *zone; - - zone = (struct timezone *) tmp; - mtime = (struct timeval *)(tmp + sizeof(struct timezone)); - gettimeofday(mtime, zone); - cnt = sizeof(tmp); - my_digest(work, tmp, sizeof(tmp)); - - return (cnt); -} - -/* - * this function simulates the ls command, but it uses stat which gives more - * information and is harder to guess - * Each call to this function will visit the next directory on the list of - * directories, in a circular manner. - * return value is the number of bytes added to the temp buffer - * - * do_ls() does not visit subdirectories - * if attacker has access to machine it can guess most of the values seen - * thus it is important to only visit directories that are freqently updated - * Attacker that has access to the network can see network traffic - * when NFS mounted directories are accessed and know exactly the data used - * but may not know exactly in what order data is used. - * Returns the number of bytes that where returned in stat structures - */ -static int -do_ls(dst_work *work) -{ - struct dir_info { - uid_t uid; - gid_t gid; - off_t size; - time_t atime, mtime, ctime; - }; - static struct dir_info dir_info; - struct stat buf; - struct dirent *entry; - static int i = 0; - static unsigned long d_round = 0; - struct timeval tv; - int n = 0, dir_len, tb_i = 0, out = 0; - - char file_name[1024]; - u_char tmp_buff[1024]; - DIR *dir = NULL; - - if (dirs[i] == NULL) /* if at the end of the list start over */ - i = 0; - if (stat(dirs[i++], &buf)) /* directory does not exist */ - return (0); - - gettimeofday(&tv, NULL); - if (d_round == 0) - d_round = tv.tv_sec - MAX_OLD; - else if (i==1) /* if starting a new round cut what we accept */ - d_round += (tv.tv_sec - d_round)/2; - - if (buf.st_atime < (time_t)d_round) - return (0); - - EREPORT(("do_ls i %d filled %4d\n", i-1, work->filled)); - memcpy(tmp_buff, &buf, sizeof(buf)); - tb_i += sizeof(buf); - - - if ((dir = opendir(dirs[i-1])) == NULL)/* open it for read */ - return (0); - strcpy(file_name, dirs[i-1]); - dir_len = strlen(file_name); - file_name[dir_len++] = '/'; - while ((entry = readdir(dir))) { - int len = strlen(entry->d_name); - out += len; - if (my_digest(work, (u_char *)entry->d_name, len)) - break; - - memcpy(&file_name[dir_len], entry->d_name, len); - file_name[dir_len + len] = 0x0; - /* for all entries in dir get the stats */ - if (stat(file_name, &buf) == 0) { - n++; /* count successfull stat calls */ - /* copy non static fields */ - dir_info.uid += buf.st_uid; - dir_info.gid += buf.st_gid; - dir_info.size += buf.st_size; - dir_info.atime += buf.st_atime; - dir_info.mtime += buf.st_mtime; - dir_info.ctime += buf.st_ctime; - out += sizeof(dir_info); - if(my_digest(work, (u_char *)&dir_info, - sizeof(dir_info))) - break; - } - } - closedir(dir); /* done */ - out += do_time(work); /* add a time stamp */ - return (out); -} - - -/* - * unix_cmd() - * this function executes the a command from the cmds[] list of unix commands - * configured in the prand_conf.h file - * return value is the number of bytes added to the randomness temp buffer - * - * it returns the number of bytes that where read in - * if more data is needed at the end time is added to the data. - * This function maintains a state to selects the next command to run - * returns the number of bytes read in from the command - */ -static int -unix_cmd(dst_work *work) -{ - static int cmd_index = 0; - int cnt = 0, n; - FILE *pipe; - u_char buffer[4096]; - - if (cmds[cmd_index] == NULL) - cmd_index = 0; - EREPORT(("unix_cmd() i %d filled %4d\n", cmd_index, work->filled)); - pipe = popen(cmds[cmd_index++], "r"); /* execute the command */ - - while ((n = fread(buffer, sizeof(char), sizeof(buffer), pipe)) > 0) { - cnt += n; /* process the output */ - if (my_digest(work, buffer, n)) - break; - /* this adds some randomness to the output */ - cnt += do_time(work); - } - while ((n = fread(buffer, sizeof(char), sizeof(buffer), pipe)) > 0) - (void)NULL; /* drain the pipe */ - pclose(pipe); - return (cnt); /* read how many bytes where read in */ -} - -/* - * digest_file() This function will read a file and run hash over it - * input is a file name - */ -static int -digest_file(dst_work *work) -{ - static int f_cnt = 0; - static unsigned long f_round = 0; - FILE *fp; - void *ctx; - const char *name; - int no, i; - struct stat st; - struct timeval tv; - u_char buf[1024]; - - if (f_round == 0 || files[f_cnt] == NULL || work->file_digest == NULL) - if (gettimeofday(&tv, NULL)) /* only do this if needed */ - return (0); - if (f_round == 0) /* first time called set to one hour ago */ - f_round = (tv.tv_sec - MAX_OLD); - name = files[f_cnt++]; - if (files[f_cnt] == NULL) { /* end of list of files */ - if(f_cnt <= 1) /* list is too short */ - return (0); - f_cnt = 0; /* start again on list */ - f_round += (tv.tv_sec - f_round)/2; /* set new cutoff */ - work->file_digest = dst_free_key(work->file_digest); - } - if (work->file_digest == NULL) { - work->file_digest = dst_buffer_to_key("", KEY_HMAC_MD5, 0, 0, - (u_char *)&tv, sizeof(tv)); - if (work->file_digest == NULL) - return (0); - } - if (access(name, R_OK) || stat(name, &st)) - return (0); /* no such file or not allowed to read it */ - if (strncmp(name, "/proc/", 6) && st.st_mtime < (time_t)f_round) - return(0); /* file has not changed recently enough */ - if (dst_sign_data(SIG_MODE_INIT, work->file_digest, &ctx, - NULL, 0, NULL, 0)) { - work->file_digest = dst_free_key(work->file_digest); - return (0); - } - if ((fp = fopen(name, "r")) == NULL) - return (0); - for (no = 0; (i = fread(buf, sizeof(*buf), sizeof(buf), fp)) > 0; - no += i) - dst_sign_data(SIG_MODE_UPDATE, work->file_digest, &ctx, - buf, i, NULL, 0); - - fclose(fp); - if (no >= 64) { - i = dst_sign_data(SIG_MODE_FINAL, work->file_digest, &ctx, - NULL, 0, &work->output[work->filled], - DST_HASH_SIZE); - if (i > 0) - work->filled += i; - } - else if (i > 0) - my_digest(work, buf, i); - my_digest(work, (const u_char *)name, strlen(name)); - return (no + strlen(name)); -} - -/* - * function to perform the FINAL and INIT operation on a hash if allowed - */ -static void -force_hash(dst_work *work, prand_hash *hash) -{ - int i = 0; - - /* - * if more than half a block then add data to output - * otherwise adde the digest to the next hash - */ - if ((hash->digested * 2) > hash->block) { - i = dst_sign_data(SIG_MODE_FINAL, hash->key, &hash->ctx, - NULL, 0, &work->output[work->filled], - DST_HASH_SIZE); - - hash->digested = 0; - dst_sign_data(SIG_MODE_INIT, hash->key, &hash->ctx, - NULL, 0, NULL, 0); - if (i > 0) - work->filled += i; - } - return; -} - -/* - * This function takes the input data does the selection of data specified - * by the hash control block. - * The step varialbe in the work sturcture determines which 1/step bytes - * are used, - * - */ -static int -do_hash(dst_work *work, prand_hash *hash, const u_char *input, int size) -{ - const u_char *tmp = input; - u_char *save = NULL, *tp; - int i, cnt = size, n, needed, avail, dig, tmp_size = 0; - - if (cnt <= 0 || input == NULL) - return (0); - - if (hash->step > 1) { /* if using subset of input data */ - tmp_size = size / hash->step + 2; - tmp = tp = save = malloc(tmp_size); - for (cnt = 0, i = hash->curr; i < size; i += hash->step, cnt++) - *(tp++) = input[i]; - /* calcutate the starting point in the next input set */ - hash->curr = (hash->step - (i - size)) % hash->step; - } - /* digest the data in block sizes */ - for (n = 0; n < cnt; n += needed) { - avail = (cnt - n); - needed = hash->block - hash->digested; - dig = (avail < needed) ? avail : needed; - dst_sign_data(SIG_MODE_UPDATE, hash->key, &hash->ctx, - &tmp[n], dig, NULL, 0); - hash->digested += dig; - if (hash->digested >= hash->block) - force_hash(work, hash); - if (work->needed < work->filled) { - if (tmp_size > 0) - SAFE_FREE2(save, tmp_size); - return (1); - } - } - if (tmp_size > 0) - SAFE_FREE2(save, tmp_size); - return (0); -} - -/* - * Copy data from INPUT for length SIZE into the work-block TMP. - * If we fill the work-block, digest it; then, - * if work-block needs more data, keep filling with the rest of the input. - */ -static int -my_digest(dst_work *work, const u_char *input, int size) -{ - - int i, full = 0; - static unsigned counter; - - counter += size; - /* first do each one of the hashes */ - for (i = 0; i < DST_NUM_HASHES && full == 0; i++) - full = do_hash(work, work->hash[i], input, size) + - do_hash(work, work->hash[i], (u_char *) &counter, - sizeof(counter)); -/* - * if enough data has be generated do final operation on all hashes - * that have enough date for that - */ - for (i = 0; full && (i < DST_NUM_HASHES); i++) - force_hash(work, work->hash[i]); - - return (full); -} - -/* - * this function gets some semi random data and sets that as an HMAC key - * If we get a valid key this function returns that key initalized - * otherwise it returns NULL; - */ -static prand_hash * -get_hmac_key(int step, int block) -{ - - u_char *buff; - int temp = 0, n = 0, size = 70; - DST_KEY *new_key = NULL; - prand_hash *new = NULL; - - /* use key that is larger than digest algorithms (64) for key size */ - buff = malloc(size); - if (buff == NULL) - return (NULL); - /* do not memset the allocated memory to get random bytes there */ - /* time of day is somewhat random expecialy in the last bytes */ - gettimeofday((struct timeval *) &buff[n], NULL); - n += sizeof(struct timeval); - -/* get some semi random stuff in here stir it with micro seconds */ - if (n < size) { - temp = dst_s_quick_random((int) buff[n - 1]); - memcpy(&buff[n], &temp, sizeof(temp)); - n += sizeof(temp); - } -/* get the pid of this process and its parent */ - if (n < size) { - temp = (int) getpid(); - memcpy(&buff[n], &temp, sizeof(temp)); - n += sizeof(temp); - } - if (n < size) { - temp = (int) getppid(); - memcpy(&buff[n], &temp, sizeof(temp)); - n += sizeof(temp); - } -/* get the user ID */ - if (n < size) { - temp = (int) getuid(); - memcpy(&buff[n], &temp, sizeof(temp)); - n += sizeof(temp); - } -#ifndef GET_HOST_ID_MISSING - if (n < size) { - temp = (int) gethostid(); - memcpy(&buff[n], &temp, sizeof(temp)); - n += sizeof(temp); - } -#endif -/* get some more random data */ - if (n < size) { - temp = dst_s_quick_random((int) buff[n - 1]); - memcpy(&buff[n], &temp, sizeof(temp)); - n += sizeof(temp); - } -/* covert this into a HMAC key */ - new_key = dst_buffer_to_key("", KEY_HMAC_MD5, 0, 0, buff, size); - SAFE_FREE(buff); - -/* get the control structure */ - if ((new = malloc(sizeof(prand_hash))) == NULL) - return (NULL); - new->digested = new->curr = 0; - new->step = step; - new->block = block; - new->key = new_key; - if (dst_sign_data(SIG_MODE_INIT, new_key, &new->ctx, NULL, 0, NULL, 0)) - return (NULL); - - return (new); -} - -/* - * own_random() - * This function goes out and from various sources tries to generate enough - * semi random data that a hash function can generate a random data. - * This function will iterate between the two main random source sources, - * information from programs and directores in random order. - * This function return the number of bytes added to the random output buffer. - */ -static int -own_random(dst_work *work) -{ - int dir = 0, b; - int bytes, n, cmd = 0, dig = 0; - int start =0; -/* - * now get the initial seed to put into the quick random function from - * the address of the work structure - */ - bytes = (int) getpid(); -/* - * proceed while needed - */ - while (work->filled < work->needed) { - EREPORT(("own_random r %08x b %6d f %6d\n", - ran_val, bytes, work->filled)); -/* pick a random number in the range of 0..7 based on that random number - * perform some operations that yield random data - */ - start = work->filled; - n = (dst_s_quick_random(bytes) >> DST_SHIFT) & 0x07; - switch (n) { - case 0: - case 3: - if (sizeof(cmds) > 2 *sizeof(*cmds)) { - b = unix_cmd(work); - cmd += b; - } - break; - - case 1: - case 7: - if (sizeof(dirs) > 2 *sizeof(*dirs)) { - b = do_ls(work); - dir += b; - } - break; - - case 4: - case 5: - /* retry getting data from /dev/random */ - b = get_dev_random(&work->output[work->filled], - work->needed - work->filled); - if (b > 0) - work->filled += b; - break; - - case 6: - if (sizeof(files) > 2 * sizeof(*files)) { - b = digest_file(work); - dig += b; - } - break; - - case 2: - default: /* to make sure we make some progress */ - work->output[work->filled++] = 0xff & - dst_s_quick_random(bytes); - b = 1; - break; - } - if (b > 0) - bytes += b; - } - return (work->filled); -} - - -/* - * dst_s_random() This function will return the requested number of bytes - * of randomness to the caller it will use the best available sources of - * randomness. - * The current order is to use /dev/random, precalculated randomness, and - * finaly use some system calls and programs to generate semi random data that - * is then digested to generate randomness. - * This function is thread safe as each thread uses its own context, but - * concurrent treads will affect each other as they update shared state - * information. - * It is strongly recommended that this function be called requesting a size - * that is not a multiple of the output of the hash function used. - * - * If /dev/random is not available this function is not suitable to generate - * large ammounts of data, rather it is suitable to seed a pseudo-random - * generator - * Returns the number of bytes put in the output buffer - */ -int -dst_s_random(u_char *output, int size) -{ - int n = 0, s, i; - static u_char old_unused[DST_HASH_SIZE * DST_NUM_HASHES]; - static int unused = 0; - - if (size <= 0 || output == NULL) - return (0); - - if (size >= 2048) - return (-1); - /* - * Read from /dev/random - */ - n = get_dev_random(output, size); - /* - * If old data is available and needed use it - */ - if (n < size && unused > 0) { - int need = size - n; - if (unused <= need) { - memcpy(output, old_unused, unused); - n += unused; - unused = 0; - } else { - memcpy(output, old_unused, need); - n += need; - unused -= need; - memcpy(old_unused, &old_unused[need], unused); - } - } - /* - * If we need more use the simulated randomness here. - */ - if (n < size) { - dst_work *my_work = (dst_work *) malloc(sizeof(dst_work)); - if (my_work == NULL) - return (n); - my_work->needed = size - n; - my_work->filled = 0; - my_work->output = (u_char *) malloc(my_work->needed + - DST_HASH_SIZE * - DST_NUM_HASHES); - my_work->file_digest = NULL; - if (my_work->output == NULL) - return (n); - memset(my_work->output, 0x0, my_work->needed); -/* allocate upto 4 different HMAC hash functions out of order */ -#if DST_NUM_HASHES >= 3 - my_work->hash[2] = get_hmac_key(3, DST_RANDOM_BLOCK_SIZE / 2); -#endif -#if DST_NUM_HASHES >= 2 - my_work->hash[1] = get_hmac_key(7, DST_RANDOM_BLOCK_SIZE / 6); -#endif -#if DST_NUM_HASHES >= 4 - my_work->hash[3] = get_hmac_key(5, DST_RANDOM_BLOCK_SIZE / 4); -#endif - my_work->hash[0] = get_hmac_key(1, DST_RANDOM_BLOCK_SIZE); - if (my_work->hash[0] == NULL) /* if failure bail out */ - return (n); - s = own_random(my_work); -/* if more generated than needed store it for future use */ - if (s >= my_work->needed) { - EREPORT(("dst_s_random(): More than needed %d >= %d\n", - s, my_work->needed)); - memcpy(&output[n], my_work->output, my_work->needed); - n += my_work->needed; - /* saving unused data for next time */ - unused = s - my_work->needed; - memcpy(old_unused, &my_work->output[my_work->needed], - unused); - } else { - /* XXXX This should not happen */ - EREPORT(("Not enough %d >= %d\n", s, my_work->needed)); - memcpy(&output[n], my_work->output, s); - n += my_work->needed; - } - -/* delete the allocated work area */ - for (i = 0; i < DST_NUM_HASHES; i++) { - dst_free_key(my_work->hash[i]->key); - SAFE_FREE(my_work->hash[i]); - } - SAFE_FREE(my_work->output); - SAFE_FREE(my_work); - } - return (n); -} - -/* - * A random number generator that is fast and strong - * this random number generator is based on HASHing data, - * the input to the digest function is a collection of <NUMBER_OF_COUNTERS> - * counters that is incremented between digest operations - * each increment operation amortizes to 2 bits changed in that value - * for 5 counters thus the input will amortize to have 10 bits changed - * The counters are initaly set using the strong random function above - * the HMAC key is selected by the same methold as the HMAC keys for the - * strong random function. - * Each set of counters is used for 2^25 operations - * - * returns the number of bytes written to the output buffer - * or negative number in case of error - */ -int -dst_s_semi_random(u_char *output, int size) -{ - static u_int32_t counter[DST_NUMBER_OF_COUNTERS]; - static u_char semi_old[DST_HASH_SIZE]; - static int semi_loc = 0, cnt = 0, hb_size = 0; - static DST_KEY *my_key = NULL; - prand_hash *hash; - int out = 0, i, n; - - if (output == NULL || size <= 0) - return (-2); - -/* check if we need a new key */ - if (my_key == NULL || cnt > (1 << 25)) { /* get HMAC KEY */ - if (my_key) - my_key->dk_func->destroy(my_key); - if ((hash = get_hmac_key(1, DST_RANDOM_BLOCK_SIZE)) == NULL) - return (0); - my_key = hash->key; -/* check if the key works stir the new key using some old random data */ - hb_size = dst_sign_data(SIG_MODE_ALL, my_key, NULL, - (u_char *) counter, sizeof(counter), - semi_old, sizeof(semi_old)); - if (hb_size <= 0) { - EREPORT(("dst_s_semi_random() Sign of alg %d failed %d\n", - my_key->dk_alg, hb_size)); - return (-1); - } -/* new set the counters to random values */ - dst_s_random((u_char *) counter, sizeof(counter)); - cnt = 0; - } -/* if old data around use it first */ - if (semi_loc < hb_size) { - if (size <= hb_size - semi_loc) { /* need less */ - memcpy(output, &semi_old[semi_loc], size); - semi_loc += size; - return (size); /* DONE */ - } else { - out = hb_size - semi_loc; - memcpy(output, &semi_old[semi_loc], out); - semi_loc += out; - } - } -/* generate more randome stuff */ - while (out < size) { - /* - * modify at least one bit by incrementing at least one counter - * based on the last bit of the last counter updated update - * the next one. - * minimaly this operation will modify at least 1 bit, - * amortized 2 bits - */ - for (n = 0; n < DST_NUMBER_OF_COUNTERS; n++) - i = (int) counter[n]++; - - i = dst_sign_data(SIG_MODE_ALL, my_key, NULL, - (u_char *) counter, hb_size, - semi_old, sizeof(semi_old)); -#ifdef REPORT_ERRORS - if (i != hb_size) - EREPORT(("HMAC SIGNATURE FAILURE %d\n", i)); -#endif - cnt++; - if (size - out < i) /* Not all data is needed */ - semi_loc = i = size - out; - memcpy(&output[out], semi_old, i); - out += i; - } - return (out); -} diff --git a/usr/src/lib/libresolv2/common/dst/rsaref_link.c b/usr/src/lib/libresolv2/common/dst/rsaref_link.c deleted file mode 100644 index b18d694825..0000000000 --- a/usr/src/lib/libresolv2/common/dst/rsaref_link.c +++ /dev/null @@ -1,768 +0,0 @@ -/* - * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef RSAREF -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/rsaref_link.c,v 1.10 2001/05/29 05:48:15 marka Exp $"; - -/* - * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. - * - * Permission to use, copy modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND TRUSTED INFORMATION SYSTEMS - * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL - * TRUSTED INFORMATION SYSTEMS BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THE SOFTWARE. - */ - -/* - * This file contains two components - * 1. Interface to the rsaref library to allow compilation when RSAREF is - * not available all calls to RSAREF are contained inside this file. - * 2. The glue to connvert RSA{REF} KEYS to and from external formats - */ -#include "port_before.h" - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#include <memory.h> -#include <sys/param.h> -#include <sys/time.h> -#include <netinet/in.h> - -#include "dst_internal.h" - -# ifdef __STDC__ -# define PROTOTYPES 1 -# else -# define PROTOTYPES 0 -# endif - -# include <global.h> -# include <rsaref.h> - -#include "port_after.h" - - -typedef struct rsakey { - char *rk_signer; - R_RSA_PRIVATE_KEY *rk_Private_Key; - R_RSA_PUBLIC_KEY *rk_Public_Key; -} RSA_Key; - - -static int dst_rsaref_sign(const int mode, DST_KEY *key, void **context, - const u_char *data, const int len, - u_char *signature, const int sig_len); -static int dst_rsaref_verify(const int mode, DST_KEY *key, void **context, - const u_char *data, const int len, - const u_char *signature, const int sig_len); - -static int dst_rsaref_to_dns_key(const DST_KEY *public, u_char *out_str, - const int out_len); -static int dst_rsaref_from_dns_key(DST_KEY *s_key, const u_char *key, - const int len); - -static int dst_rsaref_key_to_file_format(const DST_KEY *dkey, - u_char *buff, - const int buff_len); -static int dst_rsaref_key_from_file_format(DST_KEY *dkey, - const u_char *buff, - const int buff_len); - -static int dst_rsaref_compare_keys(const DST_KEY *rkey1, - const DST_KEY *rkey2); -static void *dst_rsaref_free_key_structure(void *d_key); - -static int dst_rsaref_generate_keypair(DST_KEY *key, const int exp); - -static void dst_rsaref_init_random_struct(R_RANDOM_STRUCT * randomstruct); - -/* - * dst_rsaref_init() Function to answer set up function pointers for RSAREF - * related functions - */ -int -dst_rsaref_init() -{ - if (dst_t_func[KEY_RSA] != NULL) - return (1); - dst_t_func[KEY_RSA] = malloc(sizeof(struct dst_func)); - if (dst_t_func[KEY_RSA] == NULL) - return (0); - memset(dst_t_func[KEY_RSA], 0, sizeof(struct dst_func)); - dst_t_func[KEY_RSA]->sign = dst_rsaref_sign; - dst_t_func[KEY_RSA]->verify = dst_rsaref_verify; - dst_t_func[KEY_RSA]->compare = dst_rsaref_compare_keys; - dst_t_func[KEY_RSA]->generate = dst_rsaref_generate_keypair; - dst_t_func[KEY_RSA]->destroy = dst_rsaref_free_key_structure; - dst_t_func[KEY_RSA]->to_dns_key = dst_rsaref_to_dns_key; - dst_t_func[KEY_RSA]->from_dns_key = dst_rsaref_from_dns_key; - dst_t_func[KEY_RSA]->to_file_fmt = dst_rsaref_key_to_file_format; - dst_t_func[KEY_RSA]->from_file_fmt = dst_rsaref_key_from_file_format; - return (1); -} - -/* - * dst_rsa_sign - * Call RSAREF signing functions to sign a block of data. - * There are three steps to signing, INIT (initialize structures), - * UPDATE (hash (more) data), FINAL (generate a signature). This - * routine performs one or more of these steps. - * Parameters - * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL. - * key pointer to a RSA key structure that points to public key - * and context to use. - * data data to be signed. - * len length in bytes of data. - * signature location to store signature. - * sig_len size of the signature storage area - * returns - * N Success on SIG_MODE_FINAL = returns signature length in bytes - * 0 Success on SIG_MODE_INIT and UPDATE - * <0 Failure - */ - - -static int -dst_rsaref_sign(const int mode, DST_KEY *dkey, void **context, - const u_char *data, const int len, - u_char *signature, const int sig_len) -{ - int sign_len = 0; - R_SIGNATURE_CTX *ctx = NULL; - - if (mode & SIG_MODE_INIT) - ctx = malloc(sizeof(*ctx)); - else if (context) - ctx = (R_SIGNATURE_CTX *) *context; - if (ctx == NULL) - return (-1); - - if ((mode & SIG_MODE_INIT) && R_SignInit(ctx, DA_MD5)) - return (SIGN_INIT_FAILURE); - - /* equivalent of SIG_MODE_UPDATE */ - if ((mode & SIG_MODE_UPDATE) && (data && len > 0) && - R_SignUpdate(ctx, (u_char *) data, len)) - return (SIGN_UPDATE_FAILURE); - - if (mode & SIG_MODE_FINAL) { - RSA_Key *key = (RSA_Key *) dkey->dk_KEY_struct; - if (signature == NULL || - sig_len < (int)(key->rk_Public_Key->bits + 7) / 8) - return (SIGN_FINAL_FAILURE); - if(key == NULL || key->rk_Private_Key == NULL) - return (-1); - if (R_SignFinal(ctx, signature, &sign_len, - key->rk_Private_Key)) - return (SIGN_FINAL_FAILURE); - SAFE_FREE(ctx); - } - else { - if (context == NULL) - return (-1); - *context = (void *) ctx; - } - return (sign_len); -} - - -/* - * dst_rsaref_verify() - * Calls RSAREF verification routines. There are three steps to - * verification, INIT (initialize structures), UPDATE (hash (more) data), - * FINAL (generate a signature). This routine performs one or more of - * these steps. - * Parameters - * mode SIG_MODE_INIT, SIG_MODE_UPDATE and/or SIG_MODE_FINAL. - * key pointer to a RSA key structure that points to public key - * and context to use. - * data data signed. - * len length in bytes of data. - * signature signature. - * sig_len length in bytes of signature. - * returns - * 0 Success - * <0 Failure - */ - -static int -dst_rsaref_verify(const int mode, DST_KEY *dkey, void **context, - const u_char *data, const int len, - const u_char *signature, const int sig_len) -{ - R_SIGNATURE_CTX *ctx = NULL; - - if (mode & SIG_MODE_INIT) - ctx = malloc(sizeof(*ctx)); - else if (context) - ctx = (R_SIGNATURE_CTX *) *context; - if (ctx == NULL) - return (-1); - - if ((mode & SIG_MODE_INIT) && R_VerifyInit(ctx, DA_MD5)) - return (VERIFY_INIT_FAILURE); - - if ((mode & SIG_MODE_UPDATE) && (data && len > 0) && - R_VerifyUpdate(ctx, (u_char *) data, len)) - return (VERIFY_UPDATE_FAILURE); - - if ((mode & SIG_MODE_FINAL)) { - RSA_Key *key = (RSA_Key *) dkey->dk_KEY_struct; - - if (key == NULL || key->rk_Public_Key == NULL) - return (-1); - if (signature == NULL || sig_len <= 0) - return (VERIFY_FINAL_FAILURE); - if (R_VerifyFinal(ctx, (u_char *) signature, sig_len, - key->rk_Public_Key)) - return (VERIFY_FINAL_FAILURE); - } - else { - if (context == NULL) - return (-1); - *context = (void *) ctx; - } - - return (0); -} - - -/* - * dst_rsaref_to_dns_key - * Converts key in RSAREF to DNS distribution format - * This function gets in a pointer to the public key and a work area - * to write the key into. - * Parameters - * public KEY structure - * out_str buffer to write encoded key into - * out_len size of out_str - * Return - * N >= 0 length of encoded key - * n < 0 error - */ - -static int -dst_rsaref_to_dns_key(const DST_KEY *in_key, u_char *out_str, - const int out_len) -{ - int n, loc; - R_RSA_PUBLIC_KEY *public; - u_char *op = (u_char *) out_str; - - if (in_key == NULL || in_key->dk_KEY_struct == NULL || - out_len <= 0 || out_str == NULL) - return (-1); - public = (R_RSA_PUBLIC_KEY *) - ((RSA_Key *) in_key->dk_KEY_struct)->rk_Public_Key; - if (public == NULL) - return (-1); - - memset(op, 0, out_len); - - /* find first non zero */ - for (n = 0; public->exponent[n] == 0x0; n++) ; - - n = (MAX_RSA_MODULUS_LEN - n); /* find lenght of exponent */ - *op++ = (u_int8_t) n; - - if (n > (out_len - (op-out_str))) - return (-1); - memcpy(op, &public->exponent[MAX_RSA_MODULUS_LEN - n], n); - op += n; - n++; /* include the lenght field in this count */ - - /* find first non zero */ - for (loc = 0; public->modulus[loc] == 0x0; loc++) ; - - /*copy exponent */ - if ((MAX_RSA_MODULUS_LEN - loc) > (out_len - (op-out_str))) - return (-1); - memcpy(op, &public->modulus[loc], MAX_RSA_MODULUS_LEN - loc); - n += (MAX_RSA_MODULUS_LEN - loc); - return (n); -} - - -/* - * dst_rsaref_from_dns_key - * Converts from a DNS KEY RR format to an RSA KEY. - * Parameters - * len Length in bytes of DNS key - * key DNS key - * name Key name - * s_key DST structure that will point to the RSA key this routine - * will build. - * Return - * -1 The input key has fields that are larger than this package supports - * 0 The input key, s_key or name was null. - * 1 Success - */ -static int -dst_rsaref_from_dns_key(DST_KEY *s_key, const u_char *key, const int len) -{ - int bytes; - u_char *key_ptr; - RSA_Key *r_key; - - if (key == NULL || s_key == NULL || len < 0) - return (0); - - if (s_key->dk_KEY_struct) { /* do not reuse */ - dst_rsaref_free_key_structure(s_key->dk_KEY_struct); - s_key->dk_KEY_struct = NULL; - } - if (len == 0) /* null key no conversion needed */ - return (1); - - if ((r_key = (RSA_Key *) malloc(sizeof(RSA_Key))) == NULL) { - EREPORT(("dst_rsaref_from_dns_key(): Memory allocation error 1\n")); - return (0); - } - memset(r_key, 0, sizeof(RSA_Key)); - s_key->dk_KEY_struct = (void *) r_key; - r_key->rk_signer = strdup(s_key->dk_key_name); - r_key->rk_Public_Key = (R_RSA_PUBLIC_KEY *) - malloc(sizeof(R_RSA_PUBLIC_KEY)); - if (r_key->rk_Public_Key == NULL) { - EREPORT(("dst_rsaref_from_dns_key(): Memory allocation error 3\n")); - return (0); - } - memset(r_key->rk_Public_Key, 0, sizeof(R_RSA_PUBLIC_KEY)); - key_ptr = (u_char *) key; - bytes = (int) *key_ptr++; /* length of exponent in bytes */ - if (bytes == 0) { /* special case for long exponents */ - bytes = (int) dst_s_get_int16(key_ptr); - key_ptr += sizeof(u_int16_t); - } - if (bytes > MAX_RSA_MODULUS_LEN) { - dst_rsaref_free_key_structure(r_key); - return (-1); - } - memcpy(&r_key->rk_Public_Key->exponent[MAX_RSA_MODULUS_LEN - bytes], - key_ptr, bytes); - - key_ptr += bytes; /* beginning of modulus */ - bytes = len - bytes - 1; /* length of modulus */ - if (bytes > MAX_RSA_MODULUS_LEN) { - dst_rsaref_free_key_structure(r_key); - return (-1); - } - memcpy(&r_key->rk_Public_Key->modulus[MAX_RSA_MODULUS_LEN - bytes], - key_ptr, bytes); - r_key->rk_Public_Key->bits = bytes * 8; - s_key->dk_key_size = r_key->rk_Public_Key->bits; - - return (1); -} - - -/* - * dst_rsaref_key_to_file_format - * Encodes an RSA Key into the portable file format. - * Parameters - * rkey RSA KEY structure - * buff output buffer - * buff_len size of output buffer - * Return - * 0 Failure - null input rkey - * -1 Failure - not enough space in output area - * N Success - Length of data returned in buff - */ - -static int -dst_rsaref_key_to_file_format(const DST_KEY *in_key, u_char *buff, - const int buff_len) -{ - u_char *bp; - int len, b_len; - R_RSA_PRIVATE_KEY *rkey; - - if (in_key == NULL || in_key->dk_KEY_struct == NULL) - return (-1); - rkey = (R_RSA_PRIVATE_KEY *) - ((RSA_Key *) in_key->dk_KEY_struct)->rk_Private_Key; - if (rkey == NULL) /* no output */ - return (0); - if (buff == NULL || buff_len <= (int) strlen(key_file_fmt_str)) - return (-1); /* no OR not enough space in output area */ - - memset(buff, 0, buff_len); /* just in case */ - /* write file header */ - sprintf(buff, key_file_fmt_str, KEY_FILE_FORMAT, KEY_RSA, "RSA"); - - bp = (char *) strchr(buff, '\0'); - b_len = buff_len - (bp - buff); - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Modulus: ", - rkey->modulus, - MAX_RSA_MODULUS_LEN)) <= 0) - return (-1); - - bp += len; - b_len -= len; - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "PublicExponent: ", - rkey->publicExponent, - MAX_RSA_MODULUS_LEN)) <= 0) - return (-2); - bp += len; - b_len -= len; - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "PrivateExponent: ", - rkey->exponent, - MAX_RSA_MODULUS_LEN)) <= 0) - return (-3); - bp += len; - b_len -= len; - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Prime1: ", - rkey->prime[0], - MAX_RSA_PRIME_LEN)) < 0) - return (-4); - bp += len; - b_len -= len; - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Prime2: ", - rkey->prime[1], - MAX_RSA_PRIME_LEN)) < 0) - return (-5); - bp += len; - b_len -= len; - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Exponent1: ", - rkey->primeExponent[0], - MAX_RSA_PRIME_LEN)) < 0) - return (-6); - bp += len; - b_len -= len; - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Exponent2: ", - rkey->primeExponent[1], - MAX_RSA_PRIME_LEN)) < 0) - return (-7); - bp += len; - b_len -= len; - if ((len = dst_s_conv_bignum_u8_to_b64(bp, b_len, "Coefficient: ", - rkey->coefficient, - MAX_RSA_PRIME_LEN)) < 0) - return (-8); - bp += len; - b_len -= len; - return (buff_len - b_len); -} - - -/* - * dst_rsaref_key_from_file_format - * Converts contents of a private key file into a private RSA key. - * Parameters - * r_key structure to put key into - * buff buffer containing the encoded key - * buff_len the length of the buffer - * Return - * n >= 0 Foot print of the key converted - * n < 0 Error in conversion - */ - -static int -dst_rsaref_key_from_file_format(DST_KEY *d_key, const u_char *buff, - const int buff_len) -{ - const char *p = (char *) buff; - R_RSA_PRIVATE_KEY key; - int foot = -1; - RSA_Key *r_key; - - if (d_key == NULL || buff == NULL || buff_len < 0) - return (-1); - - memset(&key, 0, sizeof(key)); - - if (!dst_s_verify_str(&p, "Modulus: ")) - return (-3); - - if (!dst_s_conv_bignum_b64_to_u8(&p, key.modulus, MAX_RSA_MODULUS_LEN)) - return (-4); - - key.bits = dst_s_calculate_bits(key.modulus, MAX_RSA_MODULUS_BITS); - - while (*++p && p < (char *) &buff[buff_len]) { - if (dst_s_verify_str(&p, "PublicExponent: ")) { - if (!dst_s_conv_bignum_b64_to_u8(&p, - key.publicExponent, - MAX_RSA_MODULUS_LEN)) - return (-5); - } else if (dst_s_verify_str(&p, "PrivateExponent: ")) { - if (!dst_s_conv_bignum_b64_to_u8(&p, key.exponent, - MAX_RSA_MODULUS_LEN)) - return (-6); - } else if (dst_s_verify_str(&p, "Prime1: ")) { - if (!dst_s_conv_bignum_b64_to_u8(&p, key.prime[0], - MAX_RSA_PRIME_LEN)) - return (-7); - } else if (dst_s_verify_str(&p, "Prime2: ")) { - if (!dst_s_conv_bignum_b64_to_u8(&p, key.prime[1], - MAX_RSA_PRIME_LEN)) - return (-8); - } else if (dst_s_verify_str(&p, "Exponent1: ")) { - if (!dst_s_conv_bignum_b64_to_u8(&p, - key.primeExponent[0], - MAX_RSA_PRIME_LEN)) - return (-9); - } else if (dst_s_verify_str(&p, "Exponent2: ")) { - if (!dst_s_conv_bignum_b64_to_u8(&p, - key.primeExponent[1], - MAX_RSA_PRIME_LEN)) - return (-10); - } else if (dst_s_verify_str(&p, "Coefficient: ")) { - if (!dst_s_conv_bignum_b64_to_u8(&p, key.coefficient, - MAX_RSA_PRIME_LEN)) - return (-11); - } else { - EREPORT(("dst_rsaref_key_from_file_format: Bad keyword %s\n", p)); - return (-12); - } - } /* while p */ - - r_key = (RSA_Key *) malloc(sizeof(RSA_Key)); - if (r_key == NULL) { - return (-2); - } - memset(r_key, 0, sizeof(*r_key)); - - r_key->rk_Private_Key = - (R_RSA_PRIVATE_KEY *) malloc(sizeof(R_RSA_PRIVATE_KEY)); - if (r_key->rk_Private_Key == NULL) { - EREPORT(("dst_rsaref_key_from_file_format: Memory allocation error\n")); - return (-13); - } - r_key->rk_Public_Key = (R_RSA_PUBLIC_KEY *) r_key->rk_Private_Key; - memcpy(r_key->rk_Private_Key, &key, sizeof(R_RSA_PRIVATE_KEY)); - - r_key->rk_signer = strdup(d_key->dk_key_name); - d_key->dk_KEY_struct = (void *) r_key; - d_key->dk_key_size = r_key->rk_Private_Key->bits; - - return (0); -} - - - -/* - * dst_rsaref_compare_keys - * Compare two keys for equality. - * Return - * 0 The keys are equal - * NON-ZERO The keys are not equal - */ - -static int -dst_rsaref_compare_keys(const DST_KEY *dkey1, const DST_KEY *dkey2) -{ - RSA_Key *rkey1 = (RSA_Key *) dkey1->dk_KEY_struct; - RSA_Key *rkey2 = (RSA_Key *) dkey2->dk_KEY_struct; - - if (rkey1 == NULL && rkey2 == NULL) - return (0); /* same */ - else if (rkey1 == NULL) - return (1); - else if (rkey2 == NULL) - return (2); - return (memcmp(rkey1->rk_Public_Key, rkey2->rk_Public_Key, - sizeof(R_RSA_PUBLIC_KEY))); -} - -/* - * dst_rsaref_generate_keypair - * Generates unique keys that are hard to predict. - * Parameters - * key generic Key structure - * exp the public exponent - * Return - * 0 Failure - * 1 Success - */ - -static int -dst_rsaref_generate_keypair(DST_KEY *key, const int exp) -{ - R_RSA_PUBLIC_KEY *public; - R_RSA_PRIVATE_KEY *private; - R_RSA_PROTO_KEY proto; - R_RANDOM_STRUCT randomStruct; - RSA_Key *rsa; - int status; - - if (key == NULL || key->dk_alg != KEY_RSA) - return (0); - if (key->dk_key_size < MIN_RSA_MODULUS_BITS || - key->dk_key_size > MAX_RSA_MODULUS_BITS) { - EREPORT(("dst_rsaref_generate_keypair: Invalid key size\n")); - return (0); /* these are the limits on key size in RSAREF */ - } - /* allocate space */ - if ((public = (R_RSA_PUBLIC_KEY *) malloc(sizeof(R_RSA_PUBLIC_KEY))) - == NULL) { - EREPORT(("dst_rsaref_generate_keypair: Memory allocation error 1\n")); - return (0); - } - if ((private = (R_RSA_PRIVATE_KEY *) malloc(sizeof(R_RSA_PRIVATE_KEY))) - == NULL) { - EREPORT(("dst_rsaref_generate_keypair: Memory allocation error 2\n")); - return (0); - } - if ((rsa = (RSA_Key *) malloc(sizeof(RSA_Key))) == NULL) { - EREPORT(("dst_rsaref_generate_keypair: Memory allocation error 3\n")); - return (0); - } - memset(public, 0, sizeof(*public)); - memset(private, 0, sizeof(*private)); - - proto.bits = key->dk_key_size; - proto.useFermat4 = exp ? 0x1 : 0x0; /* 1 for f4=65537, 0 for f0=3 */ - EREPORT(("\ndst_rsaref_generate_keypair: Generating KEY for %s Please wait\n", - key->dk_key_name)); - - /* set up random seed */ - dst_rsaref_init_random_struct(&randomStruct); - - /* generate keys */ - status = R_GeneratePEMKeys(public, private, &proto, &randomStruct); - if (status) { - EREPORT(("dst_rsaref_generate_keypair: No Key Pair generated %d\n", - status)); - SAFE_FREE(public); - SAFE_FREE(private); - SAFE_FREE(rsa); - return (0); - } - memset(rsa, 0, sizeof(*rsa)); - rsa->rk_signer = key->dk_key_name; - rsa->rk_Private_Key = private; - rsa->rk_Public_Key = public; - key->dk_KEY_struct = (void *) rsa; - - return (1); -} - - -/* - * dst_rsaref_free_key_structure - * Frees all dynamicly allocated structures in r_key - */ - -static void * -dst_rsaref_free_key_structure(void *v_key) -{ - RSA_Key *r_key = (RSA_Key *) v_key; - - if (r_key != NULL) { - if ((void *) r_key->rk_Private_Key == (void *) r_key->rk_Public_Key) - r_key->rk_Public_Key = NULL; - SAFE_FREE(r_key->rk_Private_Key); - SAFE_FREE(r_key->rk_Public_Key); - SAFE_FREE(r_key->rk_signer); - SAFE_FREE(r_key); - } - return (NULL); -} - - -/* - * dst_rsaref_init_random_struct - * A random seed value is used in key generation. - * This routine gets a bunch of system values to randomize the - * randomstruct. A number of system calls are used to get somewhat - * unpredicable values, then a special function dst_s_prandom() is called - * that will do some magic depending on the system used. - * If this function is executed on reasonably busy machine then the values - * that prandom uses are hard to - * 1. Predict - * 2. Regenerate - * 3. Hard to spy on as nothing is stored to disk and data is consumed - * as fast as it is generated. - */ - -static void -dst_rsaref_init_random_struct(R_RANDOM_STRUCT * randomstruct) -{ - unsigned bytesNeeded; - struct timeval tv; - u_char *array; - int n; - - R_RandomInit(randomstruct); - - /* The runtime of the script is unpredictable within some range - * thus I'm getting the time of day again as this is an hard to guess - * value and the number of characters of the output from the script is - * hard to guess. - * This must be the FIRST CALL - */ - gettimeofday(&tv, 0); - R_RandomUpdate(randomstruct, (u_char *) &tv, - sizeof(struct timeval)); - - /* - * first find out how many bytes I need - */ - R_GetRandomBytesNeeded(&bytesNeeded, randomstruct); - - /* - * get a storage area for it addjust the area for the possible - * side effects of digest functions writing out in blocks - */ - array = (u_char *) malloc(bytesNeeded); - - /* extract the random data from /dev/random if present, generate - * it if not present - * first fill the buffer with semi random data - * then fill as much as possible with good random data - */ - n = dst_random(DST_RAND_SEMI, bytesNeeded, array); - n += dst_random(DST_RAND_KEY, bytesNeeded, array); - if (n <= bytesNeeded) { - SAFE_FREE(array); - return(0); - } - - /* supply the random data (even if it is larger than requested) */ - R_RandomUpdate(randomstruct, array, bytesNeeded); - - SAFE_FREE(array); - - R_GetRandomBytesNeeded(&bytesNeeded, randomstruct); - if (bytesNeeded) { - EREPORT(("InitRandomStruct() didn't initialize enough randomness\n")); - exit(33); - } -} - - -#else -#include "port_before.h" - -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#include <memory.h> -#include <sys/param.h> -#include <sys/time.h> -#include <netinet/in.h> - -#include "dst_internal.h" -#include "port_after.h" -int /* rsaref is not available */ -dst_rsaref_init() -{ - return (0); -} -#endif /* RSAREF */ diff --git a/usr/src/lib/libresolv2/common/dst/support.c b/usr/src/lib/libresolv2/common/dst/support.c index 4b3438f604..730397f4c0 100644 --- a/usr/src/lib/libresolv2/common/dst/support.c +++ b/usr/src/lib/libresolv2/common/dst/support.c @@ -1,11 +1,5 @@ -static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/support.c,v 1.11 2001/05/29 05:48:16 marka Exp $"; +static const char rcsid[] = "$Header: /proj/cvs/prod/libbind/dst/support.c,v 1.6 2005/10/11 00:10:13 marka Exp $"; -/* - * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" /* * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc. @@ -39,64 +33,8 @@ static const char rcsid[] = "$Header: /proj/cvs/isc/bind8/src/lib/dst/support.c, #include "dst_internal.h" #include "port_after.h" -/* - * dst_s_conv_bignum_u8_to_b64 - * This function converts binary data stored as a u_char[] to a - * base-64 string. Leading zeroes are discarded. If a header is - * supplied, it is prefixed to the input prior to encoding. The - * output is \n\0 terminated (the \0 is not included in output length). - * Parameters - * out_buf binary data to convert - * header character string to prefix to the output (label) - * bin_data binary data - * bin_len size of binary data - * Return - * -1 not enough space in output work area - * 0 no output - * >0 number of bytes written to output work area - */ - -int -dst_s_conv_bignum_u8_to_b64(char *out_buf, const int out_len, - const char *header, const u_char *bin_data, - const int bin_len) -{ - const u_char *bp = bin_data; - char *op = out_buf; - int lenh = 0, len64 = 0; - int local_in_len = bin_len; - int local_out_len = out_len; - - if (bin_data == NULL || bin_len <= 0) /* no data no */ - return (0); - if (out_buf == NULL || out_len <= 0) /* no output_work area */ - return (-1); - - /* suppress leading \0 */ - for (; (*bp == 0x0) && (local_in_len > 0); local_in_len--) - bp++; - - if (header) { /* add header to output string */ - lenh = strlen(header); - if (lenh < out_len) - memcpy(op, header, lenh); - else - return (-1); - local_out_len -= lenh; - op += lenh; - } - len64 = b64_ntop(bp, local_in_len, op, local_out_len - 2); - if (len64 < 0) - return (-1); - op += len64++; - *(op++) = '\n'; /* put CR in the output */ - *op = '\0'; /* make sure output is 0 terminated */ - return (lenh + len64); -} - - -/* +/*% * dst_s_verify_str() * Validate that the input string(*str) is at the head of the input * buffer(**buf). If so, move the buffer head pointer (*buf) to @@ -114,73 +52,20 @@ int dst_s_verify_str(const char **buf, const char *str) { int b, s; - if (*buf == NULL) /* error checks */ + if (*buf == NULL) /*%< error checks */ return (0); if (str == NULL || *str == '\0') return (1); - b = strlen(*buf); /* get length of strings */ + b = strlen(*buf); /*%< get length of strings */ s = strlen(str); - if (s > b || strncmp(*buf, str, s)) /* check if same */ - return (0); /* not a match */ - (*buf) += s; /* advance pointer */ + if (s > b || strncmp(*buf, str, s)) /*%< check if same */ + return (0); /*%< not a match */ + (*buf) += s; /*%< advance pointer */ return (1); } - -/* - * dst_s_conv_bignum_b64_to_u8 - * Read a line of base-64 encoded string from the input buffer, - * convert it to binary, and store it in an output area. The - * input buffer is read until reaching a newline marker or the - * end of the buffer. The binary data is stored in the last X - * number of bytes of the output area where X is the size of the - * binary output. If the operation is successful, the input buffer - * pointer is advanced. This procedure does not do network to host - * byte order conversion. - * Parameters - * buf Pointer to encoded input string. Pointer is updated if - * function is successfull. - * loc Output area. - * loclen Size in bytes of output area. - * Return - * >0 Return = number of bytes of binary data stored in loc. - * 0 Failure. - */ - -int -dst_s_conv_bignum_b64_to_u8(const char **buf, u_char *loc, const int loclen) -{ - int blen; - char *bp; - u_char bstr[RAW_KEY_SIZE]; - - if (buf == NULL || *buf == NULL) { /* error checks */ - EREPORT(("dst_s_conv_bignum_b64_to_u8: null input buffer.\n")); - return (0); - } - bp = strchr(*buf, '\n'); /* find length of input line */ - if (bp != NULL) - *bp = (u_char) NULL; - - blen = b64_pton(*buf, bstr, sizeof(bstr)); - if (blen <= 0) { - EREPORT(("dst_s_conv_bignum_b64_to_u8: decoded value is null.\n")); - return (0); - } - else if (loclen < blen) { - EREPORT(("dst_s_conv_bignum_b64_to_u8: decoded value is longer than output buffer.\n")); - return (0); - } - if (bp) - *buf = bp; /* advancing buffer past \n */ - memset(loc, 0, loclen - blen); /* clearing unused output area */ - memcpy(loc + loclen - blen, bstr, blen); /* write last blen bytes */ - return (blen); -} - - -/* +/*% * dst_s_calculate_bits * Given a binary number represented in a u_char[], determine * the number of significant bits used. @@ -204,8 +89,7 @@ dst_s_calculate_bits(const u_char *str, const int max_bits) return (bits); } - -/* +/*% * calculates a checksum used in dst for an id. * takes an array of bytes and a length. * returns a 16 bit checksum. @@ -218,7 +102,7 @@ dst_s_id_calc(const u_char *key, const int keysize) int size = keysize; if (!key || (keysize <= 0)) - return (-1); + return (0xffffU); for (ac = 0; size > 1; size -= 2, kp += 2) ac += ((*kp) << 8) + *(kp + 1); @@ -230,7 +114,7 @@ dst_s_id_calc(const u_char *key, const int keysize) return (ac & 0xffff); } -/* +/*% * dst_s_dns_key_id() Function to calculate DNSSEC footprint from KEY record * rdata * Input: @@ -246,7 +130,7 @@ dst_s_dns_key_id(const u_char *dns_key_rdata, const int rdata_len) return 0; /* compute id */ - if (dns_key_rdata[3] == KEY_RSA) /* Algorithm RSA */ + if (dns_key_rdata[3] == KEY_RSA) /*%< Algorithm RSA */ return dst_s_get_int16((const u_char *) &dns_key_rdata[rdata_len - 3]); else if (dns_key_rdata[3] == KEY_HMAC_MD5) @@ -257,7 +141,7 @@ dst_s_dns_key_id(const u_char *dns_key_rdata, const int rdata_len) return dst_s_id_calc(dns_key_rdata, rdata_len); } -/* +/*% * dst_s_get_int16 * This routine extracts a 16 bit integer from a two byte character * string. The character string is assumed to be in network byte @@ -276,8 +160,7 @@ dst_s_get_int16(const u_char *buf) return (a); } - -/* +/*% * dst_s_get_int32 * This routine extracts a 32 bit integer from a four byte character * string. The character string is assumed to be in network byte @@ -297,8 +180,7 @@ dst_s_get_int32(const u_char *buf) return (a); } - -/* +/*% * dst_s_put_int16 * Take a 16 bit integer and store the value in a two byte * character string. The integer is assumed to be in network @@ -316,8 +198,7 @@ dst_s_put_int16(u_int8_t *buf, const u_int16_t val) buf[1] = (u_int8_t)(val); } - -/* +/*% * dst_s_put_int32 * Take a 32 bit integer and store the value in a four byte * character string. The integer is assumed to be in network @@ -337,13 +218,12 @@ dst_s_put_int32(u_int8_t *buf, const u_int32_t val) buf[3] = (u_int8_t)(val); } - -/* +/*% * dst_s_filename_length * * This function returns the number of bytes needed to hold the * filename for a key file. '/', '\' and ':' are not allowed. - * form: K<keyname>+<alg>+<id>.<suffix> + * form: K<keyname>+<alg>+<id>.<suffix> * * Returns 0 if the filename would contain either '\', '/' or ':' */ @@ -369,13 +249,12 @@ dst_s_filename_length(const char *name, const char *suffix) return (1 + strlen(name) + 6 + strlen(suffix)); } - -/* +/*% * dst_s_build_filename () * Builds a key filename from the key name, it's id, and a * suffix. '\', '/' and ':' are not allowed. fA filename is of the - * form: K<keyname><id>.<suffix> - * form: K<keyname>+<alg>+<id>.<suffix> + * form: K<keyname><id>.<suffix> + * form: K<keyname>+<alg>+<id>.<suffix> * * Returns -1 if the conversion fails: * if the filename would be too long for space allotted @@ -409,7 +288,7 @@ dst_s_build_filename(char *filename, const char *name, u_int16_t id, return (0); } -/* +/*% * dst_s_fopen () * Open a file in the dst_path directory. If perm is specified, the * file is checked for existence first, and not opened if it exists. @@ -426,19 +305,15 @@ dst_s_fopen(const char *filename, const char *mode, int perm) { FILE *fp; char pathname[PATH_MAX]; - size_t plen = sizeof(pathname); + + if (strlen(filename) + strlen(dst_path) >= sizeof(pathname)) + return (NULL); if (*dst_path != '\0') { strcpy(pathname, dst_path); - plen -= strlen(pathname); - } - else - pathname[0] = '\0'; - - if (plen > strlen(filename)) - strncpy(&pathname[PATH_MAX - plen], filename, plen-1); - else - return (NULL); + strcat(pathname, filename); + } else + strcpy(pathname, filename); fp = fopen(pathname, mode); if (perm) @@ -463,3 +338,5 @@ dst_s_dump(const int mode, const u_char *data, const int size, #endif } } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/inet/inet_cidr_ntop.c b/usr/src/lib/libresolv2/common/inet/inet_cidr_ntop.c index 738d82d3dd..bf960a8acc 100644 --- a/usr/src/lib/libresolv2/common/inet/inet_cidr_ntop.c +++ b/usr/src/lib/libresolv2/common/inet/inet_cidr_ntop.c @@ -1,29 +1,22 @@ /* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1998,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_cidr_ntop.c,v 8.7 2001/09/28 05:19:36 marka Exp $"; +static const char rcsid[] = "$Id: inet_cidr_ntop.c,v 1.7 2006/10/11 02:18:18 marka Exp $"; #endif #include "port_before.h" @@ -47,12 +40,12 @@ static const char rcsid[] = "$Id: inet_cidr_ntop.c,v 8.7 2001/09/28 05:19:36 mar # define SPRINTF(x) ((size_t)sprintf x) #endif -static char * inet_cidr_ntop_ipv4 __P((const u_char *src, int bits, - char *dst, size_t size)); -static char * inet_cidr_ntop_ipv6 __P((const u_char *src, int bits, - char *dst, size_t size)); +static char * +inet_cidr_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size); +static char * +inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size); -/* +/*% * char * * inet_cidr_ntop(af, src, bits, dst, size) * convert network address from network to presentation format. @@ -99,7 +92,7 @@ decoct(const u_char *src, int bytes, char *dst, size_t size) { return (dst - odst); } -/* +/*% * static char * * inet_cidr_ntop_ipv4(src, bits, dst, size) * convert IPv4 network address from network to presentation format. @@ -128,7 +121,7 @@ inet_cidr_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) { if (bits == -1) len = 4; else - for (len = 1, b = 1 ; b < 4; b++) + for (len = 1, b = 1 ; b < 4U; b++) if (*(src + b)) len = b + 1; @@ -137,7 +130,7 @@ inet_cidr_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) { if (len > bytes) bytes = len; b = decoct(src, bytes, dst, size); - if (b == 0) + if (b == 0U) goto emsgsize; dst += b; size -= b; @@ -185,7 +178,9 @@ inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) { for (i = 0; i < NS_IN6ADDRSZ; i++) words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); best.base = -1; + best.len = 0; cur.base = -1; + cur.len = 0; for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { if (words[i] == 0) { if (cur.base == -1) @@ -264,3 +259,5 @@ inet_cidr_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) { strcpy(dst, tmp); return (dst); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/inet/inet_cidr_pton.c b/usr/src/lib/libresolv2/common/inet/inet_cidr_pton.c index 26fe2e926a..07652af463 100644 --- a/usr/src/lib/libresolv2/common/inet/inet_cidr_pton.c +++ b/usr/src/lib/libresolv2/common/inet/inet_cidr_pton.c @@ -1,29 +1,22 @@ /* - * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1998,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_cidr_pton.c,v 8.7 2001/09/28 04:21:28 marka Exp $"; +static const char rcsid[] = "$Id: inet_cidr_pton.c,v 1.6 2005/04/27 04:56:19 sra Exp $"; #endif #include "port_before.h" @@ -56,7 +49,7 @@ static int inet_cidr_pton_ipv6 __P((const char *src, u_char *dst, static int getbits(const char *, int ipv6); -/* +/*% * int * inet_cidr_pton(af, src, dst, *bits) * convert network address from presentation to network format. @@ -105,7 +98,7 @@ inet_cidr_pton_ipv4(const char *src, u_char *dst, int *pbits, int ipv6) { if (tmp > 255) goto enoent; } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch)); - if (size-- == 0) + if (size-- == 0U) goto emsgsize; *dst++ = (u_char) tmp; if (ch == '\0' || ch == '/') @@ -140,7 +133,7 @@ inet_cidr_pton_ipv4(const char *src, u_char *dst, int *pbits, int ipv6) { goto enoent; /* Extend address to four octets. */ - while (size-- > 0) + while (size-- > 0U) *dst++ = 0; *pbits = bits; @@ -211,7 +204,7 @@ inet_cidr_pton_ipv6(const char *src, u_char *dst, int *pbits) { inet_cidr_pton_ipv4(curtok, tp, &bits, 1) == 0) { tp += NS_INADDRSZ; saw_xdigit = 0; - break; /* '\0' was seen by inet_pton4(). */ + break; /*%< '\\0' was seen by inet_pton4(). */ } if (ch == '/') { bits = getbits(src, 1); @@ -258,25 +251,27 @@ inet_cidr_pton_ipv6(const char *src, u_char *dst, int *pbits) { return (-1); } -int +static int getbits(const char *src, int ipv6) { int bits = 0; char *cp, ch; - if (*src == '\0') /* syntax */ + if (*src == '\0') /*%< syntax */ return (-2); do { ch = *src++; cp = strchr(digits, ch); - if (cp == NULL) /* syntax */ + if (cp == NULL) /*%< syntax */ return (-2); bits *= 10; bits += cp - digits; - if (bits == 0 && *src != '\0') /* no leading zeros */ + if (bits == 0 && *src != '\0') /*%< no leading zeros */ return (-2); - if (bits > (ipv6 ? 128 : 32)) /* range error */ + if (bits > (ipv6 ? 128 : 32)) /*%< range error */ return (-2); } while (*src != '\0'); return (bits); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/inet/inet_data.c b/usr/src/lib/libresolv2/common/inet/inet_data.c index 80a87e5660..4373a171a0 100644 --- a/usr/src/lib/libresolv2/common/inet/inet_data.c +++ b/usr/src/lib/libresolv2/common/inet/inet_data.c @@ -1,29 +1,22 @@ /* - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1995-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$Id: inet_data.c,v 1.2 2001/06/20 22:06:36 marka Exp $"; +static char rcsid[] = "$Id: inet_data.c,v 1.4 2005/04/27 04:56:19 sra Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -49,3 +42,5 @@ static char rcsid[] = "$Id: inet_data.c,v 1.2 2001/06/20 22:06:36 marka Exp $"; const struct in6_addr isc_in6addr_any = IN6ADDR_ANY_INIT; const struct in6_addr isc_in6addr_loopback = IN6ADDR_LOOPBACK_INIT; + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/inet/inet_lnaof.c b/usr/src/lib/libresolv2/common/inet/inet_lnaof.c index 0212d18f51..70ac409512 100644 --- a/usr/src/lib/libresolv2/common/inet/inet_lnaof.c +++ b/usr/src/lib/libresolv2/common/inet/inet_lnaof.c @@ -1,9 +1,4 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -35,7 +30,6 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#pragma ident "%Z%%M% %I% %E% SMI" #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)inet_lnaof.c 8.1 (Berkeley) 6/4/93"; @@ -49,24 +43,16 @@ static const char sccsid[] = "@(#)inet_lnaof.c 8.1 (Berkeley) 6/4/93"; #include "port_after.h" -/* +/*% * Return the local network address portion of an * internet address; handles class a/b/c network * number formats. */ -#ifdef ORIGINAL_ISC_CODE u_long -#else -in_addr_t -#endif inet_lnaof(in) struct in_addr in; { -#ifdef ORIGINAL_ISC_CODE - u_long i = ntohl(in.s_addr); -#else - in_addr_t i = ntohl(in.s_addr); -#endif + register u_long i = ntohl(in.s_addr); if (IN_CLASSA(i)) return ((i)&IN_CLASSA_HOST); @@ -75,3 +61,5 @@ inet_lnaof(in) else return ((i)&IN_CLASSC_HOST); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/inet/inet_makeaddr.c b/usr/src/lib/libresolv2/common/inet/inet_makeaddr.c index 59dc91d218..c56cb3eaeb 100644 --- a/usr/src/lib/libresolv2/common/inet/inet_makeaddr.c +++ b/usr/src/lib/libresolv2/common/inet/inet_makeaddr.c @@ -1,9 +1,4 @@ /* - * Copyright (c) 1997-2001 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -36,8 +31,6 @@ * SUCH DAMAGE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)inet_makeaddr.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ @@ -50,38 +43,26 @@ static const char sccsid[] = "@(#)inet_makeaddr.c 8.1 (Berkeley) 6/4/93"; #include "port_after.h" -/* +/*% * Formulate an Internet address from network + host. Used in * building addresses stored in the ifnet structure. */ struct in_addr inet_makeaddr(net, host) -#ifdef ORIGINAL_ISC_CODE u_long net, host; -#else - in_addr_t net, host; -#endif { -#ifdef ORIGINAL_ISC_CODE - u_long addr; -#else - in_addr_t addr; - struct in_addr inaddr; -#endif + struct in_addr a; - if (net < 128) - addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); - else if (net < 65536) - addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST); + if (net < 128U) + a.s_addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); + else if (net < 65536U) + a.s_addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST); else if (net < 16777216L) - addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST); + a.s_addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST); else - addr = net | host; -#ifdef ORIGINAL_ISC_CODE - addr = htonl(addr); - return (*(struct in_addr *)&addr); -#else - inaddr.s_addr = htonl(addr); - return (inaddr); -#endif + a.s_addr = net | host; + a.s_addr = htonl(a.s_addr); + return (a); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/inet/inet_net_ntop.c b/usr/src/lib/libresolv2/common/inet/inet_net_ntop.c index 0c77c1614a..fb28e3cbe5 100644 --- a/usr/src/lib/libresolv2/common/inet/inet_net_ntop.c +++ b/usr/src/lib/libresolv2/common/inet/inet_net_ntop.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.8 2001/09/27 15:08:36 marka Exp $"; +static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.5 2006/06/20 02:50:14 marka Exp $"; #endif #include "port_before.h" @@ -51,7 +44,7 @@ static char * inet_net_ntop_ipv4 __P((const u_char *src, int bits, static char * inet_net_ntop_ipv6 __P((const u_char *src, int bits, char *dst, size_t size)); -/* +/*% * char * * inet_net_ntop(af, src, bits, dst, size) * convert network number from network to presentation format. @@ -80,7 +73,7 @@ inet_net_ntop(af, src, bits, dst, size) } } -/* +/*% * static char * * inet_net_ntop_ipv4(src, bits, dst, size) * convert IPv4 network number from network to presentation format. @@ -155,7 +148,7 @@ inet_net_ntop_ipv4(src, bits, dst, size) return (NULL); } -/* +/*% * static char * * inet_net_ntop_ipv6(src, bits, fakebits, dst, size) * convert IPv6 network number from network to presentation format. @@ -166,7 +159,7 @@ inet_net_ntop_ipv4(src, bits, dst, size) * pointer to dst, or NULL if an error occurred (check errno). * note: * network byte order assumed. this means 192.5.5.240/28 has - * 0b11110000 in its fourth octet. + * 0x11110000 in its fourth octet. * author: * Vadim Kogan (UCB), June 2001 * Original version (IPv4) by Paul Vixie (ISC), July 1996 @@ -271,7 +264,7 @@ inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) { } } /* Format CIDR /width. */ - SPRINTF((cp, "/%u", bits)); + sprintf(cp, "/%u", bits); if (strlen(outbuf) + 1 > size) goto emsgsize; strcpy(dst, outbuf); @@ -282,3 +275,5 @@ emsgsize: errno = EMSGSIZE; return (NULL); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/inet/inet_net_pton.c b/usr/src/lib/libresolv2/common/inet/inet_net_pton.c index 18a89be9ae..8d8bfb1f64 100644 --- a/usr/src/lib/libresolv2/common/inet/inet_net_pton.c +++ b/usr/src/lib/libresolv2/common/inet/inet_net_pton.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Copyright (c) 1996,1999 by Internet Software Consortium. + * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1996, 1998, 1999, 2001, 2003 Internet Software Consortium. * - * Permission to use, copy, modify, and distribute this software for any + * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_net_pton.c,v 1.13 2001/09/27 15:08:38 marka Exp $"; +static const char rcsid[] = "$Id: inet_net_pton.c,v 1.10 2008/11/14 02:36:51 marka Exp $"; #endif #include "port_before.h" @@ -49,7 +42,7 @@ static const char rcsid[] = "$Id: inet_net_pton.c,v 1.13 2001/09/27 15:08:38 mar # define SPRINTF(x) ((size_t)sprintf x) #endif -/* +/*% * static int * inet_net_pton_ipv4(src, dst, size) * convert IPv4 network number from presentation to network format. @@ -66,7 +59,7 @@ static const char rcsid[] = "$Id: inet_net_pton.c,v 1.13 2001/09/27 15:08:38 mar * Paul Vixie (ISC), June 1996 */ static int -inet_net_pton_ipv4( const char *src, u_char *dst, size_t size) { +inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) { static const char xdigits[] = "0123456789abcdef"; static const char digits[] = "0123456789"; int n, ch, tmp = 0, dirty, bits; @@ -77,10 +70,10 @@ inet_net_pton_ipv4( const char *src, u_char *dst, size_t size) { && isascii((unsigned char)(src[1])) && isxdigit((unsigned char)(src[1]))) { /* Hexadecimal: Eat nybble string. */ - if (size <= 0) + if (size <= 0U) goto emsgsize; dirty = 0; - src++; /* skip x or X. */ + src++; /*%< skip x or X. */ while ((ch = *src++) != '\0' && isascii(ch) && isxdigit(ch)) { if (isupper(ch)) ch = tolower(ch); @@ -91,14 +84,14 @@ inet_net_pton_ipv4( const char *src, u_char *dst, size_t size) { else tmp = (tmp << 4) | n; if (++dirty == 2) { - if (size-- <= 0) + if (size-- <= 0U) goto emsgsize; *dst++ = (u_char) tmp; dirty = 0; } } - if (dirty) { /* Odd trailing nybble? */ - if (size-- <= 0) + if (dirty) { /*%< Odd trailing nybble? */ + if (size-- <= 0U) goto emsgsize; *dst++ = (u_char) (tmp << 4); } @@ -115,7 +108,7 @@ inet_net_pton_ipv4( const char *src, u_char *dst, size_t size) { goto enoent; } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch)); - if (size-- <= 0) + if (size-- <= 0U) goto emsgsize; *dst++ = (u_char) tmp; if (ch == '\0' || ch == '/') @@ -133,18 +126,18 @@ inet_net_pton_ipv4( const char *src, u_char *dst, size_t size) { if (ch == '/' && isascii((unsigned char)(src[0])) && isdigit((unsigned char)(src[0])) && dst > odst) { /* CIDR width specifier. Nothing can follow it. */ - ch = *src++; /* Skip over the /. */ + ch = *src++; /*%< Skip over the /. */ bits = 0; do { n = strchr(digits, ch) - digits; INSIST(n >= 0 && n <= 9); bits *= 10; bits += n; + if (bits > 32) + goto enoent; } while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch)); if (ch != '\0') goto enoent; - if (bits > 32) - goto emsgsize; } /* Firey death and destruction unless we prefetched EOS. */ @@ -156,23 +149,29 @@ inet_net_pton_ipv4( const char *src, u_char *dst, size_t size) { goto enoent; /* If no CIDR spec was given, infer width from net class. */ if (bits == -1) { - if (*odst >= 240) /* Class E */ + if (*odst >= 240) /*%< Class E */ bits = 32; - else if (*odst >= 224) /* Class D */ - bits = 4; - else if (*odst >= 192) /* Class C */ + else if (*odst >= 224) /*%< Class D */ + bits = 8; + else if (*odst >= 192) /*%< Class C */ bits = 24; - else if (*odst >= 128) /* Class B */ + else if (*odst >= 128) /*%< Class B */ bits = 16; - else /* Class A */ + else /*%< Class A */ bits = 8; /* If imputed mask is narrower than specified octets, widen. */ - if (bits >= 8 && bits < ((dst - odst) * 8)) + if (bits < ((dst - odst) * 8)) bits = (dst - odst) * 8; + /* + * If there are no additional bits specified for a class D + * address adjust bits to 4. + */ + if (bits == 8 && *odst == 224) + bits = 4; } /* Extend network to cover the actual mask. */ while (bits > ((dst - odst) * 8)) { - if (size-- <= 0) + if (size-- <= 0U) goto emsgsize; *dst++ = '\0'; } @@ -201,11 +200,11 @@ getbits(const char *src, int *bitsp) { pch = strchr(digits, ch); if (pch != NULL) { - if (n++ != 0 && val == 0) /* no leading zeros */ + if (n++ != 0 && val == 0) /*%< no leading zeros */ return (0); val *= 10; val += (pch - digits); - if (val > 128) /* range */ + if (val > 128) /*%< range */ return (0); continue; } @@ -232,16 +231,16 @@ getv4(const char *src, u_char *dst, int *bitsp) { pch = strchr(digits, ch); if (pch != NULL) { - if (n++ != 0 && val == 0) /* no leading zeros */ + if (n++ != 0 && val == 0) /*%< no leading zeros */ return (0); val *= 10; val += (pch - digits); - if (val > 255) /* range */ + if (val > 255) /*%< range */ return (0); continue; } if (ch == '.' || ch == '/') { - if (dst - odst > 3) /* too many octets? */ + if (dst - odst > 3) /*%< too many octets? */ return (0); *dst++ = val; if (ch == '/') @@ -254,7 +253,7 @@ getv4(const char *src, u_char *dst, int *bitsp) { } if (n == 0) return (0); - if (dst - odst > 3) /* too many octets? */ + if (dst - odst > 3) /*%< too many octets? */ return (0); *dst++ = val; return (1); @@ -323,7 +322,7 @@ inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) { tp += NS_INADDRSZ; saw_xdigit = 0; ipv4 = 1; - break; /* '\0' was seen by inet_pton4(). */ + break; /*%< '\\0' was seen by inet_pton4(). */ } if (ch == '/' && getbits(src, &bits) > 0) break; @@ -379,7 +378,7 @@ inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) { return (-1); } -/* +/*% * int * inet_net_pton(af, src, dst, size) * convert network number from presentation to network format. @@ -404,3 +403,5 @@ inet_net_pton(int af, const char *src, void *dst, size_t size) { return (-1); } } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/inet/inet_neta.c b/usr/src/lib/libresolv2/common/inet/inet_neta.c index 1a71b11906..63a6c201a4 100644 --- a/usr/src/lib/libresolv2/common/inet/inet_neta.c +++ b/usr/src/lib/libresolv2/common/inet/inet_neta.c @@ -1,29 +1,22 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_neta.c,v 1.6 1999/01/08 19:23:45 vixie Exp $"; +static const char rcsid[] = "$Id: inet_neta.c,v 1.3 2005/04/27 04:56:20 sra Exp $"; #endif #include "port_before.h" @@ -45,7 +38,7 @@ static const char rcsid[] = "$Id: inet_neta.c,v 1.6 1999/01/08 19:23:45 vixie Ex # define SPRINTF(x) ((size_t)sprintf x) #endif -/* +/*% * char * * inet_neta(src, dst, size) * format a u_long network number into presentation format. @@ -92,3 +85,5 @@ inet_neta(src, dst, size) errno = EMSGSIZE; return (NULL); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/inet/inet_netof.c b/usr/src/lib/libresolv2/common/inet/inet_netof.c index a5395af2d4..c228e3d818 100644 --- a/usr/src/lib/libresolv2/common/inet/inet_netof.c +++ b/usr/src/lib/libresolv2/common/inet/inet_netof.c @@ -1,9 +1,4 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -36,8 +31,6 @@ * SUCH DAMAGE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)inet_netof.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ @@ -50,23 +43,15 @@ static const char sccsid[] = "@(#)inet_netof.c 8.1 (Berkeley) 6/4/93"; #include "port_after.h" -/* +/*% * Return the network number from an internet * address; handles class a/b/c network #'s. */ -#ifdef ORIGINAL_ISC_CODE u_long -#else -in_addr_t -#endif inet_netof(in) struct in_addr in; { -#ifdef ORIGINAL_ISC_CODE register u_long i = ntohl(in.s_addr); -#else - register in_addr_t i = ntohl(in.s_addr); -#endif if (IN_CLASSA(i)) return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); @@ -75,3 +60,5 @@ inet_netof(in) else return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/inet/inet_network.c b/usr/src/lib/libresolv2/common/inet/inet_network.c index e1f6f6d96a..47976cff68 100644 --- a/usr/src/lib/libresolv2/common/inet/inet_network.c +++ b/usr/src/lib/libresolv2/common/inet/inet_network.c @@ -1,9 +1,4 @@ /* - * Copyright 1997-2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -36,8 +31,6 @@ * SUCH DAMAGE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)inet_network.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ @@ -51,30 +44,18 @@ static const char sccsid[] = "@(#)inet_network.c 8.1 (Berkeley) 6/4/93"; #include "port_after.h" -/* +/*% * Internet network address interpretation routine. * The library routines call this routine to interpret * network numbers. */ -#ifdef ORIGINAL_ISC_CODE u_long -#else -in_addr_t -#endif inet_network(cp) register const char *cp; { -#ifdef ORIGINAL_ISC_CODE register u_long val, base, n, i; -#else - register in_addr_t val, base, n, i; -#endif register char c; -#ifdef ORIGINAL_ISC_CODE u_long parts[4], *pp = parts; -#else - in_addr_t parts[4], *pp = parts; -#endif int digit; again: @@ -85,16 +66,16 @@ again: base = 16, cp++; while ((c = *cp) != 0) { if (isdigit((unsigned char)c)) { - if (base == 8 && (c == '8' || c == '9')) + if (base == 8U && (c == '8' || c == '9')) return (INADDR_NONE); val = (val * base) + (c - '0'); cp++; digit = 1; continue; } - if (base == 16 && isxdigit((unsigned char)c)) { + if (base == 16U && isxdigit((unsigned char)c)) { val = (val << 4) + - (c + 10 - (islower((unsigned char)c) ? 'a' : 'A')); + (c + 10 - (islower((unsigned char)c) ? 'a' : 'A')); cp++; digit = 1; continue; @@ -103,15 +84,9 @@ again: } if (!digit) return (INADDR_NONE); -#ifdef ORIGINAL_ISC_CODE - if (*cp == '.') { - if (pp >= parts + 4 || val > 0xff) - return (INADDR_NONE); -#else - if (pp >= parts + 4 || val > 0xff) + if (pp >= parts + 4 || val > 0xffU) return (INADDR_NONE); if (*cp == '.') { -#endif *pp++ = val, cp++; goto again; } @@ -119,7 +94,7 @@ again: return (INADDR_NONE); *pp++ = val; n = pp - parts; - if (n > 4) + if (n > 4U) return (INADDR_NONE); for (val = 0, i = 0; i < n; i++) { val <<= 8; @@ -127,3 +102,5 @@ again: } return (val); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/inet/inet_ntoa.c b/usr/src/lib/libresolv2/common/inet/inet_ntoa.c index 7c838ac458..983121e89d 100644 --- a/usr/src/lib/libresolv2/common/inet/inet_ntoa.c +++ b/usr/src/lib/libresolv2/common/inet/inet_ntoa.c @@ -1,9 +1,4 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. * @@ -36,11 +31,9 @@ * SUCH DAMAGE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)inet_ntoa.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: inet_ntoa.c,v 1.7 1999/05/14 18:16:55 vixie Exp $"; +static const char rcsid[] = "$Id: inet_ntoa.c,v 1.2 2005/04/27 04:56:21 sra Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -55,11 +48,10 @@ static const char rcsid[] = "$Id: inet_ntoa.c,v 1.7 1999/05/14 18:16:55 vixie Ex #include "port_after.h" -/* +/*% * Convert network-format internet address * to base 256 d.d.d.d representation. */ -#ifndef SUNW_LIBNSL /* We don't need this if linked with libnsl */ /*const*/ char * inet_ntoa(struct in_addr in) { static char ret[18]; @@ -68,4 +60,5 @@ inet_ntoa(struct in_addr in) { (void) inet_ntop(AF_INET, &in, ret, sizeof ret); return (ret); } -#endif /* SUNW_LIBNSL */ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/inet/inet_ntop.c b/usr/src/lib/libresolv2/common/inet/inet_ntop.c index c13d5e3fc6..114ca5d506 100644 --- a/usr/src/lib/libresolv2/common/inet/inet_ntop.c +++ b/usr/src/lib/libresolv2/common/inet/inet_ntop.c @@ -1,28 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* Copyright (c) 1996-1999 by Internet Software Consortium. + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_ntop.c,v 1.11 2001/09/27 15:12:57 marka Exp $"; +static const char rcsid[] = "$Id: inet_ntop.c,v 1.5 2005/11/03 22:59:52 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -47,7 +41,7 @@ static const char rcsid[] = "$Id: inet_ntop.c,v 1.11 2001/09/27 15:12:57 marka E # define SPRINTF(x) ((size_t)sprintf x) #endif -/* +/*% * WARNING: Don't even consider trying to compile this on a system where * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. */ @@ -55,8 +49,6 @@ static const char rcsid[] = "$Id: inet_ntop.c,v 1.11 2001/09/27 15:12:57 marka E static const char *inet_ntop4 __P((const u_char *src, char *dst, size_t size)); static const char *inet_ntop6 __P((const u_char *src, char *dst, size_t size)); -#ifndef SUNW_LIBNSL /* We don't need this if linked with libnsl */ - /* char * * inet_ntop(af, src, dst, size) * convert a network format address to presentation format. @@ -145,7 +137,9 @@ inet_ntop6(src, dst, size) for (i = 0; i < NS_IN6ADDRSZ; i++) words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); best.base = -1; + best.len = 0; cur.base = -1; + cur.len = 0; for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { if (words[i] == 0) { if (cur.base == -1) @@ -209,4 +203,5 @@ inet_ntop6(src, dst, size) strcpy(dst, tmp); return (dst); } -#endif /* SUNW_LIBNSL */ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/inet/inet_pton.c b/usr/src/lib/libresolv2/common/inet/inet_pton.c index 465d1ded01..2c516c798a 100644 --- a/usr/src/lib/libresolv2/common/inet/inet_pton.c +++ b/usr/src/lib/libresolv2/common/inet/inet_pton.c @@ -1,28 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* Copyright (c) 1996,1999 by Internet Software Consortium. + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: inet_pton.c,v 1.8 2001/07/16 03:22:24 marka Exp $"; +static const char rcsid[] = "$Id: inet_pton.c,v 1.5 2005/07/28 06:51:47 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -36,7 +30,7 @@ static const char rcsid[] = "$Id: inet_pton.c,v 1.8 2001/07/16 03:22:24 marka Ex #include <errno.h> #include "port_after.h" -/* +/*% * WARNING: Don't even consider trying to compile this on a system where * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. */ @@ -44,8 +38,6 @@ static const char rcsid[] = "$Id: inet_pton.c,v 1.8 2001/07/16 03:22:24 marka Ex static int inet_pton4 __P((const char *src, u_char *dst)); static int inet_pton6 __P((const char *src, u_char *dst)); -#ifndef SUNW_LIBNSL /* We don't need this if linked with libnsl */ - /* int * inet_pton(af, src, dst) * convert from presentation format (which usually means ASCII printable) @@ -149,7 +141,7 @@ inet_pton6(src, dst) xdigits_u[] = "0123456789ABCDEF"; u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; const char *xdigits, *curtok; - int ch, saw_xdigit; + int ch, seen_xdigits; u_int val; memset((tp = tmp), '\0', NS_IN6ADDRSZ); @@ -160,7 +152,7 @@ inet_pton6(src, dst) if (*++src != ':') return (0); curtok = src; - saw_xdigit = 0; + seen_xdigits = 0; val = 0; while ((ch = *src++) != '\0') { const char *pch; @@ -170,14 +162,13 @@ inet_pton6(src, dst) if (pch != NULL) { val <<= 4; val |= (pch - xdigits); - if (val > 0xffff) + if (++seen_xdigits > 4) return (0); - saw_xdigit = 1; continue; } if (ch == ':') { curtok = src; - if (!saw_xdigit) { + if (!seen_xdigits) { if (colonp) return (0); colonp = tp; @@ -189,19 +180,19 @@ inet_pton6(src, dst) return (0); *tp++ = (u_char) (val >> 8) & 0xff; *tp++ = (u_char) val & 0xff; - saw_xdigit = 0; + seen_xdigits = 0; val = 0; continue; } if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && inet_pton4(curtok, tp) > 0) { tp += NS_INADDRSZ; - saw_xdigit = 0; - break; /* '\0' was seen by inet_pton4(). */ + seen_xdigits = 0; + break; /*%< '\\0' was seen by inet_pton4(). */ } return (0); } - if (saw_xdigit) { + if (seen_xdigits) { if (tp + NS_INT16SZ > endp) return (0); *tp++ = (u_char) (val >> 8) & 0xff; @@ -228,4 +219,5 @@ inet_pton6(src, dst) memcpy(dst, tmp, NS_IN6ADDRSZ); return (1); } -#endif /* SUNW_LIBNSL */ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/inet/nsap_addr.c b/usr/src/lib/libresolv2/common/inet/nsap_addr.c index cab8508187..b6432e1e49 100644 --- a/usr/src/lib/libresolv2/common/inet/nsap_addr.c +++ b/usr/src/lib/libresolv2/common/inet/nsap_addr.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAI! - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANT! - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF TH! - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nsap_addr.c,v 8.12 2001/05/28 07:37:46 marka Exp $"; +static const char rcsid[] = "$Id: nsap_addr.c,v 1.5 2005/07/28 06:51:48 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -38,6 +31,7 @@ static const char rcsid[] = "$Id: nsap_addr.c,v 8.12 2001/05/28 07:37:46 marka E #include <ctype.h> #include <resolv.h> +#include <resolv_mt.h> #include "port_after.h" @@ -86,11 +80,7 @@ char * inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) { int nib; int i; -#ifdef SUNW_MT_RESOLVER - char *tmpbuf = inet_nsap_ntoa_tmpbuf; -#else - static char tmpbuf[2+255*3]; -#endif /* SUNW_MT_RESOLVER */ + char *tmpbuf = inet_nsap_ntoa_tmpbuf; char *start; if (ascii) @@ -117,3 +107,5 @@ inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) { *ascii = '\0'; return (start); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/dns.c b/usr/src/lib/libresolv2/common/irs/dns.c index 30feb1b882..cbea94680e 100644 --- a/usr/src/lib/libresolv2/common/irs/dns.c +++ b/usr/src/lib/libresolv2/common/irs/dns.c @@ -1,32 +1,26 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: dns.c,v 1.16 2001/05/29 05:48:26 marka Exp $"; +static const char rcsid[] = "$Id: dns.c,v 1.5 2006/03/09 23:57:56 marka Exp $"; #endif -/* +/*! \file + * \brief * dns.c --- this is the top-level accessor function for the dns */ @@ -121,11 +115,11 @@ dns_res_get(struct irs_acc *this) { res = (struct __res_state *)malloc(sizeof *res); if (res == NULL) return (NULL); - memset(dns->res, 0, sizeof *dns->res); + memset(res, 0, sizeof *res); dns_res_set(this, res, free); } - if ((dns->res->options & RES_INIT) == 0 && + if ((dns->res->options & RES_INIT) == 0U && res_ninit(dns->res) < 0) return (NULL); diff --git a/usr/src/lib/libresolv2/common/irs/dns_gr.c b/usr/src/lib/libresolv2/common/irs/dns_gr.c index 92da69b8c5..629d2fb173 100644 --- a/usr/src/lib/libresolv2/common/irs/dns_gr.c +++ b/usr/src/lib/libresolv2/common/irs/dns_gr.c @@ -1,33 +1,26 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: dns_gr.c,v 1.21 2002/07/08 06:26:09 marka Exp $"; +static const char rcsid[] = "$Id: dns_gr.c,v 1.4 2005/04/27 04:56:21 sra Exp $"; #endif -/* +/*! \file + * \brief * dns_gr.c --- this file contains the functions for accessing * group information from Hesiod. */ @@ -77,7 +70,7 @@ struct pvt { * we keep one buffer and resize it as needed. */ struct group group; - size_t nmemb; /* Malloc'd max index of gr_mem[]. */ + size_t nmemb; /*%< Malloc'd max index of gr_mem[]. */ char * membuf; size_t membufsize; }; diff --git a/usr/src/lib/libresolv2/common/irs/dns_ho.c b/usr/src/lib/libresolv2/common/irs/dns_ho.c index 8de5b5028f..d279b685a1 100644 --- a/usr/src/lib/libresolv2/common/irs/dns_ho.c +++ b/usr/src/lib/libresolv2/common/irs/dns_ho.c @@ -1,12 +1,24 @@ /* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. + * Portions Copyright (C) 2004-2006, 2008 Internet Systems Consortium, Inc. ("ISC") + * Portions Copyright (C) 1996-2003 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ /* * Copyright (c) 1985, 1988, 1993 * The Regents of the University of California. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -22,7 +34,7 @@ * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -36,28 +48,11 @@ * SUCH DAMAGE. */ -/* - * Portions Copyright (c) 1996-1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - /* from gethostnamadr.c 8.1 (Berkeley) 6/4/93 */ /* BIND Id: gethnamaddr.c,v 8.15 1996/05/22 04:56:30 vixie Exp $ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: dns_ho.c,v 1.43 2003/05/27 23:36:52 marka Exp $"; +static const char rcsid[] = "$Id: dns_ho.c,v 1.23 2008/11/14 02:36:51 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports. */ @@ -100,8 +95,7 @@ static const char rcsid[] = "$Id: dns_ho.c,v 1.43 2003/05/27 23:36:52 marka Exp #define MAXALIASES 35 #define MAXADDRS 35 -#define MAXPACKET (65535) /* Maximum TCP message size */ - +#define MAXPACKET (65535) /*%< Maximum TCP message size */ #define BOUNDS_CHECK(ptr, count) \ if ((ptr) + (count) > eom) { \ had_error++; \ @@ -115,14 +109,14 @@ typedef union { struct dns_res_target { struct dns_res_target *next; - querybuf qbuf; /* query buffer */ - u_char *answer; /* buffer to put answer */ - int anslen; /* size of answer buffer */ - int qclass, qtype; /* class and type of query */ - int action; /* condition whether query is really issued */ - char qname[MAXDNAME +1]; /* domain name */ + querybuf qbuf; /*%< query buffer */ + u_char *answer; /*%< buffer to put answer */ + int anslen; /*%< size of answer buffer */ + int qclass, qtype; /*%< class and type of query */ + int action; /*%< condition whether query is really issued */ + char qname[MAXDNAME +1]; /*%< domain name */ #if 0 - int n; /* result length */ + int n; /*%< result length */ #endif }; enum {RESTGT_DOALWAYS, RESTGT_AFTERFAILURE, RESTGT_IGNORE}; @@ -133,7 +127,7 @@ struct pvt { char * h_addr_ptrs[MAXADDRS + 1]; char * host_aliases[MAXALIASES]; char hostbuf[8*1024]; - u_char host_addr[16]; /* IPv4 or IPv6 */ + u_char host_addr[16]; /*%< IPv4 or IPv6 */ struct __res_state *res; void (*free_res)(void *); }; @@ -146,8 +140,7 @@ typedef union { static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff }; static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 }; /* Note: the IPv6 loopback address is in the "tunnel" space */ -static const u_char v6local[] = { 0,0, 0,1 }; /* last 4 bytes of IPv6 addr */ - +static const u_char v6local[] = { 0,0, 0,1 }; /*%< last 4 bytes of IPv6 addr */ /* Forwards. */ static void ho_close(struct irs_ho *this); @@ -223,8 +216,7 @@ ho_close(struct irs_ho *this) { ho_minimize(this); if (pvt->res && pvt->free_res) (*pvt->free_res)(pvt->res); - if (pvt) - memput(pvt, sizeof *pvt); + memput(pvt, sizeof *pvt); memput(this, sizeof *this); } @@ -265,7 +257,7 @@ ho_byname2(struct irs_ho *this, const char *name, int af) errno = ENOMEM; goto cleanup; } - memset(q, 0, sizeof(q)); + memset(q, 0, sizeof(*q)); switch (af) { case AF_INET: @@ -323,8 +315,7 @@ ho_byname2(struct irs_ho *this, const char *name, int af) if ((hp = gethostans(this, p->answer, n, name, p->qtype, af, size, NULL, (const struct addrinfo *)&ai)) != NULL) - goto cleanup; /* no more loop is necessary */ - + goto cleanup; /*%< no more loop is necessary */ querystate = RESQRY_FAIL; continue; } @@ -346,7 +337,7 @@ ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) struct dns_res_target *q, *q2, *p; int n, size, i; int querystate = RESQRY_FAIL; - + if (init(this) == -1) return (NULL); @@ -357,13 +348,13 @@ ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) errno = ENOMEM; goto cleanup; } - memset(q, 0, sizeof(q)); - memset(q2, 0, sizeof(q2)); + memset(q, 0, sizeof(*q)); + memset(q2, 0, sizeof(*q2)); if (af == AF_INET6 && len == IN6ADDRSZ && (!memcmp(uaddr, mapped, sizeof mapped) || - (!memcmp(uaddr, tunnelled, sizeof tunnelled) && - memcmp(&uaddr[sizeof tunnelled], v6local, sizeof(v6local))))) { + (!memcmp(uaddr, tunnelled, sizeof tunnelled) && + memcmp(&uaddr[sizeof tunnelled], v6local, sizeof(v6local))))) { /* Unmap. */ addr = (const char *)addr + sizeof mapped; uaddr += sizeof mapped; @@ -391,7 +382,7 @@ ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) q2->qtype = T_PTR; q2->answer = q2->qbuf.buf; q2->anslen = sizeof(q2->qbuf); - if ((pvt->res->options & RES_NO_NIBBLE2) != 0) + if ((pvt->res->options & RES_NO_NIBBLE2) != 0U) q2->action = RESTGT_IGNORE; else q2->action = RESTGT_AFTERFAILURE; @@ -419,38 +410,44 @@ ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) break; case AF_INET6: if (q->action != RESTGT_IGNORE) { + const char *nibsuff = res_get_nibblesuffix(pvt->res); qp = q->qname; for (n = IN6ADDRSZ - 1; n >= 0; n--) { i = SPRINTF((qp, "%x.%x.", uaddr[n] & 0xf, (uaddr[n] >> 4) & 0xf)); - if (i < 0) + if (i != 4) abort(); qp += i; } -#ifdef HAVE_STRLCAT - strlcat(q->qname, res_get_nibblesuffix(pvt->res), - sizeof(q->qname)); -#else - strcpy(qp, res_get_nibblesuffix(pvt->res)); -#endif + if (strlen(q->qname) + strlen(nibsuff) + 1 > + sizeof q->qname) { + errno = ENAMETOOLONG; + RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL); + hp = NULL; + goto cleanup; + } + strcpy(qp, nibsuff); /* (checked) */ } if (q2->action != RESTGT_IGNORE) { + const char *nibsuff2 = res_get_nibblesuffix2(pvt->res); qp = q2->qname; for (n = IN6ADDRSZ - 1; n >= 0; n--) { i = SPRINTF((qp, "%x.%x.", uaddr[n] & 0xf, (uaddr[n] >> 4) & 0xf)); - if (i < 0) + if (i != 4) abort(); qp += i; } -#ifdef HAVE_STRLCAT - strlcat(q->qname, res_get_nibblesuffix2(pvt->res), - sizeof(q->qname)); -#else - strcpy(qp, res_get_nibblesuffix2(pvt->res)); -#endif + if (strlen(q2->qname) + strlen(nibsuff2) + 1 > + sizeof q2->qname) { + errno = ENAMETOOLONG; + RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL); + hp = NULL; + goto cleanup; + } + strcpy(qp, nibsuff2); /* (checked) */ } break; default: @@ -483,7 +480,7 @@ ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) querystate = RESQRY_FAIL; continue; } - + memcpy(pvt->host_addr, addr, len); pvt->h_addr_ptrs[0] = (char *)pvt->host_addr; pvt->h_addr_ptrs[1] = NULL; @@ -495,10 +492,9 @@ ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) } RES_SET_H_ERRNO(pvt->res, NETDB_SUCCESS); - goto cleanup; /* no more loop is necessary. */ + goto cleanup; /*%< no more loop is necessary. */ } - hp = NULL; /* H_ERRNO was set by subroutines */ - + hp = NULL; /*%< H_ERRNO was set by subroutines */ cleanup: if (q != NULL) memput(q, sizeof(*q)); @@ -577,8 +573,8 @@ ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) errno = ENOMEM; goto cleanup; } - memset(q, 0, sizeof(q2)); - memset(q2, 0, sizeof(q2)); + memset(q, 0, sizeof(*q2)); + memset(q2, 0, sizeof(*q2)); switch (pai->ai_family) { case AF_UNSPEC: @@ -610,7 +606,7 @@ ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) q->action = RESTGT_DOALWAYS; break; default: - RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); /* better error? */ + RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); /*%< better error? */ goto cleanup; } @@ -643,15 +639,14 @@ ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) continue; } (void)gethostans(this, p->answer, n, name, p->qtype, - pai->ai_family, /* XXX: meaningless */ + pai->ai_family, /*%< XXX: meaningless */ 0, &ai, pai); if (ai) { querystate = RESQRY_SUCCESS; cur->ai_next = ai; - while (cur && cur->ai_next) + while (cur->ai_next) cur = cur->ai_next; - } - else + } else querystate = RESQRY_FAIL; } @@ -682,12 +677,12 @@ ho_res_set(struct irs_ho *this, struct __res_state *res, static struct hostent * gethostans(struct irs_ho *this, const u_char *ansbuf, int anslen, const char *qname, int qtype, - int af, int size, /* meaningless for addrinfo cases */ + int af, int size, /*!< meaningless for addrinfo cases */ struct addrinfo **ret_aip, const struct addrinfo *pai) { struct pvt *pvt = (struct pvt *)this->private; int type, class, ancount, qdcount, n, haveanswer, had_error; - int error = NETDB_SUCCESS, arcount; + int error = NETDB_SUCCESS; int (*name_ok)(const char *); const HEADER *hp; const u_char *eom; @@ -710,7 +705,7 @@ gethostans(struct irs_ho *this, switch (qtype) { case T_A: case T_AAAA: - case T_ANY: /* use T_ANY only for T_A/T_AAAA lookup */ + case T_ANY: /*%< use T_ANY only for T_A/T_AAAA lookup */ name_ok = res_hnok; break; case T_PTR: @@ -734,7 +729,6 @@ gethostans(struct irs_ho *this, hp = (const HEADER *)ansbuf; ancount = ntohs(hp->ancount); qdcount = ntohs(hp->qdcount); - arcount = ntohs(hp->arcount); bp = pvt->hostbuf; ep = pvt->hostbuf + sizeof(pvt->hostbuf); cp = ansbuf + HFIXEDSZ; @@ -757,7 +751,7 @@ gethostans(struct irs_ho *this, * same as the one we sent; this just gets the expanded name * (i.e., with the succeeding search-domain tacked on). */ - n = strlen(bp) + 1; /* for the \0 */ + n = strlen(bp) + 1; /*%< for the \\0 */ if (n > MAXHOSTNAMELEN) { RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); return (NULL); @@ -782,14 +776,14 @@ gethostans(struct irs_ho *this, had_error++; continue; } - cp += n; /* name */ + cp += n; /*%< name */ BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ); type = ns_get16(cp); - cp += INT16SZ; /* type */ + cp += INT16SZ; /*%< type */ class = ns_get16(cp); - cp += INT16SZ + INT32SZ; /* class, TTL */ + cp += INT16SZ + INT32SZ; /*%< class, TTL */ n = ns_get16(cp); - cp += INT16SZ; /* len */ + cp += INT16SZ; /*%< len */ BOUNDS_CHECK(cp, n); if (class != C_IN) { cp += n; @@ -817,19 +811,15 @@ gethostans(struct irs_ho *this, if (ap >= &pvt->host_aliases[MAXALIASES-1]) continue; *ap++ = bp; - n = strlen(bp) + 1; /* for the \0 */ + n = strlen(bp) + 1; /*%< for the \\0 */ bp += n; /* Get canonical name. */ - n = strlen(tbuf) + 1; /* for the \0 */ + n = strlen(tbuf) + 1; /*%< for the \\0 */ if (n > (ep - bp) || n > MAXHOSTNAMELEN) { had_error++; continue; } -#ifdef HAVE_STRLCPY - strlcpy(bp, tbuf, ep - bp); -#else - strcpy(bp, tbuf); -#endif + strcpy(bp, tbuf); /* (checked) */ pvt->host.h_name = bp; hname = bp; bp += n; @@ -843,7 +833,7 @@ gethostans(struct irs_ho *this, } cp += n; #ifdef RES_USE_DNAME - if ((pvt->res->options & RES_USE_DNAME) != 0) + if ((pvt->res->options & RES_USE_DNAME) != 0U) #endif { /* @@ -856,16 +846,12 @@ gethostans(struct irs_ho *this, continue; } /* Get canonical name. */ - n = strlen(tbuf) + 1; /* for the \0 */ + n = strlen(tbuf) + 1; /*%< for the \\0 */ if (n > (ep - bp)) { had_error++; continue; } -#ifdef HAVE_STRLCPY - strlcpy(bp, tbuf, ep - bp); -#else - strcpy(bp, tbuf); -#endif + strcpy(bp, tbuf); /* (checked) */ tname = bp; bp += n; continue; @@ -906,7 +892,7 @@ gethostans(struct irs_ho *this, else n = -1; if (n != -1) { - n = strlen(bp) + 1; /* for the \0 */ + n = strlen(bp) + 1; /*%< for the \\0 */ bp += n; } break; @@ -937,7 +923,7 @@ gethostans(struct irs_ho *this, if (!haveanswer) { int nn; - nn = strlen(bp) + 1; /* for the \0 */ + nn = strlen(bp) + 1; /*%< for the \\0 */ if (nn >= MAXHOSTNAMELEN) { cp += n; had_error++; @@ -951,14 +937,14 @@ gethostans(struct irs_ho *this, bp = (char *)(((u_long)bp + (sizeof(align) - 1)) & ~(sizeof(align) - 1)); /* Avoid overflows. */ - if (bp + n >= &pvt->hostbuf[sizeof pvt->hostbuf]) { + if (bp + n > &pvt->hostbuf[sizeof(pvt->hostbuf) - 1]) { had_error++; continue; } - if (ret_aip) { /* need addrinfo. keep it. */ - while (cur && cur->ai_next) + if (ret_aip) { /*%< need addrinfo. keep it. */ + while (cur->ai_next) cur = cur->ai_next; - } else if (cur->ai_next) { /* need hostent */ + } else if (cur->ai_next) { /*%< need hostent */ struct addrinfo *aip = cur->ai_next; for (aip = cur->ai_next; aip; @@ -999,14 +985,10 @@ gethostans(struct irs_ho *this, addrsort(pvt->res, pvt->h_addr_ptrs, hap - pvt->h_addr_ptrs); if (pvt->host.h_name == NULL) { - n = strlen(qname) + 1; /* for the \0 */ + n = strlen(qname) + 1; /*%< for the \\0 */ if (n > (ep - bp) || n >= MAXHOSTNAMELEN) goto no_recovery; -#ifdef HAVE_STRLCPY - strlcpy(bp, qname, ep - bp); -#else - strcpy(bp, qname); -#endif + strcpy(bp, qname); /* (checked) */ pvt->host.h_name = bp; bp += n; } @@ -1059,18 +1041,17 @@ add_hostent(struct pvt *pvt, char *bp, char **hap, struct addrinfo *ai) addrp = (char *)&((struct sockaddr_in *)ai->ai_addr)->sin_addr; break; default: - return(-1); /* abort? */ + return(-1); /*%< abort? */ } /* Ensure alignment. */ bp = (char *)(((u_long)bp + (sizeof(align) - 1)) & ~(sizeof(align) - 1)); /* Avoid overflows. */ - if (bp + addrlen >= &pvt->hostbuf[sizeof pvt->hostbuf]) + if (bp + addrlen > &pvt->hostbuf[sizeof(pvt->hostbuf) - 1]) return(-1); if (hap >= &pvt->h_addr_ptrs[MAXADDRS]) - return(0); /* fail, but not treat it as an error. */ - + return(0); /*%< fail, but not treat it as an error. */ /* Suppress duplicates. */ for (tap = (const char **)pvt->h_addr_ptrs; *tap != NULL; @@ -1118,7 +1099,7 @@ addrsort(res_state statp, char **ap, int num) { p = ap; for (i = 0; i < num; i++, p++) { for (j = 0 ; (unsigned)j < statp->nsort; j++) - if (statp->sort_list[j].addr.s_addr == + if (statp->sort_list[j].addr.s_addr == (((struct in_addr *)(*p))->s_addr & statp->sort_list[j].mask)) break; @@ -1152,10 +1133,10 @@ addrsort(res_state statp, char **ap, int num) { static int init(struct irs_ho *this) { struct pvt *pvt = (struct pvt *)this->private; - + if (!pvt->res && !ho_res_get(this)) return (-1); - if (((pvt->res->options & RES_INIT) == 0) && + if (((pvt->res->options & RES_INIT) == 0U) && res_ninit(pvt->res) == -1) return (-1); return (0); diff --git a/usr/src/lib/libresolv2/common/irs/dns_nw.c b/usr/src/lib/libresolv2/common/irs/dns_nw.c index bcae67480d..dc1e61739b 100644 --- a/usr/src/lib/libresolv2/common/irs/dns_nw.c +++ b/usr/src/lib/libresolv2/common/irs/dns_nw.c @@ -1,29 +1,22 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: dns_nw.c,v 1.25 2002/07/18 02:07:43 marka Exp $"; +static const char rcsid[] = "$Id: dns_nw.c,v 1.12 2005/04/27 04:56:22 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports. */ @@ -339,7 +332,7 @@ get1101answer(struct irs_nw *this, /* Prepare a return structure. */ bp = pvt->buf; - ep = pvt->buf + sizeof (pvt->buf); + ep = pvt->buf + sizeof(pvt->buf); pvt->net.n_name = NULL; pvt->net.n_aliases = pvt->ali; pvt->net.n_addrtype = af; @@ -356,12 +349,7 @@ get1101answer(struct irs_nw *this, RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); return (NULL); } -#ifdef HAVE_STRLCPY - strlcpy(bp, name, ep - bp); - pvt->net.n_name = bp; -#else - pvt->net.n_name = strcpy(bp, name); -#endif + pvt->net.n_name = strcpy(bp, name); /* (checked) */ bp += n; } break; @@ -389,16 +377,16 @@ get1101answer(struct irs_nw *this, while (--ancount >= 0 && cp < eom) { int n = dn_expand(ansbuf, eom, cp, bp, ep - bp); - cp += n; /* Owner */ + cp += n; /*%< Owner */ if (n < 0 || !maybe_dnok(pvt->res, bp) || cp + 3 * INT16SZ + INT32SZ > eom) { RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); return (NULL); } - GETSHORT(type, cp); /* Type */ - GETSHORT(class, cp); /* Class */ - cp += INT32SZ; /* TTL */ - GETSHORT(n, cp); /* RDLENGTH */ + GETSHORT(type, cp); /*%< Type */ + GETSHORT(class, cp); /*%< Class */ + cp += INT32SZ; /*%< TTL */ + GETSHORT(n, cp); /*%< RDLENGTH */ if (class == C_IN && type == T_PTR) { int nn; @@ -442,7 +430,7 @@ get1101answer(struct irs_nw *this, } } } - cp += n; /* RDATA */ + cp += n; /*%< RDATA */ } if (!haveanswer) { RES_SET_H_ERRNO(pvt->res, TRY_AGAIN); @@ -503,13 +491,13 @@ get1101mask(struct irs_nw *this, struct nwent *nwent) { if (n < 0 || !maybe_dnok(pvt->res, owner)) break; - cp += n; /* Owner */ + cp += n; /*%< Owner */ if (cp + 3 * INT16SZ + INT32SZ > eom) break; - GETSHORT(type, cp); /* Type */ - GETSHORT(class, cp); /* Class */ - cp += INT32SZ; /* TTL */ - GETSHORT(n, cp); /* RDLENGTH */ + GETSHORT(type, cp); /*%< Type */ + GETSHORT(class, cp); /*%< Class */ + cp += INT32SZ; /*%< TTL */ + GETSHORT(n, cp); /*%< RDLENGTH */ if (cp + n > eom) break; if (n == INADDRSZ && class == C_IN && type == T_A && @@ -525,7 +513,7 @@ get1101mask(struct irs_nw *this, struct nwent *nwent) { else break; } - cp += n; /* RDATA */ + cp += n; /*%< RDATA */ } memput(ansbuf, MAXPACKET); return (nwent); @@ -581,7 +569,7 @@ normalize_name(char *name) { /* Make lower case. */ for (t = name; *t; t++) if (isascii((unsigned char)*t) && isupper((unsigned char)*t)) - *t = tolower(*t); + *t = tolower((*t)&0xff); /* Remove trailing dots. */ while (t > name && t[-1] == '.') @@ -594,8 +582,10 @@ init(struct irs_nw *this) { if (!pvt->res && !nw_res_get(this)) return (-1); - if (((pvt->res->options & RES_INIT) == 0) && + if (((pvt->res->options & RES_INIT) == 0U) && res_ninit(pvt->res) == -1) return (-1); return (0); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/dns_p.h b/usr/src/lib/libresolv2/common/irs/dns_p.h index cc45a8e3fc..d85ae2a238 100644 --- a/usr/src/lib/libresolv2/common/irs/dns_p.h +++ b/usr/src/lib/libresolv2/common/irs/dns_p.h @@ -1,41 +1,33 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ - -#pragma ident "%Z%%M% %I% %E% SMI" - /* - * $Id: dns_p.h,v 1.11 1999/06/03 20:50:36 vixie Exp $ + * $Id: dns_p.h,v 1.4 2005/04/27 04:56:22 sra Exp $ */ #ifndef _DNS_P_H_INCLUDED #define _DNS_P_H_INCLUDED -#define maybe_ok(res, nm, ok) (((res)->options & RES_NOCHECKNAME) != 0 || \ +#define maybe_ok(res, nm, ok) (((res)->options & RES_NOCHECKNAME) != 0U || \ (ok)(nm) != 0) #define maybe_hnok(res, hn) maybe_ok((res), (hn), res_hnok) #define maybe_dnok(res, dn) maybe_ok((res), (dn), res_dnok) -/* +/*% * Object state. */ struct dns_p { @@ -56,3 +48,5 @@ extern struct irs_ho * irs_dns_ho __P((struct irs_acc *)); extern struct irs_nw * irs_dns_nw __P((struct irs_acc *)); #endif /*_DNS_P_H_INCLUDED*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/dns_pr.c b/usr/src/lib/libresolv2/common/irs/dns_pr.c index 10a574e0ea..137f306218 100644 --- a/usr/src/lib/libresolv2/common/irs/dns_pr.c +++ b/usr/src/lib/libresolv2/common/irs/dns_pr.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: dns_pr.c,v 1.15 2001/05/29 05:48:31 marka Exp $"; +static const char rcsid[] = "$Id: dns_pr.c,v 1.5 2005/04/27 04:56:22 sra Exp $"; #endif /* Imports */ @@ -271,3 +264,5 @@ parse_hes_list(struct irs_pr *this, char **hes_list) { } return (NULL); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/dns_pw.c b/usr/src/lib/libresolv2/common/irs/dns_pw.c index c40ef80e15..4ea97adfdb 100644 --- a/usr/src/lib/libresolv2/common/irs/dns_pw.c +++ b/usr/src/lib/libresolv2/common/irs/dns_pw.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: dns_pw.c,v 1.19 2001/05/29 05:48:32 marka Exp $"; +static const char rcsid[] = "$Id: dns_pw.c,v 1.3 2005/04/27 04:56:22 sra Exp $"; #endif #include "port_before.h" @@ -236,3 +229,4 @@ getpwcommon(struct irs_pw *this, const char *arg, const char *type) { } #endif /* WANT_IRS_PW */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/dns_sv.c b/usr/src/lib/libresolv2/common/irs/dns_sv.c index 6afeb5a56e..c3294255b8 100644 --- a/usr/src/lib/libresolv2/common/irs/dns_sv.c +++ b/usr/src/lib/libresolv2/common/irs/dns_sv.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: dns_sv.c,v 1.20 2001/05/29 05:48:33 marka Exp $"; +static const char rcsid[] = "$Id: dns_sv.c,v 1.5 2005/04/27 04:56:23 sra Exp $"; #endif /* Imports */ @@ -118,8 +111,8 @@ irs_dns_sv(struct irs_acc *this) { sv->res_get = sv_res_get; sv->res_set = sv_res_set; #else - sv->res_get = NULL; /* sv_res_get; */ - sv->res_set = NULL; /* sv_res_set; */ + sv->res_get = NULL; /*%< sv_res_get; */ + sv->res_set = NULL; /*%< sv_res_set; */ #endif return (sv); } @@ -303,3 +296,5 @@ sv_res_set(struct irs_sv *this, struct __res_state * res, __hesiod_res_set(dns->hes_ctx, res, free_res); } #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/gai_strerror.c b/usr/src/lib/libresolv2/common/irs/gai_strerror.c index a9e249b418..9ca1c4bfe1 100644 --- a/usr/src/lib/libresolv2/common/irs/gai_strerror.c +++ b/usr/src/lib/libresolv2/common/irs/gai_strerror.c @@ -1,27 +1,20 @@ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 2001 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <port_before.h> #include <netdb.h> #include <port_after.h> @@ -33,21 +26,20 @@ static const char *gai_errlist[] = { "no error", - "address family not supported for name",/* EAI_ADDRFAMILY */ - "temporary failure", /* EAI_AGAIN */ - "invalid flags", /* EAI_BADFLAGS */ - "permanent failure", /* EAI_FAIL */ - "address family not supported", /* EAI_FAMILY */ - "memory failure", /* EAI_MEMORY */ - "no address", /* EAI_NODATA */ - "unknown name or service", /* EAI_NONAME */ - "service not supported for socktype", /* EAI_SERVICE */ - "socktype not supported", /* EAI_SOCKTYPE */ - "system failure", /* EAI_SYSTEM */ - "bad hints", /* EAI_BADHINTS */ - "bad protocol", /* EAI_PROTOCOL */ - - "unknown error" /* Must be last. */ + "address family not supported for name",/*%< EAI_ADDRFAMILY */ + "temporary failure", /*%< EAI_AGAIN */ + "invalid flags", /*%< EAI_BADFLAGS */ + "permanent failure", /*%< EAI_FAIL */ + "address family not supported", /*%< EAI_FAMILY */ + "memory failure", /*%< EAI_MEMORY */ + "no address", /*%< EAI_NODATA */ + "unknown name or service", /*%< EAI_NONAME */ + "service not supported for socktype", /*%< EAI_SERVICE */ + "socktype not supported", /*%< EAI_SOCKTYPE */ + "system failure", /*%< EAI_SYSTEM */ + "bad hints", /*%< EAI_BADHINTS */ + "bad protocol", /*%< EAI_PROTOCOL */ + "unknown error" /*%< Must be last. */ }; static const int gai_nerr = (sizeof(gai_errlist)/sizeof(*gai_errlist)); @@ -59,7 +51,12 @@ gai_strerror(int ecode) { #ifndef DO_PTHREADS static char buf[EAI_BUFSIZE]; #else /* DO_PTHREADS */ - static pthread_key_t key = PTHREAD_ONCE_KEY_NP; +#ifndef LIBBIND_MUTEX_INITIALIZER +#define LIBBIND_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER +#endif + static pthread_mutex_t lock = LIBBIND_MUTEX_INITIALIZER; + static pthread_key_t key; + static int once = 0; char *buf; #endif @@ -67,18 +64,30 @@ gai_strerror(int ecode) { return (gai_errlist[ecode]); #ifdef DO_PTHREADS - if (pthread_key_create_once_np(&key, free) != 0) - goto unknown; + if (!once) { + if (pthread_mutex_lock(&lock) != 0) + goto unknown; + if (!once) { + if (pthread_key_create(&key, free) != 0) { + (void)pthread_mutex_unlock(&lock); + goto unknown; + } + once = 1; + } + if (pthread_mutex_unlock(&lock) != 0) + goto unknown; + } + buf = pthread_getspecific(key); - if (buf == NULL) { + if (buf == NULL) { buf = malloc(EAI_BUFSIZE); - if (buf == NULL) - goto unknown; - if (pthread_setspecific(key, buf) != 0) { + if (buf == NULL) + goto unknown; + if (pthread_setspecific(key, buf) != 0) { free(buf); goto unknown; } - } + } #endif /* * XXX This really should be snprintf(buf, EAI_BUFSIZE, ...). @@ -87,8 +96,10 @@ gai_strerror(int ecode) { sprintf(buf, "%s: %d", gai_errlist[gai_nerr - 1], ecode); return (buf); -#ifdef DO_PTHREADS -unknown: +#ifdef DO_PTHREADS + unknown: return ("unknown error"); #endif } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/gen.c b/usr/src/lib/libresolv2/common/irs/gen.c index 10acc388f1..2bc125448b 100644 --- a/usr/src/lib/libresolv2/common/irs/gen.c +++ b/usr/src/lib/libresolv2/common/irs/gen.c @@ -1,32 +1,32 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ + /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: gen.c,v 1.26 2001/05/29 05:48:35 marka Exp $"; +static const char rcsid[] = "$Id: gen.c,v 1.7 2005/04/27 04:56:23 sra Exp $"; #endif -/* +/*! \file + * \brief * this is the top level dispatcher * * The dispatcher is implemented as an accessor class; it is an @@ -186,7 +186,7 @@ gen_res_get(struct irs_acc *this) { gen_res_set(this, res, free); } - if (((irs->res->options & RES_INIT) == 0) && res_ninit(irs->res) < 0) + if (((irs->res->options & RES_INIT) == 0U) && res_ninit(irs->res) < 0) return (NULL); return (irs->res); @@ -418,8 +418,10 @@ init_map_rules(struct gen_p *irs, const char *conf_file) { default_map_rules(irs); return; } - (void) sprintf(pattern, "%%%ds %%%ds %%%ds\n", - sizeof mapname, sizeof accname, sizeof options); + (void) sprintf(pattern, "%%%lus %%%lus %%%lus\n", + (unsigned long)sizeof mapname, + (unsigned long)sizeof accname, + (unsigned long)sizeof options); while (fgets(line, sizeof line, conf)) { enum irs_map_id map; enum irs_acc_id acc; diff --git a/usr/src/lib/libresolv2/common/irs/gen_gr.c b/usr/src/lib/libresolv2/common/irs/gen_gr.c index 1caf7a22c5..d689e19319 100644 --- a/usr/src/lib/libresolv2/common/irs/gen_gr.c +++ b/usr/src/lib/libresolv2/common/irs/gen_gr.c @@ -1,29 +1,22 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: gen_gr.c,v 1.26 2002/07/18 02:07:44 marka Exp $"; +static const char rcsid[] = "$Id: gen_gr.c,v 1.8 2005/04/27 04:56:23 sra Exp $"; #endif /* Imports */ @@ -68,7 +61,7 @@ struct pvt { * we keep one buffer and resize it as needed. */ struct group group; - size_t nmemb; /* Malloc'd max index of gr_mem[]. */ + size_t nmemb; /*%< Malloc'd max index of gr_mem[]. */ char * membuf; size_t membufsize; struct __res_state * res; @@ -90,7 +83,7 @@ static void gr_res_set(struct irs_gr *, struct __res_state *, void (*)(void *)); -static void grmerge(struct irs_gr *gr, const struct group *src, +static int grmerge(struct irs_gr *gr, const struct group *src, int preserve); static int countvec(char **vec); @@ -99,6 +92,10 @@ static int countnew(char **old, char **new); static size_t sizenew(char **old, char **new); static int newgid(int, gid_t *, gid_t); +/* Macros */ + +#define FREE_IF(x) do { if ((x) != NULL) { free(x); (x) = NULL; } } while (0) + /* Public */ struct irs_gr * @@ -178,7 +175,8 @@ gr_byname(struct irs_gr *this, const char *name) { gr = rule->inst->gr; tval = (*gr->byname)(gr, name); if (tval) { - grmerge(this, tval, dirty++); + if (!grmerge(this, tval, dirty++)) + return (NULL); if (!(rule->flags & IRS_MERGE)) break; } else { @@ -204,7 +202,8 @@ gr_bygid(struct irs_gr *this, gid_t gid) { gr = rule->inst->gr; tval = (*gr->bygid)(gr, gid); if (tval) { - grmerge(this, tval, dirty++); + if (!grmerge(this, tval, dirty++)) + return (NULL); if (!(rule->flags & IRS_MERGE)) break; } else { @@ -328,7 +327,7 @@ gr_res_set(struct irs_gr *this, struct __res_state *res, /* Private. */ -static void +static int grmerge(struct irs_gr *this, const struct group *src, int preserve) { struct pvt *pvt = (struct pvt *)this->private; char *cp, **m, **p, *oldmembuf, *ep; @@ -339,9 +338,9 @@ grmerge(struct irs_gr *this, const struct group *src, int preserve) { pvt->group.gr_gid = src->gr_gid; if (pvt->nmemb < 1) { m = malloc(sizeof *m); - if (!m) { + if (m == NULL) { /* No harm done, no work done. */ - return; + return (0); } pvt->group.gr_mem = m; pvt->nmemb = 1; @@ -358,9 +357,9 @@ grmerge(struct irs_gr *this, const struct group *src, int preserve) { n = ndst + nnew + 1; if ((size_t)n > pvt->nmemb) { m = realloc(pvt->group.gr_mem, n * sizeof *m); - if (!m) { + if (m == NULL) { /* No harm done, no work done. */ - return; + return (0); } pvt->group.gr_mem = m; pvt->nmemb = n; @@ -378,13 +377,13 @@ grmerge(struct irs_gr *this, const struct group *src, int preserve) { } if (n == 0) { /* No work to do. */ - return; + return (1); } used = preserve ? pvt->membufsize : 0; cp = malloc(used + n); - if (!cp) { + if (cp == NULL) { /* No harm done, no work done. */ - return; + return (0); } ep = cp + used + n; if (used != 0) @@ -408,12 +407,13 @@ grmerge(struct irs_gr *this, const struct group *src, int preserve) { if (isnew(pvt->group.gr_mem, *m)) { *p++ = cp; *p = NULL; -#ifdef HAVE_STRLCPY - strlcpy(cp, *m, ep - cp); -#else - strcpy(cp, *m); -#endif - cp += strlen(cp) + 1; + n = strlen(*m) + 1; + if (n > ep - cp) { + FREE_IF(oldmembuf); + return (0); + } + strcpy(cp, *m); /* (checked) */ + cp += n; } if (preserve) { pvt->group.gr_name = pvt->membuf + @@ -422,23 +422,26 @@ grmerge(struct irs_gr *this, const struct group *src, int preserve) { (pvt->group.gr_passwd - oldmembuf); } else { pvt->group.gr_name = cp; -#ifdef HAVE_STRLCPY - strlcpy(cp, src->gr_name, ep - cp); -#else - strcpy(cp, src->gr_name); -#endif - cp += strlen(src->gr_name) + 1; + n = strlen(src->gr_name) + 1; + if (n > ep - cp) { + FREE_IF(oldmembuf); + return (0); + } + strcpy(cp, src->gr_name); /* (checked) */ + cp += n; + pvt->group.gr_passwd = cp; -#ifdef HAVE_STRLCPY - strlcpy(cp, src->gr_passwd, ep - cp); -#else - strcpy(cp, src->gr_passwd); -#endif - cp += strlen(src->gr_passwd) + 1; + n = strlen(src->gr_passwd) + 1; + if (n > ep - cp) { + FREE_IF(oldmembuf); + return (0); + } + strcpy(cp, src->gr_passwd); /* (checked) */ + cp += n; } - if (oldmembuf != NULL) - free(oldmembuf); + FREE_IF(oldmembuf); INSIST(cp >= pvt->membuf && cp <= &pvt->membuf[pvt->membufsize]); + return (1); } static int @@ -487,3 +490,4 @@ newgid(int ngroups, gid_t *groups, gid_t group) { } #endif /* WANT_IRS_GR */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/gen_ho.c b/usr/src/lib/libresolv2/common/irs/gen_ho.c index 529738d8be..d38ea26b86 100644 --- a/usr/src/lib/libresolv2/common/irs/gen_ho.c +++ b/usr/src/lib/libresolv2/common/irs/gen_ho.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: gen_ho.c,v 1.16 2001/05/29 05:48:36 marka Exp $"; +static const char rcsid[] = "$Id: gen_ho.c,v 1.5 2006/03/09 23:57:56 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports */ @@ -355,7 +348,7 @@ ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) ho = rule->inst->ho; RES_SET_H_ERRNO(pvt->res, NETDB_INTERNAL); errno = 0; - if (ho->addrinfo == NULL) /* for safety */ + if (ho->addrinfo == NULL) /*%< for safety */ continue; rval = (*ho->addrinfo)(ho, name, pai); if (rval != NULL) @@ -378,8 +371,6 @@ ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) } if (softerror != 0 && pvt->res->res_h_errno == HOST_NOT_FOUND) RES_SET_H_ERRNO(pvt->res, therrno); - if (rval) - freeaddrinfo(rval); return (NULL); } @@ -390,9 +381,11 @@ init(struct irs_ho *this) { if (!pvt->res && !ho_res_get(this)) return (-1); - if (((pvt->res->options & RES_INIT) == 0) && + if (((pvt->res->options & RES_INIT) == 0U) && (res_ninit(pvt->res) == -1)) return (-1); return (0); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/gen_ng.c b/usr/src/lib/libresolv2/common/irs/gen_ng.c index c628193868..c617c7c9f5 100644 --- a/usr/src/lib/libresolv2/common/irs/gen_ng.c +++ b/usr/src/lib/libresolv2/common/irs/gen_ng.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: gen_ng.c,v 1.15 2001/05/29 05:48:38 marka Exp $"; +static const char rcsid[] = "$Id: gen_ng.c,v 1.3 2005/04/27 04:56:23 sra Exp $"; #endif /* Imports */ @@ -177,3 +170,5 @@ ng_minimize(struct irs_ng *this) { (*ng->minimize)(ng); } } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/gen_nw.c b/usr/src/lib/libresolv2/common/irs/gen_nw.c index 9fbb91a7bd..480a435478 100644 --- a/usr/src/lib/libresolv2/common/irs/gen_nw.c +++ b/usr/src/lib/libresolv2/common/irs/gen_nw.c @@ -1,29 +1,22 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: gen_nw.c,v 1.13 1999/10/13 16:39:29 vixie Exp $"; +static const char rcsid[] = "$Id: gen_nw.c,v 1.4 2005/04/27 04:56:23 sra Exp $"; #endif /* Imports */ @@ -262,8 +255,10 @@ init(struct irs_nw *this) { if (!pvt->res && !nw_res_get(this)) return (-1); - if (((pvt->res->options & RES_INIT) == 0) && + if (((pvt->res->options & RES_INIT) == 0U) && res_ninit(pvt->res) == -1) return (-1); return (0); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/gen_p.h b/usr/src/lib/libresolv2/common/irs/gen_p.h index f07d02b8fc..1adc5909bb 100644 --- a/usr/src/lib/libresolv2/common/irs/gen_p.h +++ b/usr/src/lib/libresolv2/common/irs/gen_p.h @@ -1,32 +1,26 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* - * $Id: gen_p.h,v 1.11 2001/05/29 05:48:39 marka Exp $ + * $Id: gen_p.h,v 1.3 2005/04/27 04:56:23 sra Exp $ */ -/* Notes: +/*! \file + * Notes: * We hope to create a complete set of thread-safe entry points someday, * which will mean a set of getXbyY() functions that take as an argument * a pointer to the map class, which will have a pointer to the private @@ -43,32 +37,32 @@ #ifndef _GEN_P_H_INCLUDED #define _GEN_P_H_INCLUDED -/* +/*% * These are the access methods. */ enum irs_acc_id { - irs_lcl, /* Local. */ - irs_dns, /* DNS or Hesiod. */ - irs_nis, /* Sun NIS ("YP"). */ - irs_irp, /* IR protocol. */ + irs_lcl, /*%< Local. */ + irs_dns, /*%< DNS or Hesiod. */ + irs_nis, /*%< Sun NIS ("YP"). */ + irs_irp, /*%< IR protocol. */ irs_nacc }; -/* +/*% * These are the map types. */ enum irs_map_id { - irs_gr, /* "group" */ - irs_pw, /* "passwd" */ - irs_sv, /* "services" */ - irs_pr, /* "protocols" */ - irs_ho, /* "hosts" */ - irs_nw, /* "networks" */ - irs_ng, /* "netgroup" */ + irs_gr, /*%< "group" */ + irs_pw, /*%< "passwd" */ + irs_sv, /*%< "services" */ + irs_pr, /*%< "protocols" */ + irs_ho, /*%< "hosts" */ + irs_nw, /*%< "networks" */ + irs_ng, /*%< "netgroup" */ irs_nmap }; -/* +/*% * This is an accessor instance. */ struct irs_inst { @@ -82,7 +76,7 @@ struct irs_inst { struct irs_ng * ng; }; -/* +/*% * This is a search rule for some map type. */ struct irs_rule { @@ -90,9 +84,8 @@ struct irs_rule { struct irs_inst * inst; int flags; }; -#define IRS_MERGE 0x0001 /* Don't stop if acc. has data? */ -#define IRS_CONTINUE 0x0002 /* Don't stop if acc. has no data? */ - +#define IRS_MERGE 0x0001 /*%< Don't stop if acc. has data? */ +#define IRS_CONTINUE 0x0002 /*%< Don't stop if acc. has no data? */ /* * This is the private data for a search access class. */ diff --git a/usr/src/lib/libresolv2/common/irs/gen_pr.c b/usr/src/lib/libresolv2/common/irs/gen_pr.c index eefffa75bf..93c0426c78 100644 --- a/usr/src/lib/libresolv2/common/irs/gen_pr.c +++ b/usr/src/lib/libresolv2/common/irs/gen_pr.c @@ -1,29 +1,22 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: gen_pr.c,v 1.12 1999/10/13 16:39:30 vixie Exp $"; +static const char rcsid[] = "$Id: gen_pr.c,v 1.3 2005/04/27 04:56:24 sra Exp $"; #endif /* Imports */ @@ -231,3 +224,5 @@ pr_res_set(struct irs_pr *this, struct __res_state *res, (*pr->res_set)(pr, pvt->res, NULL); } } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/gen_pw.c b/usr/src/lib/libresolv2/common/irs/gen_pw.c index 82d0452a12..512b011518 100644 --- a/usr/src/lib/libresolv2/common/irs/gen_pw.c +++ b/usr/src/lib/libresolv2/common/irs/gen_pw.c @@ -1,29 +1,22 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: gen_pw.c,v 1.14 1999/10/13 16:39:30 vixie Exp $"; +static const char rcsid[] = "$Id: gen_pw.c,v 1.3 2005/04/27 04:56:24 sra Exp $"; #endif /* Imports */ @@ -238,3 +231,4 @@ pw_res_set(struct irs_pw *this, struct __res_state *res, } #endif /* WANT_IRS_PW */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/gen_sv.c b/usr/src/lib/libresolv2/common/irs/gen_sv.c index db3c58b02b..4cad166d2f 100644 --- a/usr/src/lib/libresolv2/common/irs/gen_sv.c +++ b/usr/src/lib/libresolv2/common/irs/gen_sv.c @@ -1,29 +1,22 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: gen_sv.c,v 1.12 1999/10/13 16:39:30 vixie Exp $"; +static const char rcsid[] = "$Id: gen_sv.c,v 1.3 2005/04/27 04:56:24 sra Exp $"; #endif /* Imports */ @@ -232,3 +225,5 @@ sv_res_set(struct irs_sv *this, struct __res_state *res, (*sv->res_set)(sv, pvt->res, NULL); } } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/getaddrinfo.c b/usr/src/lib/libresolv2/common/irs/getaddrinfo.c index a84716a1ce..1839ba48e1 100644 --- a/usr/src/lib/libresolv2/common/irs/getaddrinfo.c +++ b/usr/src/lib/libresolv2/common/irs/getaddrinfo.c @@ -1,8 +1,3 @@ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - /* $KAME: getaddrinfo.c,v 1.14 2001/01/06 09:41:15 jinmei Exp $ */ /* @@ -34,55 +29,57 @@ * SUCH DAMAGE. */ -/* +/*! \file * Issues to be discussed: - * - Thread safe-ness must be checked. - * - Return values. There are nonstandard return values defined and used + *\li Thread safe-ness must be checked. + *\li Return values. There are nonstandard return values defined and used * in the source code. This is because RFC2553 is silent about which error * code must be returned for which situation. - * - IPv4 classful (shortened) form. RFC2553 is silent about it. XNET 5.2 + *\li IPv4 classful (shortened) form. RFC2553 is silent about it. XNET 5.2 * says to use inet_aton() to convert IPv4 numeric to binary (allows * classful form as a result). * current code - disallow classful form for IPv4 (due to use of inet_pton). - * - freeaddrinfo(NULL). RFC2553 is silent about it. XNET 5.2 says it is + *\li freeaddrinfo(NULL). RFC2553 is silent about it. XNET 5.2 says it is * invalid. * current code - SEGV on freeaddrinfo(NULL) * Note: - * - We use getipnodebyname() just for thread-safeness. There's no intent + *\li We use getipnodebyname() just for thread-safeness. There's no intent * to let it do PF_UNSPEC (actually we never pass PF_UNSPEC to * getipnodebyname(). - * - The code filters out AFs that are not supported by the kernel, + *\li The code filters out AFs that are not supported by the kernel, * when globbing NULL hostname (to loopback, or wildcard). Is it the right * thing to do? What is the relationship with post-RFC2553 AI_ADDRCONFIG * in ai_flags? - * - (post-2553) semantics of AI_ADDRCONFIG itself is too vague. + *\li (post-2553) semantics of AI_ADDRCONFIG itself is too vague. * (1) what should we do against numeric hostname (2) what should we do * against NULL hostname (3) what is AI_ADDRCONFIG itself. AF not ready? * non-loopback address configured? global address configured? - * - To avoid search order issue, we have a big amount of code duplicate + * \par Additional Issue: + * To avoid search order issue, we have a big amount of code duplicate * from gethnamaddr.c and some other places. The issues that there's no * lower layer function to lookup "IPv4 or IPv6" record. Calling * gethostbyname2 from getaddrinfo will end up in wrong search order, as * follows: - * - The code makes use of following calls when asked to resolver with + * \li The code makes use of following calls when asked to resolver with * ai_family = PF_UNSPEC: - * getipnodebyname(host, AF_INET6); + *\code getipnodebyname(host, AF_INET6); * getipnodebyname(host, AF_INET); - * This will result in the following queries if the node is configure to + *\endcode + * \li This will result in the following queries if the node is configure to * prefer /etc/hosts than DNS: + *\code * lookup /etc/hosts for IPv6 address * lookup DNS for IPv6 address * lookup /etc/hosts for IPv4 address * lookup DNS for IPv4 address + *\endcode * which may not meet people's requirement. - * The right thing to happen is to have underlying layer which does + * \li The right thing to happen is to have underlying layer which does * PF_UNSPEC lookup (lookup both) and return chain of addrinfos. * This would result in a bit of code duplicate with _dns_ghbyname() and * friends. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include <sys/types.h> @@ -206,20 +203,20 @@ struct addrinfo *addr2addrinfo __P((const struct addrinfo *, #if 0 static const char *ai_errlist[] = { "Success", - "Address family for hostname not supported", /* EAI_ADDRFAMILY */ - "Temporary failure in name resolution", /* EAI_AGAIN */ - "Invalid value for ai_flags", /* EAI_BADFLAGS */ - "Non-recoverable failure in name resolution", /* EAI_FAIL */ - "ai_family not supported", /* EAI_FAMILY */ - "Memory allocation failure", /* EAI_MEMORY */ - "No address associated with hostname", /* EAI_NODATA */ - "hostname nor servname provided, or not known", /* EAI_NONAME */ - "servname not supported for ai_socktype", /* EAI_SERVICE */ - "ai_socktype not supported", /* EAI_SOCKTYPE */ - "System error returned in errno", /* EAI_SYSTEM */ - "Invalid value for hints", /* EAI_BADHINTS */ - "Resolved protocol is unknown", /* EAI_PROTOCOL */ - "Unknown error", /* EAI_MAX */ + "Address family for hostname not supported", /*%< EAI_ADDRFAMILY */ + "Temporary failure in name resolution", /*%< EAI_AGAIN */ + "Invalid value for ai_flags", /*%< EAI_BADFLAGS */ + "Non-recoverable failure in name resolution", /*%< EAI_FAIL */ + "ai_family not supported", /*%< EAI_FAMILY */ + "Memory allocation failure", /*%< EAI_MEMORY */ + "No address associated with hostname", /*%< EAI_NODATA */ + "hostname nor servname provided, or not known", /*%< EAI_NONAME */ + "servname not supported for ai_socktype", /*%< EAI_SERVICE */ + "ai_socktype not supported", /*%< EAI_SOCKTYPE */ + "System error returned in errno", /*%< EAI_SYSTEM */ + "Invalid value for hints", /*%< EAI_BADHINTS */ + "Resolved protocol is unknown", /*%< EAI_PROTOCOL */ + "Unknown error", /*%< EAI_MAX */ }; #endif @@ -251,12 +248,8 @@ do { \ goto free; \ } while (/*CONSTCOND*/0) -/* - * Our compiler does not like an unconditional branch out of a loop, - * especially one defined in a macro! - */ -#ifdef ORIGINAL_ISC_CODE -#define ERR(err) \ +#ifndef SOLARIS2 +#define SETERROR(err) \ do { \ /* external reference: error, and label bad */ \ error = (err); \ @@ -264,20 +257,22 @@ do { \ /*NOTREACHED*/ \ } while (/*CONSTCOND*/0) #else -#define ERR(err) \ +#define SETERROR(err) \ do { \ - /* external reference: error */ \ + /* external reference: error, and label bad */ \ error = (err); \ - /*NOTREACHED*/ \ + if (error == error) \ + goto bad; \ } while (/*CONSTCOND*/0) #endif + #define MATCH_FAMILY(x, y, w) \ ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == PF_UNSPEC || (y) == PF_UNSPEC))) #define MATCH(x, y, w) \ ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY))) -#if 0 /* bind8 has its own version */ +#if 0 /*%< bind8 has its own version */ char * gai_strerror(ecode) int ecode; @@ -341,17 +336,15 @@ getaddrinfo(hostname, servname, hints, res) pai->ai_family = PF_UNSPEC; pai->ai_socktype = ANY; pai->ai_protocol = ANY; -#ifndef ORIGINAL_ISC_CODE -#ifdef __sparcv9 +#if defined(sun) && defined(_SOCKLEN_T) && defined(__sparcv9) /* - * We need to clear _ai_pad to preserve binary + * clear _ai_pad to preserve binary * compatibility with previously compiled 64-bit * applications in a pre-SUSv3 environment by * guaranteeing the upper 32-bits are empty. */ pai->_ai_pad = 0; -#endif /* __sparcv9 */ -#endif /* ORIGINAL_ISC_CODE */ +#endif pai->ai_addrlen = 0; pai->ai_canonname = NULL; pai->ai_addr = NULL; @@ -362,44 +355,27 @@ getaddrinfo(hostname, servname, hints, res) if (hints) { /* error check for hints */ if (hints->ai_addrlen || hints->ai_canonname || - hints->ai_addr || hints->ai_next) { - ERR(EAI_BADHINTS); /* xxx */ -#if !defined(ORIGINAL_ISC_CODE) - goto bad; -#endif - } -/* - * The AI_ macros defined by ISC are different than those defined by Solaris. - * AI_MASK is defined by ISC to check the range of their flags and doesn't work - * with Solaris. - */ -#ifdef ORIGINAL_ISC_CODE - if (hints->ai_flags & ~AI_MASK) { - ERR(EAI_BADFLAGS); - } -#endif + hints->ai_addr || hints->ai_next) + SETERROR(EAI_BADHINTS); /*%< xxx */ + if (hints->ai_flags & ~AI_MASK) + SETERROR(EAI_BADFLAGS); switch (hints->ai_family) { case PF_UNSPEC: case PF_INET: case PF_INET6: break; default: - ERR(EAI_FAMILY); -#if !defined(ORIGINAL_ISC_CODE) - goto bad; -#endif + SETERROR(EAI_FAMILY); } memcpy(pai, hints, sizeof(*pai)); -#ifndef ORIGINAL_ISC_CODE -#ifdef __sparcv9 +#if defined(sun) && defined(_SOCKLEN_T) && defined(__sparcv9) /* * We need to clear _ai_pad to preserve binary * compatibility. See prior comment. */ pai->_ai_pad = 0; -#endif /* __sparcv9 */ -#endif /* ORIGINAL_ISC_CODE */ +#endif /* * if both socktype/protocol are specified, check if they * are meaningful combination. @@ -414,10 +390,7 @@ getaddrinfo(hostname, servname, hints, res) continue; if (pai->ai_socktype == ex->e_socktype && pai->ai_protocol != ex->e_protocol) { - ERR(EAI_BADHINTS); -#if !defined(ORIGINAL_ISC_CODE) - goto bad; -#endif + SETERROR(EAI_BADHINTS); } } } @@ -437,10 +410,7 @@ getaddrinfo(hostname, servname, hints, res) case AI_ALL: #if 1 /* illegal */ - ERR(EAI_BADFLAGS); -#if !defined(ORIGINAL_ISC_CODE) - goto bad; -#endif + SETERROR(EAI_BADFLAGS); #else pai->ai_flags &= ~(AI_ALL | AI_V4MAPPED); break; @@ -467,12 +437,8 @@ getaddrinfo(hostname, servname, hints, res) #endif } error = get_portmatch(pai, servname); - if (error) { - ERR(error); -#if !defined(ORIGINAL_ISC_CODE) - goto bad; -#endif - } + if (error) + SETERROR(error); *pai = ai0; } @@ -530,18 +496,10 @@ getaddrinfo(hostname, servname, hints, res) if (sentinel.ai_next) goto good; - if (pai->ai_flags & AI_NUMERICHOST) { - ERR(EAI_NONAME); -#if !defined(ORIGINAL_ISC_CODE) - goto bad; -#endif - } - if (hostname == NULL) { - ERR(EAI_NONAME); -#if !defined(ORIGINAL_ISC_CODE) - goto bad; -#endif - } + if (pai->ai_flags & AI_NUMERICHOST) + SETERROR(EAI_NONAME); + if (hostname == NULL) + SETERROR(EAI_NONAME); /* * hostname as alphabetical name. @@ -563,7 +521,7 @@ getaddrinfo(hostname, servname, hints, res) goto free; } if (afai == NULL) { - error = EAI_NONAME; /* we've had no errors. */ + error = EAI_NONAME; /*%< we've had no errors. */ goto free; } @@ -620,11 +578,7 @@ getaddrinfo(hostname, servname, hints, res) cur = cur->ai_next; } - freeaddrinfo(afai); /* afai must not be NULL at this point. */ - - /* we must not have got any errors. */ - if (error != 0) /* just for diagnosis */ - abort(); + freeaddrinfo(afai); /*%< afai must not be NULL at this point. */ if (sentinel.ai_next) { good: @@ -647,7 +601,7 @@ bad: return(error); } -/* +/*% * FQDN hostname, DNS lookup */ static int @@ -675,7 +629,7 @@ explore_fqdn(pai, hostname, servname, res) if (!net_data || !(ho = net_data->ho)) return(0); -#if 0 /* XXX (notyet) */ +#if 0 /*%< XXX (notyet) */ if (net_data->ho_stayopen && net_data->ho_last && net_data->ho_last->h_addrtype == af) { if (ns_samename(name, net_data->ho_last->h_name) == 1) @@ -711,7 +665,7 @@ explore_fqdn(pai, hostname, servname, res) error = EAI_NONAME; break; default: - case NETDB_SUCCESS: /* should be impossible... */ + case NETDB_SUCCESS: /*%< should be impossible... */ error = EAI_NONAME; break; } @@ -719,7 +673,7 @@ explore_fqdn(pai, hostname, servname, res) } for (cur = result; cur; cur = cur->ai_next) { - GET_PORT(cur, servname); /* XXX: redundant lookups... */ + GET_PORT(cur, servname); /*%< XXX: redundant lookups... */ /* canonname should already be filled. */ } @@ -735,8 +689,8 @@ free: static int explore_copy(pai, src0, res) - const struct addrinfo *pai; /* seed */ - const struct addrinfo *src0; /* source */ + const struct addrinfo *pai; /*%< seed */ + const struct addrinfo *src0; /*%< source */ struct addrinfo **res; { int error; @@ -770,7 +724,7 @@ fail: return error; } -/* +/*% * hostname == NULL. * passive socket -> anyaddr (0.0.0.0 or ::) * non-passive socket -> localhost (127.0.0.1 or ::1) @@ -818,7 +772,7 @@ free: return error; } -/* +/*% * numeric hostname */ static int @@ -850,10 +804,10 @@ explore_numeric(pai, hostname, servname, res) pai->ai_family == PF_UNSPEC /*?*/) { GET_AI(cur->ai_next, afd, pton); GET_PORT(cur->ai_next, servname); - while (cur && cur->ai_next) + while (cur->ai_next) cur = cur->ai_next; } else - ERR(EAI_FAMILY); /*xxx*/ + SETERROR(EAI_FAMILY); /*xxx*/ } break; #endif @@ -863,14 +817,10 @@ explore_numeric(pai, hostname, servname, res) pai->ai_family == PF_UNSPEC /*?*/) { GET_AI(cur->ai_next, afd, pton); GET_PORT(cur->ai_next, servname); - while (cur && cur->ai_next) + while (cur->ai_next) cur = cur->ai_next; - } else { - ERR(EAI_FAMILY); /*xxx*/ -#if !defined(ORIGINAL_ISC_CODE) - goto bad; -#endif - } + } else + SETERROR(EAI_FAMILY); /*xxx*/ } break; } @@ -885,7 +835,7 @@ bad: return error; } -/* +/*% * numeric hostname with scope */ static int @@ -936,7 +886,7 @@ explore_numeric_scope(pai, hostname, servname, res) sin6 = (struct sockaddr_in6 *)(void *)cur->ai_addr; if (!ip6_str2scopeid(scope, sin6, &scopeid)) { free(hostname2); - return(EAI_NONAME); /* XXX: is return OK? */ + return(EAI_NONAME); /*%< XXX: is return OK? */ } #ifdef HAVE_SIN6_SCOPE_ID sin6->sin6_scope_id = scopeid; @@ -1014,11 +964,7 @@ copy_ai(pai) free(ai); return NULL; } -#ifdef HAVE_STRLCPY - strlcpy(ai->ai_canonname, pai->ai_canonname, l); -#else - strncpy(ai->ai_canonname, pai->ai_canonname, l); -#endif + strcpy(ai->ai_canonname, pai->ai_canonname); /* (checked) */ } else { /* just to make sure */ ai->ai_canonname = NULL; @@ -1136,7 +1082,7 @@ find_afd(af) return NULL; } -/* +/*% * post-2553: AI_ADDRCONFIG check. if we use getipnodeby* as backend, backend * will take care of it. * the semantics of AI_ADDRCONFIG is not defined well. we are not sure @@ -1173,7 +1119,8 @@ ip6_str2scopeid(char *scope, struct sockaddr_in6 *sin6, return (0); #ifdef USE_IFNAMELINKID - if (IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6)) { + if (IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6) || + IN6_IS_ADDR_MC_NODELOCAL(a6)) { /* * Using interface names as link indices can be allowed * only when we can assume a one-to-one mappings between @@ -1193,8 +1140,7 @@ ip6_str2scopeid(char *scope, struct sockaddr_in6 *sin6, if (IN6_IS_ADDR_MC_ORGLOCAL(a6)) goto trynumeric; else - goto trynumeric; /* global */ - + goto trynumeric; /*%< global */ /* try to convert to a numeric id as a last resort */ trynumeric: errno = 0; @@ -1231,7 +1177,7 @@ hostent2addrinfo(hp, pai) cur = &sentinel; for (i = 0; (ap = aplist[i]) != NULL; i++) { -#if 0 /* the trick seems too much */ +#if 0 /*%< the trick seems too much */ af = hp->h_addr_list; if (af == AF_INET6 && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)ap)) { @@ -1255,7 +1201,7 @@ hostent2addrinfo(hp, pai) */ GET_CANONNAME(cur->ai_next, hp->h_name); } - while (cur && cur->ai_next) /* no need to loop, actually. */ + while (cur->ai_next) /*%< no need to loop, actually. */ cur = cur->ai_next; continue; diff --git a/usr/src/lib/libresolv2/common/irs/getgrent.c b/usr/src/lib/libresolv2/common/irs/getgrent.c index 5ac15a1c87..e6c6c42147 100644 --- a/usr/src/lib/libresolv2/common/irs/getgrent.c +++ b/usr/src/lib/libresolv2/common/irs/getgrent.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: getgrent.c,v 1.20 2001/05/29 05:48:41 marka Exp $"; +static const char rcsid[] = "$Id: getgrent.c,v 1.5 2005/04/27 04:56:24 sra Exp $"; #endif /* Imports */ @@ -228,3 +221,4 @@ init() { } #endif /* WANT_IRS_GR */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/getgrent_r.c b/usr/src/lib/libresolv2/common/irs/getgrent_r.c index 01c0a936ed..eb9c7947cd 100644 --- a/usr/src/lib/libresolv2/common/irs/getgrent_r.c +++ b/usr/src/lib/libresolv2/common/irs/getgrent_r.c @@ -1,30 +1,22 @@ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1998-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = - "$Id: getgrent_r.c,v 8.7 2001/11/01 08:02:08 marka Exp $"; +static const char rcsid[] = "$Id: getgrent_r.c,v 1.7 2005/04/27 04:56:24 sra Exp $"; #endif /* LIBC_SCCS and not lint */ #include <port_before.h> @@ -38,10 +30,10 @@ static const char rcsid[] = #if (defined(POSIX_GETGRNAM_R) || defined(POSIX_GETGRGID_R)) && \ defined(_POSIX_PTHREAD_SEMANTICS) /* turn off solaris remapping in <grp.h> */ -#define _UNIX95 +#define _UNIX95 #undef _POSIX_PTHREAD_SEMANTICS #include <grp.h> -#define _POSIX_PTHREAD_SEMANTICS 1 +#define _POSIX_PTHREAD_SEMANTICS 1 #else #include <grp.h> #endif @@ -57,7 +49,7 @@ copy_group(struct group *, struct group *, char *buf, int buflen); #ifdef POSIX_GETGRNAM_R int __posix_getgrnam_r(const char *name, struct group *gptr, - char *buf, size_t buflen, struct group **result) { + char *buf, int buflen, struct group **result) { #else int getgrnam_r(const char *name, struct group *gptr, @@ -94,7 +86,7 @@ getgrnam_r(const char *name, struct group *gptr, #ifdef POSIX_GETGRGID_R int __posix_getgrgid_r(gid_t gid, struct group *gptr, - char *buf, size_t buflen, struct group **result) { + char *buf, int buflen, struct group **result) { #else /* POSIX_GETGRGID_R */ int getgrgid_r(gid_t gid, struct group *gptr, @@ -128,7 +120,7 @@ getgrgid_r(gid_t gid, struct group *gptr, } #endif -/* +/*% * These assume a single context is in operation per thread. * If this is not the case we will need to call irs directly * rather than through the base functions. @@ -188,15 +180,15 @@ copy_group(struct group *ge, struct group *gptr, char *buf, int buflen) { int numptr, len; /* Find out the amount of space required to store the answer. */ - numptr = 1; /* NULL ptr */ + numptr = 1; /*%< NULL ptr */ len = (char *)ALIGN(buf) - buf; for (i = 0; ge->gr_mem[i]; i++, numptr++) { len += strlen(ge->gr_mem[i]) + 1; } len += strlen(ge->gr_name) + 1; len += strlen(ge->gr_passwd) + 1; - len += numptr * sizeof (char *); - + len += numptr * sizeof(char*); + if (len > buflen) { errno = ERANGE; return (ERANGE); @@ -205,7 +197,7 @@ copy_group(struct group *ge, struct group *gptr, char *buf, int buflen) { /* copy group id */ gptr->gr_gid = ge->gr_gid; - cp = (char *)ALIGN(buf) + numptr * sizeof (char *); + cp = (char *)ALIGN(buf) + numptr * sizeof(char *); /* copy official name */ n = strlen(ge->gr_name) + 1; @@ -215,7 +207,7 @@ copy_group(struct group *ge, struct group *gptr, char *buf, int buflen) { /* copy member list */ gptr->gr_mem = (char **)ALIGN(buf); - for (i = 0; ge->gr_mem[i]; i++) { + for (i = 0 ; ge->gr_mem[i]; i++) { n = strlen(ge->gr_mem[i]) + 1; strcpy(cp, ge->gr_mem[i]); gptr->gr_mem[i] = cp; @@ -235,3 +227,4 @@ copy_group(struct group *ge, struct group *gptr, char *buf, int buflen) { static int getgrent_r_unknown_system = 0; #endif /* GROUP_R_RETURN */ #endif /* !def(_REENTRANT) || !def(DO_PTHREADS) || !def(WANT_IRS_PW) */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/gethostent.c b/usr/src/lib/libresolv2/common/irs/gethostent.c index 592f842111..57c9d24496 100644 --- a/usr/src/lib/libresolv2/common/irs/gethostent.c +++ b/usr/src/lib/libresolv2/common/irs/gethostent.c @@ -3,25 +3,26 @@ * Use is subject to license terms. */ + /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: gethostent.c,v 1.34 2003/05/29 00:05:18 marka Exp $"; +static const char rcsid[] = "$Id: gethostent.c,v 1.8 2006/01/10 05:06:00 marka Exp $"; #endif /* Imports */ @@ -77,6 +78,7 @@ extern int __res_retry(int); extern int __res_retry_reset(void); #endif /* SUNW_OVERRIDE_RETRY */ + /* Public */ struct hostent * @@ -94,11 +96,7 @@ gethostbyname2(const char *name, int af) { } struct hostent * -#ifdef ORIGINAL_ISC_CODE gethostbyaddr(const char *addr, int len, int af) { -#else -gethostbyaddr(const void *addr, socklen_t len, int af) { -#endif /* ORIGINAL_ISC_CODE */ struct net_data *net_data = init(); return (gethostbyaddr_p(addr, len, af, net_data)); @@ -111,33 +109,17 @@ gethostent() { return (gethostent_p(net_data)); } -#ifdef ORIGINAL_ISC_CODE void -#else -int -#endif sethostent(int stayopen) { struct net_data *net_data = init(); sethostent_p(stayopen, net_data); -#ifdef ORIGINAL_ISC_CODE -#else - return (0); -#endif } -#ifdef ORIGINAL_ISC_CODE void -#else -int -#endif endhostent() { struct net_data *net_data = init(); endhostent_p(net_data); -#ifdef ORIGINAL_ISC_CODE -#else - return (0); -#endif } /* Shared private. */ @@ -147,18 +129,7 @@ gethostbyname_p(const char *name, struct net_data *net_data) { struct hostent *hp; if (!net_data) -#ifdef SUNW_SETHERRNO - { - /* - * Should set the context h_errno, but since net_data - * is NULL, we don't have a context. - */ - h_errno = NETDB_INTERNAL; - return (NULL); - } -#else return (NULL); -#endif /* SUNW_SETHERRNO */ if (net_data->res->options & RES_USE_INET6) { hp = gethostbyname2_p(name, AF_INET6, net_data); @@ -177,16 +148,9 @@ gethostbyname2_p(const char *name, int af, struct net_data *net_data) { char **hap; if (!net_data || !(ho = net_data->ho)) -#ifdef SUNW_SETHERRNO - { - h_errno = NETDB_INTERNAL; return (NULL); - } -#else - return (NULL); -#endif /* SUNW_SETHERRNO */ if (net_data->ho_stayopen && net_data->ho_last && - net_data->ho_last->h_addrtype == af) { + net_data->ho_last->h_addrtype == af) { if (ns_samename(name, net_data->ho_last->h_name) == 1) return (net_data->ho_last); for (hap = net_data->ho_last->h_aliases; hap && *hap; hap++) @@ -216,14 +180,7 @@ gethostbyaddr_p(const char *addr, int len, int af, struct net_data *net_data) { char **hap; if (!net_data || !(ho = net_data->ho)) -#ifdef SUNW_SETHERRNO - { - h_errno = NETDB_INTERNAL; return (NULL); - } -#else - return (NULL); -#endif /* SUNW_SETHERRNO */ if (net_data->ho_stayopen && net_data->ho_last && net_data->ho_last->h_length == len) for (hap = net_data->ho_last->h_addr_list; @@ -244,17 +201,10 @@ gethostent_p(struct net_data *net_data) { struct hostent *hp; if (!net_data || !(ho = net_data->ho)) -#ifdef SUNW_SETHERRNO - { - h_errno = NETDB_INTERNAL; - return (NULL); - } -#else return (NULL); -#endif /* SUNW_SETHERRNO */ while ((hp = (*ho->next)(ho)) != NULL && hp->h_addrtype == AF_INET6 && - (net_data->res->options & RES_USE_INET6) == 0) + (net_data->res->options & RES_USE_INET6) == 0U) continue; net_data->ho_last = hp; return (net_data->ho_last); @@ -302,11 +252,11 @@ static const unsigned char in6addr_mapped[12] = { static int scan_interfaces(int *, int *); static struct hostent *copyandmerge(struct hostent *, struct hostent *, int, int *); -/* +/*% * Public functions */ -/* +/*% * AI_V4MAPPED + AF_INET6 * If no IPv6 address then a query for IPv4 and map returned values. * @@ -416,20 +366,25 @@ getipnodebyaddr(const void *src, size_t len, int af, int *error_num) { struct net_data *net_data = init(); /* Sanity Checks. */ - if (src == NULL || net_data == NULL) { +#ifdef ORIGINAL_ISC_CODE + if (src == NULL) { +#else + /* this change was added circa May 2009, but not in ISC libbind 6.0 */ + if (src == NULL|| net_data == NULL) { +#endif /* ORIGINAL_ISC_CODE */ *error_num = NO_RECOVERY; return (NULL); } - + switch (af) { case AF_INET: - if (len != INADDRSZ) { + if (len != (size_t)INADDRSZ) { *error_num = NO_RECOVERY; return (NULL); } break; case AF_INET6: - if (len != IN6ADDRSZ) { + if (len != (size_t)IN6ADDRSZ) { *error_num = NO_RECOVERY; return (NULL); } @@ -512,11 +467,11 @@ freehostent(struct hostent *he) { memput(he, sizeof *he); } -/* +/*% * Private */ -/* +/*% * Scan the interface table and set have_v4 and have_v6 depending * upon whether there are IPv4 and IPv6 interface addresses. * @@ -528,9 +483,26 @@ freehostent(struct hostent *he) { #if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR) && \ !defined(IRIX_EMUL_IOCTL_SIOCGIFCONF) +#ifdef __hpux +#define lifc_len iflc_len +#define lifc_buf iflc_buf +#define lifc_req iflc_req +#define LIFCONF if_laddrconf +#else #define SETFAMILYFLAGS #define LIFCONF lifconf +#endif + +#ifdef __hpux +#define lifr_addr iflr_addr +#define lifr_name iflr_name +#define lifr_dstaddr iflr_dstaddr +#define lifr_flags iflr_flags +#define ss_family sa_family +#define LIFREQ if_laddrreq +#else #define LIFREQ lifreq +#endif static void scan_interfaces6(int *have_v4, int *have_v6) { @@ -555,7 +527,7 @@ scan_interfaces6(int *have_v4, int *have_v6) { if (buf == NULL) goto cleanup; #ifdef SETFAMILYFLAGS - lifc.lifc_family = AF_UNSPEC; /* request all families */ + lifc.lifc_family = AF_UNSPEC; /*%< request all families */ lifc.lifc_flags = 0; #endif lifc.lifc_len = bufsiz; @@ -583,7 +555,7 @@ scan_interfaces6(int *have_v4, int *have_v6) { } /* Parse system's interface list. */ - cplim = buf + lifc.lifc_len; /* skip over if's with big ifr_addr's */ + cplim = buf + lifc.lifc_len; /*%< skip over if's with big ifr_addr's */ for (cp = buf; (*have_v4 == 0 || *have_v6 == 0) && cp < cplim; cp += cpsize) { @@ -658,11 +630,38 @@ scan_interfaces6(int *have_v4, int *have_v6) { } #endif +#if ( defined(__linux__) || defined(__linux) || defined(LINUX) ) +#ifndef IF_NAMESIZE +# ifdef IFNAMSIZ +# define IF_NAMESIZE IFNAMSIZ +# else +# define IF_NAMESIZE 16 +# endif +#endif +static void +scan_linux6(int *have_v6) { + FILE *proc = NULL; + char address[33]; + char name[IF_NAMESIZE+1]; + int ifindex, prefix, flag3, flag4; + + proc = fopen("/proc/net/if_inet6", "r"); + if (proc == NULL) + return; + + if (fscanf(proc, "%32[a-f0-9] %x %x %x %x %16s\n", + address, &ifindex, &prefix, &flag3, &flag4, name) == 6) + *have_v6 = 1; + fclose(proc); + return; +} +#endif + static int scan_interfaces(int *have_v4, int *have_v6) { struct ifconf ifc; union { - char _pad[256]; /* leave space for IPv6 addresses */ + char _pad[256]; /*%< leave space for IPv6 addresses */ struct ifreq ifreq; } u; struct in_addr in4; @@ -684,6 +683,9 @@ scan_interfaces(int *have_v4, int *have_v6) { if (*have_v4 != 0 && *have_v6 != 0) return (0); #endif +#ifdef __linux + scan_linux6(have_v6); +#endif /* Get interface list from system. */ if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) @@ -732,7 +734,7 @@ scan_interfaces(int *have_v4, int *have_v6) { } /* Parse system's interface list. */ - cplim = buf + ifc.ifc_len; /* skip over if's with big ifr_addr's */ + cplim = buf + ifc.ifc_len; /*%< skip over if's with big ifr_addr's */ for (cp = buf; (*have_v4 == 0 || *have_v6 == 0) && cp < cplim; cp += cpsize) { @@ -812,8 +814,8 @@ scan_interfaces(int *have_v4, int *have_v6) { static struct hostent * copyandmerge(struct hostent *he1, struct hostent *he2, int af, int *error_num) { struct hostent *he = NULL; - int addresses = 1; /* NULL terminator */ - int names = 1; /* NULL terminator */ + int addresses = 1; /*%< NULL terminator */ + int names = 1; /*%< NULL terminator */ int len = 0; char **cpp, **npp; @@ -972,6 +974,10 @@ init() { if (!net_data->ho || !net_data->res) { error: errno = EIO; + +#ifdef SUNW_SETHERRNO + h_errno = NETDB_INTERNAL; +#endif /* SUNW_SETHERRNO */ if (net_data && net_data->res) RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL); return (NULL); @@ -1027,7 +1033,7 @@ fakeaddr(const char *name, int af, struct net_data *net_data) { } strncpy(pvt->name, name, NS_MAXDNAME); pvt->name[NS_MAXDNAME] = '\0'; - if (af == AF_INET && (net_data->res->options & RES_USE_INET6) != 0) { + if (af == AF_INET && (net_data->res->options & RES_USE_INET6) != 0U) { map_v4v6_address(pvt->addr, pvt->addr); af = AF_INET6; } @@ -1054,7 +1060,7 @@ fakeaddr(const char *name, int af, struct net_data *net_data) { return (&pvt->host); } -#ifdef grot /* for future use in gethostbyaddr(), for "SUNSECURITY" */ +#ifdef grot /*%< for future use in gethostbyaddr(), for "SUNSECURITY" */ struct hostent *rhp; char **haddr; u_long old_options; @@ -1085,5 +1091,6 @@ fakeaddr(const char *name, int af, struct net_data *net_data) { } } #endif /* grot */ - #endif /*__BIND_NOSTATIC*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/gethostent_r.c b/usr/src/lib/libresolv2/common/irs/gethostent_r.c index f6f77b7735..fdb7ee225c 100644 --- a/usr/src/lib/libresolv2/common/irs/gethostent_r.c +++ b/usr/src/lib/libresolv2/common/irs/gethostent_r.c @@ -1,29 +1,22 @@ /* - * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1998-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: gethostent_r.c,v 8.7 2001/11/01 08:02:09 marka Exp $"; +static const char rcsid[] = "$Id: gethostent_r.c,v 1.9 2005/09/03 12:41:37 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include <port_before.h> @@ -51,10 +44,12 @@ gethostbyname_r(const char *name, struct hostent *hptr, HOST_R_ARGS) { int n = 0; #endif +#ifdef HOST_R_ERRNO HOST_R_ERRNO; +#endif #ifdef HOST_R_SETANSWER - if (he == NULL || (n = copy_hostent(he, hptr, HOST_R_COPY)) == 0) + if (he == NULL || (n = copy_hostent(he, hptr, HOST_R_COPY)) != 0) *answerp = NULL; else *answerp = hptr; @@ -76,10 +71,12 @@ gethostbyaddr_r(const char *addr, int len, int type, int n = 0; #endif +#ifdef HOST_R_ERRNO HOST_R_ERRNO; +#endif #ifdef HOST_R_SETANSWER - if (he == NULL || (n = copy_hostent(he, hptr, HOST_R_COPY)) == 0) + if (he == NULL || (n = copy_hostent(he, hptr, HOST_R_COPY)) != 0) *answerp = NULL; else *answerp = hptr; @@ -93,7 +90,7 @@ gethostbyaddr_r(const char *addr, int len, int type, #endif } -/* +/*% * These assume a single context is in operation per thread. * If this is not the case we will need to call irs directly * rather than through the base functions. @@ -106,10 +103,12 @@ gethostent_r(struct hostent *hptr, HOST_R_ARGS) { int n = 0; #endif +#ifdef HOST_R_ERRNO HOST_R_ERRNO; +#endif #ifdef HOST_R_SETANSWER - if (he == NULL || (n = copy_hostent(he, hptr, HOST_R_COPY)) == 0) + if (he == NULL || (n = copy_hostent(he, hptr, HOST_R_COPY)) != 0) *answerp = NULL; else *answerp = hptr; @@ -130,6 +129,9 @@ sethostent_r(int stay_open, HOST_R_ENT_ARGS) sethostent_r(int stay_open) #endif { +#ifdef HOST_R_ENT_ARGS + UNUSED(hdptr); +#endif sethostent(stay_open); #ifdef HOST_R_SET_RESULT return (HOST_R_SET_RESULT); @@ -143,6 +145,9 @@ endhostent_r(HOST_R_ENT_ARGS) endhostent_r(void) #endif { +#ifdef HOST_R_ENT_ARGS + UNUSED(hdptr); +#endif endhostent(); HOST_R_END_RESULT(HOST_R_OK); } @@ -158,7 +163,7 @@ copy_hostent(struct hostent *he, struct hostent *hptr, HOST_R_COPY_ARGS) { int nptr, len; /* Find out the amount of space required to store the answer. */ - nptr = 2; /* NULL ptrs */ + nptr = 2; /*%< NULL ptrs */ len = (char *)ALIGN(buf) - buf; for (i = 0; he->h_addr_list[i]; i++, nptr++) { len += he->h_length; @@ -221,8 +226,8 @@ copy_hostent(struct hostent *he, struct hostent *hptr, HOST_R_COPY_ARGS) { /* copy up to first 35 addresses */ i = 0; - cp = hdptr->hostaddr; - eob = hdptr->hostaddr + sizeof(hdptr->hostaddr); + cp = hdptr->hostbuf; + eob = hdptr->hostbuf + sizeof(hdptr->hostbuf); hptr->h_addr_list = hdptr->h_addr_ptrs; while (he->h_addr_list[i] && i < (_MAXADDRS)) { if (n < (eob - cp)) { @@ -237,8 +242,6 @@ copy_hostent(struct hostent *he, struct hostent *hptr, HOST_R_COPY_ARGS) { hptr->h_addr_list[i] = NULL; /* copy official name */ - cp = hdptr->hostbuf; - eob = hdptr->hostbuf + sizeof(hdptr->hostbuf); if ((n = strlen(he->h_name) + 1) < (eob - cp)) { strcpy(cp, he->h_name); hptr->h_name = cp; @@ -269,3 +272,4 @@ copy_hostent(struct hostent *he, struct hostent *hptr, HOST_R_COPY_ARGS) { static int gethostent_r_unknown_system = 0; #endif /* HOST_R_RETURN */ #endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/getnameinfo.c b/usr/src/lib/libresolv2/common/irs/getnameinfo.c index e645196a80..89c8230ef9 100644 --- a/usr/src/lib/libresolv2/common/irs/getnameinfo.c +++ b/usr/src/lib/libresolv2/common/irs/getnameinfo.c @@ -1,13 +1,18 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* * Issues to be discussed: * - Thread safe-ness must be checked */ +#if ( defined(__linux__) || defined(__linux) || defined(LINUX) ) +#ifndef IF_NAMESIZE +# ifdef IFNAMSIZ +# define IF_NAMESIZE IFNAMSIZ +# else +# define IF_NAMESIZE 16 +# endif +#endif +#endif + /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. * All rights reserved. @@ -41,8 +46,6 @@ * SUCH DAMAGE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <port_before.h> #include <sys/types.h> @@ -60,7 +63,7 @@ #include <port_after.h> -/* +/*% * Note that a_off will be dynamically adjusted so that to be consistent * with the definition of sockaddr_in{,6}. * The value presented below is just a guess. @@ -96,23 +99,11 @@ static int ip6_sa2str __P((const struct sockaddr_in6 *, char *, size_t, int)); int getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) const struct sockaddr *sa; -#ifdef ORIGINAL_ISC_CODE size_t salen; -#else - socklen_t salen; -#endif char *host; -#ifdef ORIGINAL_ISC_CODE size_t hostlen; -#else - socklen_t hostlen; -#endif char *serv; -#ifdef ORIGINAL_ISC_CODE size_t servlen; -#else - socklen_t servlen; -#endif int flags; { struct afd *afd; @@ -148,10 +139,10 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) found: if (salen != afd->a_socklen) return EAI_FAIL; - port = ((const struct sockinet *)sa)->si_port; /* network byte order */ + port = ((const struct sockinet *)sa)->si_port; /*%< network byte order */ addr = (const char *)sa + afd->a_off; - if (serv == NULL || servlen == 0) { + if (serv == NULL || servlen == 0U) { /* * rfc2553bis says that serv == NULL or servlen == 0 means that * the caller does not want the result. @@ -173,7 +164,7 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) switch (sa->sa_family) { case AF_INET: - if (ntohl(*(const u_long *)addr) >> IN_CLASSA_NSHIFT == 0) + if (ntohl(*(const u_int32_t *)addr) >> IN_CLASSA_NSHIFT == 0) flags |= NI_NUMERICHOST; break; case AF_INET6: @@ -196,7 +187,7 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) } break; } - if (host == NULL || hostlen == 0) { + if (host == NULL || hostlen == 0U) { /* * rfc2553bis says that host == NULL or hostlen == 0 means that * the caller does not want the result. @@ -260,13 +251,13 @@ ip6_parsenumeric(const struct sockaddr *sa, const char *addr, char *host, return EAI_SYSTEM; numaddrlen = strlen(numaddr); - if (numaddrlen + 1 > hostlen) /* don't forget terminator */ + if (numaddrlen + 1 > hostlen) /*%< don't forget terminator */ return EAI_MEMORY; strcpy(host, numaddr); #ifdef HAVE_SIN6_SCOPE_ID if (((const struct sockaddr_in6 *)sa)->sin6_scope_id) { - char scopebuf[MAXHOSTNAMELEN]; /* XXX */ + char scopebuf[MAXHOSTNAMELEN]; /*%< XXX */ int scopelen; /* ip6_sa2str never fails */ @@ -302,7 +293,7 @@ ip6_sa2str(const struct sockaddr_in6 *sa6, char *buf, #ifdef NI_NUMERICSCOPE if (flags & NI_NUMERICSCOPE) { sprintf(tmp, "%u", sa6->sin6_scope_id); - if (bufsiz != 0) { + if (bufsiz != 0U) { strncpy(buf, tmp, bufsiz - 1); buf[bufsiz - 1] = '\0'; } @@ -332,10 +323,12 @@ ip6_sa2str(const struct sockaddr_in6 *sa6, char *buf, /* last resort */ sprintf(tmp, "%u", sa6->sin6_scope_id); - if (bufsiz != 0) { + if (bufsiz != 0U) { strncpy(buf, tmp, bufsiz - 1); buf[bufsiz - 1] = '\0'; } return(strlen(tmp)); } #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/getnetent.c b/usr/src/lib/libresolv2/common/irs/getnetent.c index 8cf81d4699..a6abe7175b 100644 --- a/usr/src/lib/libresolv2/common/irs/getnetent.c +++ b/usr/src/lib/libresolv2/common/irs/getnetent.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: getnetent.c,v 1.19 2001/05/29 05:48:47 marka Exp $"; +static const char rcsid[] = "$Id: getnetent.c,v 1.7 2005/04/27 04:56:25 sra Exp $"; #endif /* Imports */ @@ -91,45 +84,25 @@ getnetbyname(const char *name) { } struct netent * -#ifdef ORIGINAL_ISC_CODE getnetbyaddr(unsigned long net, int type) { -#else -getnetbyaddr(in_addr_t net, int type) { -#endif struct net_data *net_data = init(); return (getnetbyaddr_p(net, type, net_data)); } -#ifdef ORIGINAL_ISC_CODE void -#else -int -#endif setnetent(int stayopen) { struct net_data *net_data = init(); setnetent_p(stayopen, net_data); -#ifdef ORIGINAL_ISC_CODE -#else - return (0); -#endif } -#ifdef ORIGINAL_ISC_CODE void -#else -int -#endif endnetent() { struct net_data *net_data = init(); endnetent_p(net_data); -#ifdef ORIGINAL_ISC_CODE -#else - return (0); -#endif } /* Shared private. */ @@ -183,13 +156,13 @@ getnetbyaddr_p(unsigned long net, int type, struct net_data *net_data) { return (net_data->nw_last); /* cannonize net(host order) */ - if (net < 256) { + if (net < 256UL) { net <<= 24; bits = 8; - } else if (net < 65536) { + } else if (net < 65536UL) { net <<= 16; bits = 16; - } else if (net < 16777216) { + } else if (net < 16777216UL) { net <<= 8; bits = 24; } else @@ -348,7 +321,7 @@ nw_to_net(struct nwent *nwent, struct net_data *net_data) { pvt->netent.n_aliases = nwent->n_aliases; pvt->netent.n_addrtype = nwent->n_addrtype; -/* +/*% * What this code does: Converts net addresses from network to host form. * * msbyte: the index of the most significant byte in the n_addr array. @@ -368,3 +341,5 @@ nw_to_net(struct nwent *nwent, struct net_data *net_data) { } #endif /*__BIND_NOSTATIC*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/getnetent_r.c b/usr/src/lib/libresolv2/common/irs/getnetent_r.c index 1f8f9686c9..9fb52bc394 100644 --- a/usr/src/lib/libresolv2/common/irs/getnetent_r.c +++ b/usr/src/lib/libresolv2/common/irs/getnetent_r.c @@ -1,29 +1,22 @@ /* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1998-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: getnetent_r.c,v 8.6 2001/11/01 08:02:11 marka Exp $"; +static const char rcsid[] = "$Id: getnetent_r.c,v 1.6 2005/09/03 12:41:38 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include <port_before.h> @@ -90,7 +83,7 @@ getnetbyaddr_r(GETNETBYADDR_ADDR_T addr, int type, struct netent *nptr, NET_R_AR #endif } -/* +/*% * These assume a single context is in operation per thread. * If this is not the case we will need to call irs directly * rather than through the base functions. @@ -125,6 +118,9 @@ setnetent_r(int stay_open, NET_R_ENT_ARGS) setnetent_r(int stay_open) #endif { +#ifdef NET_R_ENT_ARGS + UNUSED(ndptr); +#endif setnetent(stay_open); #ifdef NET_R_SET_RESULT return (NET_R_SET_RESULT); @@ -138,6 +134,9 @@ endnetent_r(NET_R_ENT_ARGS) endnetent_r() #endif { +#ifdef NET_R_ENT_ARGS + UNUSED(ndptr); +#endif endnetent(); NET_R_END_RESULT(NET_R_OK); } @@ -152,7 +151,7 @@ copy_netent(struct netent *ne, struct netent *nptr, NET_R_COPY_ARGS) { int numptr, len; /* Find out the amount of space required to store the answer. */ - numptr = 1; /* NULL ptr */ + numptr = 1; /*%< NULL ptr */ len = (char *)ALIGN(buf) - buf; for (i = 0; ne->n_aliases[i]; i++, numptr++) { len += strlen(ne->n_aliases[i]) + 1; @@ -232,3 +231,4 @@ copy_netent(struct netent *ne, struct netent *nptr, NET_R_COPY_ARGS) { static int getnetent_r_unknown_system = 0; #endif /* NET_R_RETURN */ #endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/getnetgrent.c b/usr/src/lib/libresolv2/common/irs/getnetgrent.c index 69e322d647..2a21772468 100644 --- a/usr/src/lib/libresolv2/common/irs/getnetgrent.c +++ b/usr/src/lib/libresolv2/common/irs/getnetgrent.c @@ -1,29 +1,22 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Portions Copyright (c) 1996,1999 by Internet Software Consortium. + * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1996-1999, 2001, 2003 Internet Software Consortium. * - * Permission to use, copy, modify, and distribute this software for any + * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: getnetgrent.c,v 1.17 2003/04/29 05:51:14 marka Exp $"; +static const char rcsid[] = "$Id: getnetgrent.c,v 1.6 2008/11/14 02:36:51 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports */ @@ -57,35 +50,18 @@ static struct net_data *init(void); #ifndef SETNETGRENT_ARGS #define SETNETGRENT_ARGS const char *netgroup #endif - -#ifdef ORIGINAL_ISC_CODE void -#else -int -#endif setnetgrent(SETNETGRENT_ARGS) { struct net_data *net_data = init(); setnetgrent_p(netgroup, net_data); -#ifdef ORIGINAL_ISC_CODE -#else - return (0); -#endif } -#ifdef ORIGINAL_ISC_CODE void -#else -int -#endif endnetgrent(void) { struct net_data *net_data = init(); endnetgrent_p(net_data); -#ifdef ORIGINAL_ISC_CODE -#else - return (0); -#endif } #ifndef INNETGR_ARGS @@ -99,9 +75,10 @@ innetgr(INNETGR_ARGS) { return (innetgr_p(netgroup, host, user, domain, net_data)); } -#ifdef ORIGINAL_ISC_CODE int -getnetgrent(const char **host, const char **user, const char **domain) { +getnetgrent(NGR_R_CONST char **host, NGR_R_CONST char **user, + NGR_R_CONST char **domain) +{ struct net_data *net_data = init(); const char *ch, *cu, *cd; int ret; @@ -115,16 +92,6 @@ getnetgrent(const char **host, const char **user, const char **domain) { DE_CONST(cd, *domain); return (ret); } -#else -int -getnetgrent(char **host, char **user, char **domain) { - struct net_data *net_data = init(); - - return (getnetgrent_p((const char **)host, (const char **)user, - (const char **)domain, net_data)); - -} -#endif /* ORIGINAL_ISC_CODE */ /* Shared private. */ @@ -184,8 +151,10 @@ init(void) { return (NULL); } } - + return (net_data); } #endif /*__BIND_NOSTATIC*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/getnetgrent_r.c b/usr/src/lib/libresolv2/common/irs/getnetgrent_r.c index a53ebd2cee..aa8810320d 100644 --- a/usr/src/lib/libresolv2/common/irs/getnetgrent_r.c +++ b/usr/src/lib/libresolv2/common/irs/getnetgrent_r.c @@ -1,29 +1,22 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Copyright (c) 1998-1999 by Internet Software Consortium. + * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1998, 1999, 2001, 2003 Internet Software Consortium. * - * Permission to use, copy, modify, and distribute this software for any + * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: getnetgrent_r.c,v 8.7 2003/04/29 05:51:14 marka Exp $"; +static const char rcsid[] = "$Id: getnetgrent_r.c,v 1.14 2008/11/14 02:36:51 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include <port_before.h> @@ -36,15 +29,17 @@ static const char rcsid[] = "$Id: getnetgrent_r.c,v 8.7 2003/04/29 05:51:14 mark #include <sys/types.h> #include <netinet/in.h> #include <netdb.h> -#include <netgroup.h> #include <stdlib.h> #include <port_after.h> #ifdef NGR_R_RETURN +#ifndef NGR_R_PRIVATE +#define NGR_R_PRIVATE 0 +#endif -static NGR_R_RETURN -copy_protoent(char **, char **, char **, const char *, const char *, - const char *, NGR_R_COPY_ARGS); +static NGR_R_RETURN +copy_protoent(NGR_R_CONST char **, NGR_R_CONST char **, NGR_R_CONST char **, + const char *, const char *, const char *, NGR_R_COPY_ARGS); NGR_R_RETURN innetgr_r(const char *netgroup, const char *host, const char *user, @@ -59,34 +54,62 @@ innetgr_r(const char *netgroup, const char *host, const char *user, return (innetgr(ng, ho, us, dom)); } -/* +/*% * These assume a single context is in operation per thread. * If this is not the case we will need to call irs directly * rather than through the base functions. */ NGR_R_RETURN -getnetgrent_r(char **machinep, char **userp, char **domainp, NGR_R_ARGS) { - char *mp, *up, *dp; +getnetgrent_r(NGR_R_CONST char **machinep, NGR_R_CONST char **userp, + NGR_R_CONST char **domainp, NGR_R_ARGS) +{ + NGR_R_CONST char *mp, *up, *dp; int res = getnetgrent(&mp, &up, &dp); - if (res != 1) + if (res != 1) return (res); return (copy_protoent(machinep, userp, domainp, mp, up, dp, NGR_R_COPY)); } +#if NGR_R_PRIVATE == 2 +struct private { + char *buf; +}; + +#endif NGR_R_SET_RETURN -#ifdef NGR_R_ENT_ARGS -setnetgrent_r(const char *netgroup, NGR_R_ENT_ARGS) +#ifdef NGR_R_SET_ARGS +setnetgrent_r(NGR_R_SET_CONST char *netgroup, NGR_R_SET_ARGS) #else -setnetgrent_r(const char *netgroup) +setnetgrent_r(NGR_R_SET_CONST char *netgroup) #endif { - setnetgrent(netgroup); -#ifdef NGR_R_PRIVATE +#if NGR_R_PRIVATE == 2 + struct private *p; +#endif + char *tmp; +#if defined(NGR_R_SET_ARGS) && NGR_R_PRIVATE == 0 + UNUSED(buf); + UNUSED(buflen); +#endif + + DE_CONST(netgroup, tmp); + setnetgrent(tmp); + +#if NGR_R_PRIVATE == 1 *buf = NULL; +#elif NGR_R_PRIVATE == 2 + *buf = p = malloc(sizeof(struct private)); + if (p == NULL) +#ifdef NGR_R_SET_RESULT + return (NGR_R_BAD); +#else + return; +#endif + p->buf = NULL; #endif #ifdef NGR_R_SET_RESULT return (NGR_R_SET_RESULT); @@ -94,17 +117,29 @@ setnetgrent_r(const char *netgroup) } NGR_R_END_RETURN -#ifdef NGR_R_ENT_ARGS -endnetgrent_r(NGR_R_ENT_ARGS) +#ifdef NGR_R_END_ARGS +endnetgrent_r(NGR_R_END_ARGS) #else endnetgrent_r(void) #endif { +#if NGR_R_PRIVATE == 2 + struct private *p = buf; +#endif +#if defined(NGR_R_SET_ARGS) && NGR_R_PRIVATE == 0 + UNUSED(buf); + UNUSED(buflen); +#endif + endnetgrent(); -#ifdef NGR_R_PRIVATE +#if NGR_R_PRIVATE == 1 if (*buf != NULL) free(*buf); *buf = NULL; +#elif NGR_R_PRIVATE == 2 + if (p->buf != NULL) + free(p->buf); + free(p); #endif NGR_R_END_RESULT(NGR_R_OK); } @@ -112,9 +147,13 @@ endnetgrent_r(void) /* Private */ static int -copy_protoent(char **machinep, char **userp, char **domainp, - const char *mp, const char *up, const char *dp, - NGR_R_COPY_ARGS) { +copy_protoent(NGR_R_CONST char **machinep, NGR_R_CONST char **userp, + NGR_R_CONST char **domainp, const char *mp, const char *up, + const char *dp, NGR_R_COPY_ARGS) +{ +#if NGR_R_PRIVATE == 2 + struct private *p = buf; +#endif char *cp; int n; int len; @@ -124,13 +163,21 @@ copy_protoent(char **machinep, char **userp, char **domainp, if (mp != NULL) len += strlen(mp) + 1; if (up != NULL) len += strlen(up) + 1; if (dp != NULL) len += strlen(dp) + 1; - -#ifdef NGR_R_PRIVATE - free(*buf); + +#if NGR_R_PRIVATE == 1 + if (*buf != NULL) + free(*buf); *buf = malloc(len); if (*buf == NULL) return(NGR_R_BAD); cp = *buf; +#elif NGR_R_PRIVATE == 2 + if (p->buf) + free(p->buf); + p->buf = malloc(len); + if (p->buf == NULL) + return(NGR_R_BAD); + cp = p->buf; #else if (len > (int)buflen) { errno = ERANGE; @@ -139,7 +186,6 @@ copy_protoent(char **machinep, char **userp, char **domainp, cp = buf; #endif - if (mp != NULL) { n = strlen(mp) + 1; strcpy(cp, mp); @@ -170,3 +216,4 @@ copy_protoent(char **machinep, char **userp, char **domainp, static int getnetgrent_r_unknown_system = 0; #endif /* NGR_R_RETURN */ #endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/getprotoent.c b/usr/src/lib/libresolv2/common/irs/getprotoent.c index 9a2b7332e3..1e109f9659 100644 --- a/usr/src/lib/libresolv2/common/irs/getprotoent.c +++ b/usr/src/lib/libresolv2/common/irs/getprotoent.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: getprotoent.c,v 1.16 2001/11/01 07:34:33 marka Exp $"; +static const char rcsid[] = "$Id: getprotoent.c,v 1.4 2005/04/27 04:56:26 sra Exp $"; #endif /* Imports */ @@ -75,34 +68,18 @@ getprotobynumber(int proto) { return (getprotobynumber_p(proto, net_data)); } -#ifdef ORIGINAL_ISC_CODE void -#else -int -#endif setprotoent(int stayopen) { struct net_data *net_data = init(); setprotoent_p(stayopen, net_data); -#ifdef ORIGINAL_ISC_CODE -#else - return (0); -#endif } -#ifdef ORIGINAL_ISC_CODE void -#else -int -#endif endprotoent() { struct net_data *net_data = init(); endprotoent_p(net_data); -#ifdef ORIGINAL_ISC_CODE -#else - return (0); -#endif } /* Shared private. */ @@ -195,3 +172,5 @@ init() { } #endif /*__BIND_NOSTATIC*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/getprotoent_r.c b/usr/src/lib/libresolv2/common/irs/getprotoent_r.c index c8f540d5c1..d5d9ae53b6 100644 --- a/usr/src/lib/libresolv2/common/irs/getprotoent_r.c +++ b/usr/src/lib/libresolv2/common/irs/getprotoent_r.c @@ -1,29 +1,22 @@ /* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1998-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: getprotoent_r.c,v 8.6 2001/11/01 08:02:14 marka Exp $"; +static const char rcsid[] = "$Id: getprotoent_r.c,v 1.6 2006/08/01 01:14:16 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include <port_before.h> @@ -83,7 +76,7 @@ getprotobynumber_r(int proto, struct protoent *pptr, PROTO_R_ARGS) { #endif } -/* +/*% * These assume a single context is in operation per thread. * If this is not the case we will need to call irs directly * rather than through the base functions. @@ -116,6 +109,9 @@ setprotoent_r(int stay_open, PROTO_R_ENT_ARGS) setprotoent_r(int stay_open) #endif { +#ifdef PROTO_R_ENT_UNUSED + PROTO_R_ENT_UNUSED; +#endif setprotoent(stay_open); #ifdef PROTO_R_SET_RESULT return (PROTO_R_SET_RESULT); @@ -129,6 +125,9 @@ endprotoent_r(PROTO_R_ENT_ARGS) endprotoent_r() #endif { +#ifdef PROTO_R_ENT_UNUSED + PROTO_R_ENT_UNUSED; +#endif endprotoent(); PROTO_R_END_RESULT(PROTO_R_OK); } @@ -143,7 +142,7 @@ copy_protoent(struct protoent *pe, struct protoent *pptr, PROTO_R_COPY_ARGS) { int numptr, len; /* Find out the amount of space required to store the answer. */ - numptr = 1; /* NULL ptr */ + numptr = 1; /*%< NULL ptr */ len = (char *)ALIGN(buf) - buf; for (i = 0; pe->p_aliases[i]; i++, numptr++) { len += strlen(pe->p_aliases[i]) + 1; @@ -221,3 +220,4 @@ copy_protoent(struct protoent *pe, struct protoent *pptr, PROTO_R_COPY_ARGS) { static int getprotoent_r_unknown_system = 0; #endif /* PROTO_R_RETURN */ #endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/getpwent.c b/usr/src/lib/libresolv2/common/irs/getpwent.c index 8b4667c716..c70f99e64c 100644 --- a/usr/src/lib/libresolv2/common/irs/getpwent.c +++ b/usr/src/lib/libresolv2/common/irs/getpwent.c @@ -1,29 +1,22 @@ /* - * Copyright (c) 1997-2001 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: getpwent.c,v 1.21 2000/02/21 21:40:56 vixie Exp $"; +static const char rcsid[] = "$Id: getpwent.c,v 1.3 2005/04/27 04:56:26 sra Exp $"; #endif /* Imports */ @@ -43,6 +36,7 @@ static int __bind_irs_pw_unneeded; #include <pwd.h> #include <resolv.h> #include <stdio.h> +#include <string.h> #include <irs.h> @@ -204,3 +198,4 @@ init() { } #endif /* WANT_IRS_PW */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/getpwent_r.c b/usr/src/lib/libresolv2/common/irs/getpwent_r.c index 4e3b8a2578..f754084317 100644 --- a/usr/src/lib/libresolv2/common/irs/getpwent_r.c +++ b/usr/src/lib/libresolv2/common/irs/getpwent_r.c @@ -1,30 +1,22 @@ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1998-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = - "$Id: getpwent_r.c,v 8.6 2001/11/01 08:02:15 marka Exp $"; +static const char rcsid[] = "$Id: getpwent_r.c,v 1.8 2005/04/27 04:56:26 sra Exp $"; #endif /* LIBC_SCCS and not lint */ #include <port_before.h> @@ -40,9 +32,9 @@ static const char rcsid[] = /* turn off solaris remapping in <grp.h> */ #undef _POSIX_PTHREAD_SEMANTICS #include <pwd.h> -#define _POSIX_PTHREAD_SEMANTICS 1 +#define _POSIX_PTHREAD_SEMANTICS 1 #else -#define _UNIX95 1 +#define _UNIX95 1 #include <pwd.h> #endif #else @@ -52,7 +44,7 @@ static const char rcsid[] = #ifdef PASS_R_RETURN -static int +static int copy_passwd(struct passwd *, struct passwd *, char *buf, int buflen); /* POSIX 1003.1c */ @@ -96,7 +88,7 @@ getpwnam_r(const char *login, struct passwd *pwptr, char *buf, int buflen) { #ifdef POSIX_GETPWUID_R int __posix_getpwuid_r(uid_t uid, struct passwd *pwptr, - char *buf, size_t buflen, struct passwd **result) { + char *buf, int buflen, struct passwd **result) { #else int getpwuid_r(uid_t uid, struct passwd *pwptr, @@ -129,7 +121,7 @@ getpwuid_r(uid_t uid, struct passwd *pwptr, char *buf, int buflen) { } #endif -/* +/*% * These assume a single context is in operation per thread. * If this is not the case we will need to call irs directly * rather than through the base functions. @@ -138,7 +130,7 @@ getpwuid_r(uid_t uid, struct passwd *pwptr, char *buf, int buflen) { PASS_R_RETURN getpwent_r(struct passwd *pwptr, PASS_R_ARGS) { struct passwd *pw = getpwent(); - int res; + int res = 0; if (pw == NULL) return (PASS_R_BAD); @@ -192,13 +184,13 @@ endpwent_r(void) PASS_R_RETURN fgetpwent_r(FILE *f, struct passwd *pwptr, PASS_R_COPY_ARGS) { struct passwd *pw = fgetpwent(f); - int res; + int res = 0; if (pw == NULL) return (PASS_R_BAD); res = copy_passwd(pw, pwptr, PASS_R_COPY); - return (res ? PASS_R_BAD : PASS_R_OK); + return (res ? PASS_R_BAD : PASS_R_OK ); } #endif @@ -219,13 +211,13 @@ copy_passwd(struct passwd *pw, struct passwd *pwptr, char *buf, int buflen) { len += strlen(pw->pw_gecos) + 1; len += strlen(pw->pw_dir) + 1; len += strlen(pw->pw_shell) + 1; - + if (len > buflen) { errno = ERANGE; return (ERANGE); } - /* copy fixed atomic values */ + /* copy fixed atomic values*/ pwptr->pw_uid = pw->pw_uid; pwptr->pw_gid = pw->pw_gid; #ifdef HAVE_PW_CHANGE @@ -281,3 +273,4 @@ copy_passwd(struct passwd *pw, struct passwd *pwptr, char *buf, int buflen) { static int getpwent_r_unknown_system = 0; #endif /* PASS_R_RETURN */ #endif /* !def(_REENTRANT) || !def(DO_PTHREADS) || !def(WANT_IRS_PW) */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/getservent.c b/usr/src/lib/libresolv2/common/irs/getservent.c index 395aa2aba6..8de0db3058 100644 --- a/usr/src/lib/libresolv2/common/irs/getservent.c +++ b/usr/src/lib/libresolv2/common/irs/getservent.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: getservent.c,v 1.17 2001/11/01 07:33:16 marka Exp $"; +static const char rcsid[] = "$Id: getservent.c,v 1.4 2005/04/27 04:56:26 sra Exp $"; #endif /* Imports */ @@ -75,34 +68,18 @@ getservbyport(int port, const char *proto) { return (getservbyport_p(port, proto, net_data)); } -#ifdef ORIGINAL_ISC_CODE void -#else -int -#endif setservent(int stayopen) { struct net_data *net_data = init(); setservent_p(stayopen, net_data); -#ifdef ORIGINAL_ISC_CODE -#else - return (0); -#endif } -#ifdef ORIGINAL_ISC_CODE void -#else -int -#endif endservent() { struct net_data *net_data = init(); endservent_p(net_data); -#ifdef ORIGINAL_ISC_CODE -#else - return (0); -#endif } /* Shared private. */ @@ -198,3 +175,5 @@ init() { } #endif /*__BIND_NOSTATIC*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/getservent_r.c b/usr/src/lib/libresolv2/common/irs/getservent_r.c index 8548a85bba..42d1e46163 100644 --- a/usr/src/lib/libresolv2/common/irs/getservent_r.c +++ b/usr/src/lib/libresolv2/common/irs/getservent_r.c @@ -1,29 +1,22 @@ /* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1998-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: getservent_r.c,v 8.5 2001/11/01 08:02:16 marka Exp $"; +static const char rcsid[] = "$Id: getservent_r.c,v 1.6 2006/08/01 01:14:16 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include <port_before.h> @@ -86,7 +79,7 @@ getservbyport_r(int port, const char *proto, #endif } -/* +/*% * These assume a single context is in operation per thread. * If this is not the case we will need to call irs directly * rather than through the base functions. @@ -119,7 +112,9 @@ setservent_r(int stay_open, SERV_R_ENT_ARGS) setservent_r(int stay_open) #endif { - +#ifdef SERV_R_ENT_UNUSED + SERV_R_ENT_UNUSED; +#endif setservent(stay_open); #ifdef SERV_R_SET_RESULT return (SERV_R_SET_RESULT); @@ -133,7 +128,9 @@ endservent_r(SERV_R_ENT_ARGS) endservent_r() #endif { - +#ifdef SERV_R_ENT_UNUSED + SERV_R_ENT_UNUSED; +#endif endservent(); SERV_R_END_RESULT(SERV_R_OK); } @@ -148,7 +145,7 @@ copy_servent(struct servent *se, struct servent *sptr, SERV_R_COPY_ARGS) { int numptr, len; /* Find out the amount of space required to store the answer. */ - numptr = 1; /* NULL ptr */ + numptr = 1; /*%< NULL ptr */ len = (char *)ALIGN(buf) - buf; for (i = 0; se->s_aliases[i]; i++, numptr++) { len += strlen(se->s_aliases[i]) + 1; @@ -201,8 +198,8 @@ copy_servent(struct servent *se, struct servent *sptr, SERV_R_COPY_ARGS) { sptr->s_port = se->s_port; /* copy official name */ - cp = ndptr->line; - eob = ndptr->line + sizeof(ndptr->line); + cp = sdptr->line; + eob = sdptr->line + sizeof(sdptr->line); if ((n = strlen(se->s_name) + 1) < (eob - cp)) { strcpy(cp, se->s_name); sptr->s_name = cp; @@ -213,7 +210,7 @@ copy_servent(struct servent *se, struct servent *sptr, SERV_R_COPY_ARGS) { /* copy aliases */ i = 0; - sptr->s_aliases = ndptr->serv_aliases; + sptr->s_aliases = sdptr->serv_aliases; while (se->s_aliases[i] && i < (_MAXALIASES-1)) { if ((n = strlen(se->s_aliases[i]) + 1) < (eob - cp)) { strcpy(cp, se->s_aliases[i]); @@ -242,3 +239,4 @@ copy_servent(struct servent *se, struct servent *sptr, SERV_R_COPY_ARGS) { static int getservent_r_unknown_system = 0; #endif /*SERV_R_RETURN */ #endif /* !defined(_REENTRANT) || !defined(DO_PTHREADS) */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/hesiod.c b/usr/src/lib/libresolv2/common/irs/hesiod.c index 74c76bb879..80d669dbe0 100644 --- a/usr/src/lib/libresolv2/common/irs/hesiod.c +++ b/usr/src/lib/libresolv2/common/irs/hesiod.c @@ -1,41 +1,34 @@ -/* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: hesiod.c,v 1.23 2002/07/18 02:07:45 marka Exp $"; +static const char rcsid[] = "$Id: hesiod.c,v 1.7 2005/07/28 06:51:48 marka Exp $"; #endif /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * This file is primarily maintained by <tytso@mit.edu> and <ghudson@mit.edu>. - */ -/* +/*! \file + * \brief * hesiod.c --- the core portion of the hesiod resolver. * * This file is derived from the hesiod library from Project Athena; * It has been extensively rewritten by Theodore Ts'o to have a more * thread-safe interface. + * \author + * This file is primarily maintained by <tytso@mit.edu> and <ghudson@mit.edu>. */ /* Imports */ @@ -76,7 +69,7 @@ static int init(struct hesiod_p *ctx); /* Public */ -/* +/*% * This function is called to initialize a hesiod_p. */ int @@ -90,32 +83,21 @@ hesiod_init(void **context) { return (-1); } -#ifdef ORIGINAL_ISC_CODE - ctx->LHS = NULL; - ctx->RHS = NULL; - ctx->res = NULL; -#else memset(ctx, 0, sizeof (*ctx)); -#endif /* ORIGINAL_ISC_CODE */ if (parse_config_file(ctx, _PATH_HESIOD_CONF) < 0) { #ifdef DEF_RHS /* * Use compiled in defaults. */ - ctx->LHS = malloc(strlen(DEF_LHS)+1); - ctx->RHS = malloc(strlen(DEF_RHS)+1); - if (ctx->LHS == 0 || ctx->RHS == 0) { + ctx->LHS = malloc(strlen(DEF_LHS) + 1); + ctx->RHS = malloc(strlen(DEF_RHS) + 1); + if (ctx->LHS == NULL || ctx->RHS == NULL) { errno = ENOMEM; goto cleanup; } -#ifdef HAVE_STRLCPY - strlcpy(ctx->LHS, DEF_LHS, strlen(DEF_LHS) + 1); - strlcpy(ctx->RHS, DEF_RHS, strlen(DEF_RHS) + 1); -#else - strcpy(ctx->LHS, DEF_LHS); - strcpy(ctx->RHS, DEF_RHS); -#endif + strcpy(ctx->LHS, DEF_LHS); /* (checked) */ + strcpy(ctx->RHS, DEF_RHS); /* (checked) */ #else goto cleanup; #endif @@ -134,22 +116,10 @@ hesiod_init(void **context) { goto cleanup; } if (cp[0] == '.') { -#ifdef HAVE_STRLCPY - strlcpy(ctx->RHS, cp, RHSlen); -#else - strcpy(ctx->RHS, cp); -#endif + strcpy(ctx->RHS, cp); /* (checked) */ } else { -#ifdef HAVE_STRLCPY - strlcpy(ctx->RHS, ".", RHSlen); -#else - strcpy(ctx->RHS, "."); -#endif -#ifdef HAVE_STRLCAT - strlcat(ctx->RHS, cp, RHSlen); -#else - strcat(ctx->RHS, cp); -#endif + strcpy(ctx->RHS, "."); /* (checked) */ + strcat(ctx->RHS, cp); /* (checked) */ } } @@ -175,7 +145,7 @@ hesiod_init(void **context) { return (-1); } -/* +/*% * This function deallocates the hesiod_p */ void @@ -195,7 +165,7 @@ hesiod_end(void *context) { errno = save_errno; } -/* +/*% * This function takes a hesiod (name, type) and returns a DNS * name which is to be resolved. */ @@ -254,7 +224,7 @@ hesiod_to_bind(void *context, const char *name, const char *type) { return (bindname); } -/* +/*% * This is the core function. Given a hesiod (name, type), it * returns an array of strings returned by the resolver. */ @@ -295,7 +265,7 @@ hesiod_free_list(void *context, char **list) { free(list); } -/* +/*% * This function parses the /etc/hesiod.conf file */ static int @@ -365,17 +335,17 @@ parse_config_file(struct hesiod_p *ctx, const char *filename) { return (-1); } -/* +/*% * Given a DNS class and a DNS name, do a lookup for TXT records, and * return a list of them. */ static char ** get_txt_records(struct hesiod_p *ctx, int class, const char *name) { struct { - int type; /* RR type */ - int class; /* RR class */ - int dlen; /* len of data section */ - u_char *data; /* pointer to data */ + int type; /*%< RR type */ + int class; /*%< RR class */ + int dlen; /*%< len of data section */ + u_char *data; /*%< pointer to data */ } rr; HEADER *hp; u_char qbuf[MAX_HESRESP], abuf[MAX_HESRESP]; @@ -442,7 +412,7 @@ get_txt_records(struct hesiod_p *ctx, int class, const char *name) { rr.type = ns_get16(cp); cp += INT16SZ; rr.class = ns_get16(cp); - cp += INT16SZ + INT32SZ; /* skip the ttl, too */ + cp += INT16SZ + INT32SZ; /*%< skip the ttl, too */ rr.dlen = ns_get16(cp); cp += INT16SZ; if (cp + rr.dlen > eom) { @@ -527,7 +497,7 @@ init(struct hesiod_p *ctx) { if (!ctx->res && !__hesiod_res_get(ctx)) return (-1); - if (((ctx->res->options & RES_INIT) == 0) && + if (((ctx->res->options & RES_INIT) == 0U) && (res_ninit(ctx->res) == -1)) return (-1); diff --git a/usr/src/lib/libresolv2/common/irs/hesiod_p.h b/usr/src/lib/libresolv2/common/irs/hesiod_p.h index 7a9b68bc35..99da15d0cd 100644 --- a/usr/src/lib/libresolv2/common/irs/hesiod_p.h +++ b/usr/src/lib/libresolv2/common/irs/hesiod_p.h @@ -1,49 +1,42 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * This file is primarily maintained by <tytso@mit.edu> and <ghudson@mit.edu>. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* - * $Id: hesiod_p.h,v 1.9 1999/01/08 19:24:39 vixie Exp $ - */ - -/* - * hesiod_p.h -- private definitions for the hesiod library + * $Id: hesiod_p.h,v 1.3 2005/04/27 04:56:27 sra Exp $ */ #ifndef _HESIOD_P_H_INCLUDED #define _HESIOD_P_H_INCLUDED -#define DEF_RHS ".Athena.MIT.EDU" /* Defaults if HESIOD_CONF */ -#define DEF_LHS ".ns" /* file is not */ - /* present. */ +/** \file + * \brief + * hesiod_p.h -- private definitions for the hesiod library. + * + * \author + * This file is primarily maintained by tytso@mit.edu and ghudson@mit.edu. + */ + +#define DEF_RHS ".Athena.MIT.EDU" /*%< Defaults if HESIOD_CONF */ +#define DEF_LHS ".ns" /*%< file is not */ + /*%< present. */ struct hesiod_p { - char * LHS; /* normally ".ns" */ - char * RHS; /* AKA the default hesiod domain */ - struct __res_state * res; /* resolver context */ + char * LHS; /*%< normally ".ns" */ + char * RHS; /*%< AKA the default hesiod domain */ + struct __res_state * res; /*%< resolver context */ void (*free_res)(void *); void (*res_set)(struct hesiod_p *, struct __res_state *, void (*)(void *)); diff --git a/usr/src/lib/libresolv2/common/irs/irp.c b/usr/src/lib/libresolv2/common/irs/irp.c index ceb17b735c..ef10631c22 100644 --- a/usr/src/lib/libresolv2/common/irs/irp.c +++ b/usr/src/lib/libresolv2/common/irs/irp.c @@ -1,29 +1,22 @@ /* - * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Copyright (c) 1996, 1998 by Internet Software Consortium. + * Copyright (C) 2004-2006, 2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1996, 1998-2001, 2003 Internet Software Consortium. * - * Permission to use, copy, modify, and distribute this software for any + * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: irp.c,v 8.8 2001/09/25 04:50:29 marka Exp $"; +static const char rcsid[] = "$Id: irp.c,v 1.12 2008/11/14 02:36:51 marka Exp $"; #endif /* Imports */ @@ -73,7 +66,7 @@ static void irp_close(struct irs_acc *); /* send errors to syslog if true. */ int irp_log_errors = 1; -/* +/*% * This module handles the irp module connection to irpd. * * The client expects a synchronous interface to functions like @@ -81,7 +74,7 @@ int irp_log_errors = 1; * the wire (it's used in the server). */ -/* +/*% * irs_acc *irs_irp_acc(const char *options); * * Initialize the irp module. @@ -144,8 +137,7 @@ irs_irp_connection_setup(struct irp_p *cxndata, int *warned) { return (0); } - -/* +/*% * int irs_irp_connect(void); * * Sets up the connection to the remote irpd server. @@ -252,9 +244,7 @@ irs_irp_connect(struct irp_p *pvt) { return (0); } - - -/* +/*% * int irs_irp_is_connected(struct irp_p *pvt); * * Returns: @@ -268,9 +258,7 @@ irs_irp_is_connected(struct irp_p *pvt) { return (pvt->fdCxn >= 0); } - - -/* +/*% * void * irs_irp_disconnect(struct irp_p *pvt); * @@ -362,11 +350,7 @@ irs_irp_read_line(struct irp_p *pvt, char *buffer, int len) { return (buffpos); } - - - - -/* +/*% * int irp_read_response(struct irp_p *pvt); * * Returns: @@ -394,7 +378,7 @@ irs_irp_read_response(struct irp_p *pvt, char *text, size_t textlen) { if (sscanf(line, "%d", &code) != 1) { code = 0; - } else if (text != NULL && textlen > 0) { + } else if (text != NULL && textlen > 0U) { p = line; while (isspace((unsigned char)*p)) p++; while (isdigit((unsigned char)*p)) p++; @@ -406,9 +390,7 @@ irs_irp_read_response(struct irp_p *pvt, char *text, size_t textlen) { return (code); } - - -/* +/*% * char *irp_read_body(struct irp_p *pvt, size_t *size); * * Read in the body of a response. Terminated by a line with @@ -432,6 +414,9 @@ irs_irp_read_body(struct irp_p *pvt, size_t *size) { char *buffer = memget(len); int idx = 0; + if (buffer == NULL) + return (NULL); + for (;;) { if (irs_irp_read_line(pvt, line, sizeof line) <= 0 || strchr(line, '\n') == NULL) @@ -475,8 +460,7 @@ irs_irp_read_body(struct irp_p *pvt, size_t *size) { return (NULL); } - -/* +/*% * int irs_irp_get_full_response(struct irp_p *pvt, int *code, * char **body, size_t *bodylen); * @@ -519,12 +503,11 @@ irs_irp_get_full_response(struct irp_p *pvt, int *code, char *text, return (0); } - -/* +/*% * int irs_irp_send_command(struct irp_p *pvt, const char *fmt, ...); * * Sends command to remote connected via the PVT - * struture. FMT and args after it are fprintf-like + * structure. FMT and args after it are fprintf-like * arguments for formatting. * * Returns: @@ -545,7 +528,8 @@ irs_irp_send_command(struct irp_p *pvt, const char *fmt, ...) { } va_start(ap, fmt); - todo = vsprintf(buffer, fmt, ap); + (void) vsprintf(buffer, fmt, ap); + todo = strlen(buffer); va_end(ap); if (todo > (int)sizeof(buffer) - 3) { syslog(LOG_CRIT, "memory overrun in irs_irp_send_command()"); @@ -576,9 +560,7 @@ irs_irp_send_command(struct irp_p *pvt, const char *fmt, ...) { /* Methods */ - - -/* +/*% * void irp_close(struct irs_acc *this) * */ @@ -597,3 +579,5 @@ irp_close(struct irs_acc *this) { + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/irp_gr.c b/usr/src/lib/libresolv2/common/irs/irp_gr.c index e77468af7e..1f40e76022 100644 --- a/usr/src/lib/libresolv2/common/irs/irp_gr.c +++ b/usr/src/lib/libresolv2/common/irs/irp_gr.c @@ -1,29 +1,22 @@ /* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright(c) 1996, 1998 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: irp_gr.c,v 8.3 2001/05/29 05:48:57 marka Exp $"; +static const char rcsid[] = "$Id: irp_gr.c,v 1.4 2005/04/27 04:56:27 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* extern */ @@ -61,16 +54,17 @@ static int __bind_irs_gr_unneeded; /* Types. */ -/* +/*! \file + * \brief * Module for the getnetgrent(3) family to use when connected to a * remote irp daemon. - * + * \brief * See irpd.c for justification of caching done here. * */ struct pvt { - struct irp_p *girpdata; /* global IRP data */ + struct irp_p *girpdata; /*%< global IRP data */ int warned; struct group group; }; @@ -90,21 +84,9 @@ static void free_group(struct group *gr); /* Public. */ - - - - -/* - * struct irs_gr * irs_irp_gr(struct irs_acc *this) - * - * Notes: - * +/*% * Initialize the group sub-module. * - * Notes: - * - * Module data. - * */ struct irs_gr * @@ -139,13 +121,7 @@ irs_irp_gr(struct irs_acc *this) { /* Methods. */ - - -/* - * void gr_close(struct irs_gr *this) - * - * Notes: - * +/*% * Close the sub-module. * */ @@ -160,14 +136,7 @@ gr_close(struct irs_gr *this) { memput(this, sizeof *this); } - - - -/* - * struct group * gr_next(struct irs_gr *this) - * - * Notes: - * +/*% * Gets the next group out of the cached data and returns it. * */ @@ -214,15 +183,7 @@ gr_next(struct irs_gr *this) { return (gr); } - - - - -/* - * struct group * gr_byname(struct irs_gr *this, const char *name) - * - * Notes: - * +/*% * Gets a group by name from irpd and returns it. * */ @@ -270,15 +231,7 @@ gr_byname(struct irs_gr *this, const char *name) { return (gr); } - - - - -/* - * struct group * gr_bygid(struct irs_gr *this, gid_t gid) - * - * Notes: - * +/*% * Gets a group by gid from irpd and returns it. * */ @@ -325,10 +278,7 @@ gr_bygid(struct irs_gr *this, gid_t gid) { return (gr); } - - - -/* +/*% * void gr_rewind(struct irs_gr *this) * */ @@ -357,14 +307,7 @@ gr_rewind(struct irs_gr *this) { return; } - - - -/* - * void gr_minimize(struct irs_gr *this) - * - * Notes: - * +/*% * Frees up cached data and disconnects(if necessary) from the remote. * */ @@ -379,9 +322,7 @@ gr_minimize(struct irs_gr *this) { /* Private. */ - - -/* +/*% * static void free_group(struct group *gr); * * Deallocate all the memory irp_unmarshall_gr allocated. @@ -413,3 +354,4 @@ free_group(struct group *gr) { #endif /* WANT_IRS_GR */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/irp_ho.c b/usr/src/lib/libresolv2/common/irs/irp_ho.c index 12a03edd1b..d4ce5c3bbe 100644 --- a/usr/src/lib/libresolv2/common/irs/irp_ho.c +++ b/usr/src/lib/libresolv2/common/irs/irp_ho.c @@ -1,29 +1,22 @@ /* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996,1998 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: irp_ho.c,v 8.3 2001/05/29 05:48:59 marka Exp $"; +static const char rcsid[] = "$Id: irp_ho.c,v 1.3 2005/04/27 04:56:28 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports. */ @@ -91,9 +84,7 @@ static struct addrinfo * ho_addrinfo(struct irs_ho *this, const char *name, /* Public. */ - - -/* +/*% * struct irs_ho * irs_irp_ho(struct irs_acc *this) * * Notes: @@ -136,13 +127,7 @@ irs_irp_ho(struct irs_acc *this) { /* Methods. */ - - -/* - * void ho_close(struct irs_ho *this) - * - * Notes: - * +/*% * Closes down the module. * */ @@ -288,15 +273,7 @@ ho_byaddr(struct irs_ho *this, const void *addr, int len, int af) { return (ho); } - - - - -/* - * struct hostent * ho_next(struct irs_ho *this) - * - * Notes: - * +/*% * The implementation for gethostent(3). The first time it's * called all the data is pulled from the remote(i.e. what * the maximum number of gethostent(3) calls would return) @@ -343,11 +320,7 @@ ho_next(struct irs_ho *this) { return (ho); } - - - - -/* +/*% * void ho_rewind(struct irs_ho *this) * */ @@ -376,10 +349,7 @@ ho_rewind(struct irs_ho *this) { return; } - - - -/* +/*% * void ho_minimize(struct irs_ho *this) * */ @@ -393,10 +363,7 @@ ho_minimize(struct irs_ho *this) { irs_irp_disconnect(pvt->girpdata); } - - - -/* +/*% * void free_host(struct hostent *ho) * */ @@ -434,3 +401,5 @@ ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) UNUSED(pai); return(NULL); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/irp_ng.c b/usr/src/lib/libresolv2/common/irs/irp_ng.c index d585e636a0..1af862cab4 100644 --- a/usr/src/lib/libresolv2/common/irs/irp_ng.c +++ b/usr/src/lib/libresolv2/common/irs/irp_ng.c @@ -1,29 +1,22 @@ /* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996, 1998 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: irp_ng.c,v 8.3 2001/05/29 05:49:00 marka Exp $"; +static const char rcsid[] = "$Id: irp_ng.c,v 1.4 2006/12/07 04:46:27 marka Exp $"; #endif /* Imports */ @@ -69,13 +62,7 @@ static void ng_minimize(struct irs_ng *); /* Public */ - - -/* - * struct irs_ng * irs_irp_ng(struct irs_acc *this) - * - * Notes: - * +/*% * Intialize the irp netgroup module. * */ @@ -162,15 +149,7 @@ ng_rewind(struct irs_ng *this, const char *group) { return; } - - - /* - * int ng_next(struct irs_ng *this, const char **host, const char **user, - * const char **domain) - * - * Notes: - * * Get the next netgroup item from the cache. * */ @@ -212,14 +191,7 @@ ng_next(struct irs_ng *this, const char **host, const char **user, return (rval); } - - /* - * int ng_test(struct irs_ng *this, const char *name, const char *host, - * const char *user, const char *domain) - * - * Notes: - * * Search for a match in a netgroup. * */ @@ -246,14 +218,14 @@ ng_test(struct irs_ng *this, const char *name, } if (irs_irp_send_command(pvt->girpdata, "innetgr %s", body) == 0) { - memput(body, bodylen); - code = irs_irp_read_response(pvt->girpdata, text, sizeof text); if (code == IRPD_GETNETGR_MATCHES) { rval = 1; } } + memput(body, bodylen); + return (rval); } @@ -277,3 +249,5 @@ ng_minimize(struct irs_ng *this) { /* Private */ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/irp_nw.c b/usr/src/lib/libresolv2/common/irs/irp_nw.c index 7c18f4cbac..eb4654f9b9 100644 --- a/usr/src/lib/libresolv2/common/irs/irp_nw.c +++ b/usr/src/lib/libresolv2/common/irs/irp_nw.c @@ -1,29 +1,22 @@ /* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996,1998 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: irp_nw.c,v 8.1 1999/01/18 07:46:54 vixie Exp $"; +static const char rcsid[] = "$Id: irp_nw.c,v 1.4 2006/03/09 23:57:56 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #if 0 @@ -86,9 +79,7 @@ static void free_nw(struct nwent *nw); /* Public */ - - -/* +/*% * struct irs_nw * irs_irp_nw(struct irs_acc *this) * */ @@ -124,9 +115,7 @@ irs_irp_nw(struct irs_acc *this) { /* Methods */ - - -/* +/*% * void nw_close(struct irs_nw *this) * */ @@ -143,10 +132,7 @@ nw_close(struct irs_nw *this) { memput(this, sizeof *this); } - - - -/* +/*% * struct nwent * nw_byaddr(struct irs_nw *this, void *net, * int length, int type) * @@ -159,7 +145,7 @@ nw_byaddr(struct irs_nw *this, void *net, int length, int type) { char *body = NULL; size_t bodylen; int code; - char paddr[24]; /* bigenough for ip4 w/ cidr spec. */ + char paddr[24]; /*%< bigenough for ip4 w/ cidr spec. */ char text[256]; if (inet_net_ntop(type, net, length, paddr, sizeof paddr) == NULL) { @@ -196,10 +182,7 @@ nw_byaddr(struct irs_nw *this, void *net, int length, int type) { return (nw); } - - - -/* +/*% * struct nwent * nw_byname(struct irs_nw *this, const char *name, int type) * */ @@ -248,10 +231,7 @@ nw_byname(struct irs_nw *this, const char *name, int type) { return (nw); } - - - -/* +/*% * void nw_rewind(struct irs_nw *this) * */ @@ -280,16 +260,7 @@ nw_rewind(struct irs_nw *this) { return; } - - - - - -/* - * struct nwent * nw_next(struct irs_nw *this) - * - * Notes: - * +/*% * Prepares the cache if necessary and returns the first, or * next item from it. */ @@ -326,15 +297,12 @@ nw_next(struct irs_nw *this) { nw = NULL; } + if (body != NULL) + memput(body, bodylen); return (nw); } - - - - - -/* +/*% * void nw_minimize(struct irs_nw *this) * */ @@ -351,11 +319,7 @@ nw_minimize(struct irs_nw *this) { /* private. */ - - -/* - * static void free_passwd(struct passwd *pw); - * +/*% * deallocate all the memory irp_unmarshall_pw allocated. * */ @@ -380,3 +344,5 @@ free_nw(struct nwent *nw) { if (nw->n_addr != NULL) free(nw->n_addr); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/irp_p.h b/usr/src/lib/libresolv2/common/irs/irp_p.h index 0527d85d8e..4f943f81bd 100644 --- a/usr/src/lib/libresolv2/common/irs/irp_p.h +++ b/usr/src/lib/libresolv2/common/irs/irp_p.h @@ -1,41 +1,33 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* - * $Id: irp_p.h,v 8.3 2003/04/29 01:26:06 marka Exp $ + * $Id: irp_p.h,v 1.5 2005/04/27 04:56:28 sra Exp $ */ #ifndef _IRP_P_H_INCLUDED #define _IRP_P_H_INCLUDED -#pragma ident "%Z%%M% %I% %E% SMI" - #include <stdio.h> struct irp_p { char inbuffer[1024]; - int inlast; /* index of one past the last char in buffer */ - int incurr; /* index of the next char to be read from buffer */ - + int inlast; /*%< index of one past the last char in buffer */ + int incurr; /*%< index of the next char to be read from buffer */ int fdCxn; }; @@ -64,3 +56,5 @@ int irs_irp_get_full_response(struct irp_p *pvt, int *code, extern int irp_log_errors; #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/irp_pr.c b/usr/src/lib/libresolv2/common/irs/irp_pr.c index e72f6c2fe4..ea876e8281 100644 --- a/usr/src/lib/libresolv2/common/irs/irp_pr.c +++ b/usr/src/lib/libresolv2/common/irs/irp_pr.c @@ -1,29 +1,22 @@ /* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: irp_pr.c,v 8.1 1999/01/18 07:46:54 vixie Exp $"; +static const char rcsid[] = "$Id: irp_pr.c,v 1.3 2005/04/27 04:56:29 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* extern */ @@ -76,9 +69,7 @@ static void free_proto(struct protoent *pr); /* Public */ - - -/* +/*% * struct irs_pr * irs_irp_pr(struct irs_acc *this) * */ @@ -114,9 +105,7 @@ irs_irp_pr(struct irs_acc *this) { /* Methods */ - - -/* +/*% * void pr_close(struct irs_pr *this) * */ @@ -133,9 +122,7 @@ pr_close(struct irs_pr *this) { memput(this, sizeof *this); } - - -/* +/*% * struct protoent * pr_byname(struct irs_pr *this, const char *name) * */ @@ -184,9 +171,7 @@ pr_byname(struct irs_pr *this, const char *name) { return (pr); } - - -/* +/*% * struct protoent * pr_bynumber(struct irs_pr *this, int proto) * */ @@ -235,10 +220,7 @@ pr_bynumber(struct irs_pr *this, int proto) { return (pr); } - - - -/* +/*% * void pr_rewind(struct irs_pr *this) * */ @@ -267,14 +249,7 @@ pr_rewind(struct irs_pr *this) { return; } - - - -/* - * struct protoent * pr_next(struct irs_pr *this) - * - * Notes: - * +/*% * Prepares the cache if necessary and returns the next item in it. * */ @@ -318,10 +293,7 @@ pr_next(struct irs_pr *this) { return (pr); } - - - -/* +/*% * void pr_minimize(struct irs_pr *this) * */ @@ -333,14 +305,7 @@ pr_minimize(struct irs_pr *this) { irs_irp_disconnect(pvt->girpdata); } - - - - - -/* - * static void free_proto(struct protoent *pw); - * +/*% * Deallocate all the memory irp_unmarshall_pr allocated. * */ @@ -358,3 +323,5 @@ free_proto(struct protoent *pr) { for (p = pr->p_aliases ; p != NULL && *p != NULL ; p++) free(*p); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/irp_pw.c b/usr/src/lib/libresolv2/common/irs/irp_pw.c index aa6fcbcbce..3722e5974d 100644 --- a/usr/src/lib/libresolv2/common/irs/irp_pw.c +++ b/usr/src/lib/libresolv2/common/irs/irp_pw.c @@ -1,29 +1,22 @@ /* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: irp_pw.c,v 8.2 2001/11/01 07:29:26 marka Exp $"; +static const char rcsid[] = "$Id: irp_pw.c,v 1.4 2005/04/27 04:56:29 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* Extern */ @@ -62,9 +55,9 @@ static int __bind_irs_pw_unneeded; /* Types */ struct pvt { - struct irp_p *girpdata; /* global IRP data */ + struct irp_p *girpdata; /*%< global IRP data */ int warned; - struct passwd passwd; /* password structure */ + struct passwd passwd; /*%< password structure */ }; /* Forward */ @@ -111,9 +104,7 @@ irs_irp_pw(struct irs_acc *this) { /* Methods */ - - -/* +/*% * void pw_close(struct irs_pw *this) * */ @@ -130,10 +121,7 @@ pw_close(struct irs_pw *this) { memput(this, sizeof *this); } - - - -/* +/*% * struct passwd * pw_next(struct irs_pw *this) * */ @@ -177,10 +165,7 @@ pw_next(struct irs_pw *this) { return (pw); } - - - -/* +/*% * struct passwd * pw_byname(struct irs_pw *this, const char *name) * */ @@ -228,10 +213,7 @@ pw_byname(struct irs_pw *this, const char *name) { return (pw); } - - - -/* +/*% * struct passwd * pw_byuid(struct irs_pw *this, uid_t uid) * */ @@ -279,10 +261,7 @@ pw_byuid(struct irs_pw *this, uid_t uid) { return (pw); } - - - -/* +/*% * void pw_rewind(struct irs_pw *this) * */ @@ -311,8 +290,7 @@ pw_rewind(struct irs_pw *this) { return; } - -/* +/*% * void pw_minimize(struct irs_pw *this) * */ @@ -327,11 +305,7 @@ pw_minimize(struct irs_pw *this) { /* Private. */ - - -/* - * static void free_passwd(struct passwd *pw); - * +/*% * Deallocate all the memory irp_unmarshall_pw allocated. * */ @@ -363,3 +337,4 @@ free_passwd(struct passwd *pw) { } #endif /* WANT_IRS_PW */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/irp_sv.c b/usr/src/lib/libresolv2/common/irs/irp_sv.c index 144ae5a7fc..577e697fe6 100644 --- a/usr/src/lib/libresolv2/common/irs/irp_sv.c +++ b/usr/src/lib/libresolv2/common/irs/irp_sv.c @@ -1,29 +1,22 @@ /* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996,1998 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: irp_sv.c,v 8.1 1999/01/18 07:46:54 vixie Exp $"; +static const char rcsid[] = "$Id: irp_sv.c,v 1.3 2005/04/27 04:56:29 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* extern */ @@ -80,9 +73,7 @@ static void free_service(struct servent *sv); /* Public */ - - -/* +/*% * struct irs_sv * irs_irp_sv(struct irs_acc *this) * */ @@ -119,9 +110,7 @@ irs_irp_sv(struct irs_acc *this) { /* Methods */ - - -/* +/*% * void sv_close(struct irs_sv *this) * */ @@ -138,14 +127,7 @@ sv_close(struct irs_sv *this) { memput(this, sizeof *this); } - - - -/* - * struct servent * sv_next(struct irs_sv *this) - * - * Notes: - * +/*% * Fills the cache if necessary and returns the next item from it. * */ @@ -189,10 +171,7 @@ sv_next(struct irs_sv *this) { return (sv); } - - - -/* +/*% * struct servent * sv_byname(struct irs_sv *this, const char *name, * const char *proto) * @@ -243,10 +222,7 @@ sv_byname(struct irs_sv *this, const char *name, const char *proto) { return (sv); } - - - -/* +/*% * struct servent * sv_byport(struct irs_sv *this, int port, * const char *proto) * @@ -298,11 +274,7 @@ sv_byport(struct irs_sv *this, int port, const char *proto) { return (sv); } - - - - -/* +/*% * void sv_rewind(struct irs_sv *this) * */ @@ -331,11 +303,7 @@ sv_rewind(struct irs_sv *this) { return; } - - - - -/* +/*% * void sv_minimize(struct irs_sv *this) * */ @@ -374,3 +342,5 @@ free_service(struct servent *sv) { } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/irpmarshall.c b/usr/src/lib/libresolv2/common/irs/irpmarshall.c index dfeb984262..85ffff1866 100644 --- a/usr/src/lib/libresolv2/common/irs/irpmarshall.c +++ b/usr/src/lib/libresolv2/common/irs/irpmarshall.c @@ -1,9 +1,4 @@ /* - * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* * Copyright(c) 1989, 1993, 1995 * The Regents of the University of California. All rights reserved. * @@ -37,26 +32,24 @@ */ /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: irpmarshall.c,v 8.7 2001/05/29 05:49:01 marka Exp $"; +static const char rcsid[] = "$Id: irpmarshall.c,v 1.7 2006/03/09 23:57:56 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #if 0 @@ -125,15 +118,14 @@ static const char *COLONSTR = ":"; #ifdef WANT_IRS_PW /* +++++++++++++++++++++++++ struct passwd +++++++++++++++++++++++++ */ - -/* +/*% * int irp_marshall_pw(const struct passwd *pw, char **buffer, size_t *len) * - * notes: + * notes: \li * - * See above + * See irpmarshall.h * - * return: + * return: \li * * 0 on sucess, -1 on failure. * @@ -141,7 +133,7 @@ static const char *COLONSTR = ":"; int irp_marshall_pw(const struct passwd *pw, char **buffer, size_t *len) { - size_t need = 1 ; /* for null byte */ + size_t need = 1 ; /*%< for null byte */ char pwUid[24]; char pwGid[24]; char pwChange[24]; @@ -177,7 +169,7 @@ irp_marshall_pw(const struct passwd *pw, char **buffer, size_t *len) { pwClass = ""; #endif - need += strlen(pw->pw_name) + 1; /* one for fieldsep */ + need += strlen(pw->pw_name) + 1; /*%< one for fieldsep */ need += strlen(pw->pw_passwd) + 1; need += strlen(pwUid) + 1; need += strlen(pwGid) + 1; @@ -199,7 +191,7 @@ irp_marshall_pw(const struct passwd *pw, char **buffer, size_t *len) { } if (*buffer == NULL) { - need += 2; /* for CRLF */ + need += 2; /*%< for CRLF */ *buffer = memget(need); if (*buffer == NULL) { errno = ENOMEM; @@ -223,18 +215,14 @@ irp_marshall_pw(const struct passwd *pw, char **buffer, size_t *len) { return (0); } - - - - -/* +/*% * int irp_unmarshall_pw(struct passwd *pw, char *buffer) * - * notes: + * notes: \li * - * see above + * See irpmarshall.h * - * return: + * return: \li * * 0 on success, -1 on failure * @@ -265,7 +253,7 @@ irp_unmarshall_pw(struct passwd *pw, char *buffer) { /* pw_passwd field */ pass = NULL; - if (getfield(&pass, 0, &p, fieldsep) == NULL) { /* field can be empty */ + if (getfield(&pass, 0, &p, fieldsep) == NULL) { /*%< field can be empty */ goto error; } @@ -278,10 +266,10 @@ irp_unmarshall_pw(struct passwd *pw, char *buffer) { } t = strtol(tmpbuf, &tb, 10); if (*tb) { - goto error; /* junk in value */ + goto error; /*%< junk in value */ } pwuid = (uid_t)t; - if ((long) pwuid != t) { /* value must have been too big. */ + if ((long) pwuid != t) { /*%< value must have been too big. */ goto error; } @@ -295,10 +283,10 @@ irp_unmarshall_pw(struct passwd *pw, char *buffer) { } t = strtol(tmpbuf, &tb, 10); if (*tb) { - goto error; /* junk in value */ + goto error; /*%< junk in value */ } pwgid = (gid_t)t; - if ((long)pwgid != t) { /* value must have been too big. */ + if ((long)pwgid != t) { /*%< value must have been too big. */ goto error; } @@ -320,10 +308,10 @@ irp_unmarshall_pw(struct passwd *pw, char *buffer) { } t = strtol(tmpbuf, &tb, 10); if (*tb) { - goto error; /* junk in value */ + goto error; /*%< junk in value */ } pwchange = (time_t)t; - if ((long)pwchange != t) { /* value must have been too big. */ + if ((long)pwchange != t) { /*%< value must have been too big. */ goto error; } @@ -337,10 +325,10 @@ irp_unmarshall_pw(struct passwd *pw, char *buffer) { } t = strtol(tmpbuf, &tb, 10); if (*tb) { - goto error; /* junk in value */ + goto error; /*%< junk in value */ } pwexpire = (time_t)t; - if ((long) pwexpire != t) { /* value must have been too big. */ + if ((long) pwexpire != t) { /*%< value must have been too big. */ goto error; } @@ -404,28 +392,23 @@ irp_unmarshall_pw(struct passwd *pw, char *buffer) { /* ------------------------- struct passwd ------------------------- */ #endif /* WANT_IRS_PW */ - - - /* +++++++++++++++++++++++++ struct group +++++++++++++++++++++++++ */ - - -/* +/*% * int irp_marshall_gr(const struct group *gr, char **buffer, size_t *len) * - * notes: + * notes: \li * - * see above. + * See irpmarshall.h. * - * return: + * return: \li * * 0 on success, -1 on failure */ int irp_marshall_gr(const struct group *gr, char **buffer, size_t *len) { - size_t need = 1; /* for null byte */ + size_t need = 1; /*%< for null byte */ char grGid[24]; const char *fieldsep = COLONSTR; @@ -456,7 +439,7 @@ irp_marshall_gr(const struct group *gr, char **buffer, size_t *len) { } if (*buffer == NULL) { - need += 2; /* for CRLF */ + need += 2; /*%< for CRLF */ *buffer = memget(need); if (*buffer == NULL) { errno = ENOMEM; @@ -477,17 +460,14 @@ irp_marshall_gr(const struct group *gr, char **buffer, size_t *len) { return (0); } - - - -/* +/*% * int irp_unmarshall_gr(struct group *gr, char *buffer) * - * notes: + * notes: \li * - * see above + * See irpmarshall.h * - * return: + * return: \li * * 0 on success and -1 on failure. * @@ -515,7 +495,7 @@ irp_unmarshall_gr(struct group *gr, char *buffer) { /* gr_name field */ name = NULL; - if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0) { + if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0U) { goto error; } @@ -530,15 +510,15 @@ irp_unmarshall_gr(struct group *gr, char *buffer) { /* gr_gid field */ tb = tmpbuf; if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL || - strlen(tb) == 0) { + strlen(tb) == 0U) { goto error; } t = strtol(tmpbuf, &tb, 10); if (*tb) { - goto error; /* junk in value */ + goto error; /*%< junk in value */ } grgid = (gid_t)t; - if ((long) grgid != t) { /* value must have been too big. */ + if ((long) grgid != t) { /*%< value must have been too big. */ goto error; } @@ -582,16 +562,14 @@ irp_unmarshall_gr(struct group *gr, char *buffer) { /* +++++++++++++++++++++++++ struct servent +++++++++++++++++++++++++ */ - - -/* +/*% * int irp_marshall_sv(const struct servent *sv, char **buffer, size_t *len) * - * notes: + * notes: \li * - * see above + * See irpmarshall.h * - * return: + * return: \li * * 0 on success, -1 on failure. * @@ -599,7 +577,7 @@ irp_unmarshall_gr(struct group *gr, char *buffer) { int irp_marshall_sv(const struct servent *sv, char **buffer, size_t *len) { - size_t need = 1; /* for null byte */ + size_t need = 1; /*%< for null byte */ char svPort[24]; const char *fieldsep = COLONSTR; short realport; @@ -630,7 +608,7 @@ irp_marshall_sv(const struct servent *sv, char **buffer, size_t *len) { } if (*buffer == NULL) { - need += 2; /* for CRLF */ + need += 2; /*%< for CRLF */ *buffer = memget(need); if (*buffer == NULL) { errno = ENOMEM; @@ -648,18 +626,14 @@ irp_marshall_sv(const struct servent *sv, char **buffer, size_t *len) { return (0); } - - - - -/* +/*% * int irp_unmarshall_sv(struct servent *sv, char *buffer) * - * notes: + * notes: \li * - * see above + * See irpmarshall.h * - * return: + * return: \li * * 0 on success, -1 on failure. * @@ -686,7 +660,7 @@ irp_unmarshall_sv(struct servent *sv, char *buffer) { /* s_name field */ name = NULL; - if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0) { + if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0U) { goto error; } @@ -707,15 +681,15 @@ irp_unmarshall_sv(struct servent *sv, char *buffer) { /* s_port field */ tb = tmpbuf; if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL || - strlen(tb) == 0) { + strlen(tb) == 0U) { goto error; } t = strtol(tmpbuf, &tb, 10); if (*tb) { - goto error; /* junk in value */ + goto error; /*%< junk in value */ } svport = (short)t; - if ((long) svport != t) { /* value must have been too big. */ + if ((long) svport != t) { /*%< value must have been too big. */ goto error; } svport = htons(svport); @@ -748,16 +722,14 @@ irp_unmarshall_sv(struct servent *sv, char *buffer) { /* +++++++++++++++++++++++++ struct protoent +++++++++++++++++++++++++ */ - - -/* +/*% * int irp_marshall_pr(struct protoent *pr, char **buffer, size_t *len) * - * notes: + * notes: \li * - * see above + * See irpmarshall.h * - * return: + * return: \li * * 0 on success and -1 on failure. * @@ -765,7 +737,7 @@ irp_unmarshall_sv(struct servent *sv, char *buffer) { int irp_marshall_pr(struct protoent *pr, char **buffer, size_t *len) { - size_t need = 1; /* for null byte */ + size_t need = 1; /*%< for null byte */ char prProto[24]; const char *fieldsep = COLONSTR; @@ -791,7 +763,7 @@ irp_marshall_pr(struct protoent *pr, char **buffer, size_t *len) { } if (*buffer == NULL) { - need += 2; /* for CRLF */ + need += 2; /*%< for CRLF */ *buffer = memget(need); if (*buffer == NULL) { errno = ENOMEM; @@ -809,16 +781,14 @@ irp_marshall_pr(struct protoent *pr, char **buffer, size_t *len) { } - - -/* +/*% * int irp_unmarshall_pr(struct protoent *pr, char *buffer) * - * notes: + * notes: \li * - * See above + * See irpmarshall.h * - * return: + * return: \li * * 0 on success, -1 on failure * @@ -844,7 +814,7 @@ int irp_unmarshall_pr(struct protoent *pr, char *buffer) { /* p_name field */ name = NULL; - if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0) { + if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0U) { goto error; } @@ -865,15 +835,15 @@ int irp_unmarshall_pr(struct protoent *pr, char *buffer) { /* p_proto field */ tb = tmpbuf; if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL || - strlen(tb) == 0) { + strlen(tb) == 0U) { goto error; } t = strtol(tmpbuf, &tb, 10); if (*tb) { - goto error; /* junk in value */ + goto error; /*%< junk in value */ } prproto = (int)t; - if ((long) prproto != t) { /* value must have been too big. */ + if ((long) prproto != t) { /*%< value must have been too big. */ goto error; } @@ -898,15 +868,14 @@ int irp_unmarshall_pr(struct protoent *pr, char *buffer) { /* +++++++++++++++++++++++++ struct hostent +++++++++++++++++++++++++ */ - -/* +/*% * int irp_marshall_ho(struct hostent *ho, char **buffer, size_t *len) * - * notes: + * notes: \li * - * see above. + * See irpmarshall.h. * - * return: + * return: \li * * 0 on success, -1 on failure. * @@ -914,7 +883,7 @@ int irp_unmarshall_pr(struct protoent *pr, char *buffer) { int irp_marshall_ho(struct hostent *ho, char **buffer, size_t *len) { - size_t need = 1; /* for null byte */ + size_t need = 1; /*%< for null byte */ char hoaddrtype[24]; char holength[24]; char **av; @@ -952,7 +921,7 @@ irp_marshall_ho(struct hostent *ho, char **buffer, size_t *len) { /* we determine an upper bound on the string length needed, not an exact length. */ - addrlen = (ho->h_addrtype == AF_INET ? 16 : 46) ; /* XX other AF's?? */ + addrlen = (ho->h_addrtype == AF_INET ? 16 : 46) ; /*%< XX other AF's?? */ for (av = ho->h_addr_list; av != NULL && *av != NULL ; av++) need += addrlen; @@ -967,7 +936,7 @@ irp_marshall_ho(struct hostent *ho, char **buffer, size_t *len) { } if (*buffer == NULL) { - need += 2; /* for CRLF */ + need += 2; /*%< for CRLF */ *buffer = memget(need); if (*buffer == NULL) { errno = ENOMEM; @@ -1006,16 +975,14 @@ irp_marshall_ho(struct hostent *ho, char **buffer, size_t *len) { return (-1); } - - -/* +/*% * int irp_unmarshall_ho(struct hostent *ho, char *buffer) * - * notes: + * notes: \li * - * See above. + * See irpmarshall.h. * - * return: + * return: \li * * 0 on success, -1 on failure. * @@ -1027,7 +994,7 @@ irp_unmarshall_ho(struct hostent *ho, char *buffer) { int hoaddrtype; int holength; long t; - char *name = NULL; + char *name; char **aliases = NULL; char **hohaddrlist = NULL; size_t hoaddrsize; @@ -1047,7 +1014,7 @@ irp_unmarshall_ho(struct hostent *ho, char *buffer) { /* h_name field */ name = NULL; - if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0) { + if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0U) { goto error; } @@ -1068,7 +1035,7 @@ irp_unmarshall_ho(struct hostent *ho, char *buffer) { /* h_addrtype field */ tb = tmpbuf; if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL || - strlen(tb) == 0) { + strlen(tb) == 0U) { goto error; } if (strcmp(tmpbuf, "AF_INET") == 0) @@ -1082,15 +1049,15 @@ irp_unmarshall_ho(struct hostent *ho, char *buffer) { /* h_length field */ tb = tmpbuf; if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL || - strlen(tb) == 0) { + strlen(tb) == 0U) { goto error; } t = strtol(tmpbuf, &tb, 10); if (*tb) { - goto error; /* junk in value */ + goto error; /*%< junk in value */ } holength = (int)t; - if ((long) holength != t) { /* value must have been too big. */ + if ((long) holength != t) { /*%< value must have been too big. */ goto error; } @@ -1150,6 +1117,7 @@ irp_unmarshall_ho(struct hostent *ho, char *buffer) { errno = myerrno; if (name != NULL) free(name); + free_array(hohaddrlist, 0); free_array(aliases, 0); return (-1); @@ -1161,16 +1129,15 @@ irp_unmarshall_ho(struct hostent *ho, char *buffer) { /* +++++++++++++++++++++++++ struct netgrp +++++++++++++++++++++++++ */ - -/* +/*% * int irp_marshall_ng(const char *host, const char *user, * const char *domain, char *buffer, size_t *len) * - * notes: + * notes: \li * * See note for irp_marshall_ng_start * - * return: + * return: \li * * 0 on success, 0 on failure. * @@ -1179,7 +1146,7 @@ irp_unmarshall_ho(struct hostent *ho, char *buffer) { int irp_marshall_ng(const char *host, const char *user, const char *domain, char **buffer, size_t *len) { - size_t need = 1; /* for nul byte */ + size_t need = 1; /*%< for nul byte */ const char *fieldsep = ","; if (len == NULL) { @@ -1187,7 +1154,7 @@ irp_marshall_ng(const char *host, const char *user, const char *domain, return (-1); } - need += 4; /* two parens and two commas */ + need += 4; /*%< two parens and two commas */ need += (host == NULL ? 0 : strlen(host)); need += (user == NULL ? 0 : strlen(user)); need += (domain == NULL ? 0 : strlen(domain)); @@ -1201,7 +1168,7 @@ irp_marshall_ng(const char *host, const char *user, const char *domain, } if (*buffer == NULL) { - need += 2; /* for CRLF */ + need += 2; /*%< for CRLF */ *buffer = memget(need); if (*buffer == NULL) { errno = ENOMEM; @@ -1233,18 +1200,17 @@ irp_marshall_ng(const char *host, const char *user, const char *domain, /* ---------- */ - -/* +/*% * int irp_unmarshall_ng(const char **host, const char **user, * const char **domain, char *buffer) * - * notes: + * notes: \li * * Unpacks the BUFFER into 3 character arrays it allocates and assigns * to *HOST, *USER and *DOMAIN. If any field of the value is empty, * then the corresponding paramater value will be set to NULL. * - * return: + * return: \li * * 0 on success and -1 on failure. */ @@ -1320,7 +1286,6 @@ irp_unmarshall_ng(const char **hostp, const char **userp, const char **domainp, if (host != NULL) free(host); if (user != NULL) free(user); - if (domain != NULL) free(domain); return (-1); } @@ -1332,15 +1297,14 @@ irp_unmarshall_ng(const char **hostp, const char **userp, const char **domainp, /* +++++++++++++++++++++++++ struct nwent +++++++++++++++++++++++++ */ - -/* +/*% * int irp_marshall_nw(struct nwent *ne, char **buffer, size_t *len) * - * notes: + * notes: \li * * See at top. * - * return: + * return: \li * * 0 on success and -1 on failure. * @@ -1348,7 +1312,7 @@ irp_unmarshall_ng(const char **hostp, const char **userp, const char **domainp, int irp_marshall_nw(struct nwent *ne, char **buffer, size_t *len) { - size_t need = 1; /* for null byte */ + size_t need = 1; /*%< for null byte */ char nAddrType[24]; char nNet[MAXPADDRSIZE]; const char *fieldsep = COLONSTR; @@ -1381,7 +1345,7 @@ irp_marshall_nw(struct nwent *ne, char **buffer, size_t *len) { } if (*buffer == NULL) { - need += 2; /* for CRLF */ + need += 2; /*%< for CRLF */ *buffer = memget(need); if (*buffer == NULL) { errno = ENOMEM; @@ -1399,16 +1363,14 @@ irp_marshall_nw(struct nwent *ne, char **buffer, size_t *len) { return (0); } - - -/* +/*% * int irp_unmarshall_nw(struct nwent *ne, char *buffer) * - * notes: + * notes: \li * * See note up top. * - * return: + * return: \li * * 0 on success and -1 on failure. * @@ -1435,7 +1397,7 @@ irp_unmarshall_nw(struct nwent *ne, char *buffer) { /* n_name field */ name = NULL; - if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0) { + if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0U) { goto error; } @@ -1456,7 +1418,7 @@ irp_unmarshall_nw(struct nwent *ne, char *buffer) { /* h_addrtype field */ tb = tmpbuf; if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL || - strlen(tb) == 0) { + strlen(tb) == 0U) { goto error; } if (strcmp(tmpbuf, "AF_INET") == 0) @@ -1470,7 +1432,7 @@ irp_unmarshall_nw(struct nwent *ne, char *buffer) { /* n_net field */ tb = tmpbuf; if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL || - strlen(tb) == 0) { + strlen(tb) == 0U) { goto error; } nnet = 0; @@ -1509,15 +1471,14 @@ irp_unmarshall_nw(struct nwent *ne, char *buffer) { /* +++++++++++++++++++++++++ struct netent +++++++++++++++++++++++++ */ - -/* +/*% * int irp_marshall_ne(struct netent *ne, char **buffer, size_t *len) * - * notes: + * notes: \li * * See at top. * - * return: + * return: \li * * 0 on success and -1 on failure. * @@ -1525,7 +1486,7 @@ irp_unmarshall_nw(struct nwent *ne, char *buffer) { int irp_marshall_ne(struct netent *ne, char **buffer, size_t *len) { - size_t need = 1; /* for null byte */ + size_t need = 1; /*%< for null byte */ char nAddrType[24]; char nNet[MAXPADDRSIZE]; const char *fieldsep = COLONSTR; @@ -1558,7 +1519,7 @@ irp_marshall_ne(struct netent *ne, char **buffer, size_t *len) { } if (*buffer == NULL) { - need += 2; /* for CRLF */ + need += 2; /*%< for CRLF */ *buffer = memget(need); if (*buffer == NULL) { errno = ENOMEM; @@ -1576,16 +1537,14 @@ irp_marshall_ne(struct netent *ne, char **buffer, size_t *len) { return (0); } - - -/* +/*% * int irp_unmarshall_ne(struct netent *ne, char *buffer) * - * notes: + * notes: \li * * See note up top. * - * return: + * return: \li * * 0 on success and -1 on failure. * @@ -1612,7 +1571,7 @@ irp_unmarshall_ne(struct netent *ne, char *buffer) { /* n_name field */ name = NULL; - if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0) { + if (getfield(&name, 0, &p, fieldsep) == NULL || strlen(name) == 0U) { goto error; } @@ -1633,7 +1592,7 @@ irp_unmarshall_ne(struct netent *ne, char *buffer) { /* h_addrtype field */ tb = tmpbuf; if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL || - strlen(tb) == 0) { + strlen(tb) == 0U) { goto error; } if (strcmp(tmpbuf, "AF_INET") == 0) @@ -1647,7 +1606,7 @@ irp_unmarshall_ne(struct netent *ne, char *buffer) { /* n_net field */ tb = tmpbuf; if (getfield(&tb, sizeof tmpbuf, &p, fieldsep) == NULL || - strlen(tb) == 0) { + strlen(tb) == 0U) { goto error; } bits = inet_net_pton(naddrtype, tmpbuf, &nnet, sizeof nnet); @@ -1678,11 +1637,10 @@ irp_unmarshall_ne(struct netent *ne, char *buffer) { /* =========================================================================== */ - -/* +/*% * static char ** splitarray(const char *buffer, const char *buffend, char delim) * - * notes: + * notes: \li * * Split a delim separated astring. Not allowed * to have two delims next to each other. BUFFER points to begining of @@ -1690,7 +1648,7 @@ irp_unmarshall_ne(struct netent *ne, char *buffer) { * (i.e. points at where the null byte would be if null * terminated). * - * return: + * return: \li * * Returns a malloced array of pointers, each pointer pointing to a * malloced string. If BUFEER is an empty string, then return values is @@ -1726,7 +1684,7 @@ splitarray(const char *buffer, const char *buffend, char delim) { } if (count > 0) { - count++ ; /* for NULL at end */ + count++ ; /*%< for NULL at end */ aptr = arr = malloc(count * sizeof (char *)); if (aptr == NULL) { errno = ENOMEM; @@ -1756,13 +1714,10 @@ splitarray(const char *buffer, const char *buffend, char delim) { return (arr); } - - - -/* +/*% * static size_t joinlength(char * const *argv) * - * return: + * return: \li * * the number of bytes in all the arrays pointed at * by argv, including their null bytes(which will usually be turned @@ -1783,18 +1738,16 @@ joinlength(char * const *argv) { return (len); } - - -/* +/*% * int joinarray(char * const *argv, char *buffer, char delim) * - * notes: + * notes: \li * * Copy all the ARGV strings into the end of BUFFER * separating them with DELIM. BUFFER is assumed to have * enough space to hold everything and to be already null-terminated. * - * return: + * return: \li * * 0 unless argv or buffer is NULL. * @@ -1824,11 +1777,10 @@ joinarray(char * const *argv, char *buffer, char delim) { return (0); } - -/* +/*% * static char * getfield(char **res, size_t reslen, char **ptr, char delim) * - * notes: + * notes: \li * * Stores in *RES, which is a buffer of length RESLEN, a * copy of the bytes from *PTR up to and including the first @@ -1836,7 +1788,7 @@ joinarray(char * const *argv, char *buffer, char delim) { * assigned a malloced buffer to hold the copy. *PTR is * modified to point at the found delimiter. * - * return: + * return: \li * * If there was no delimiter, then NULL is returned, * otherewise *RES is returned. @@ -1861,7 +1813,7 @@ getfield(char **res, size_t reslen, char **ptr, char delim) { if (*res == NULL) { *res = strndup(*ptr, q - *ptr); } else { - if ((size_t)(q - *ptr + 1) > reslen) { /* to big for res */ + if ((size_t)(q - *ptr + 1) > reslen) { /*%< to big for res */ errno = EINVAL; return (NULL); } else { @@ -1879,16 +1831,16 @@ getfield(char **res, size_t reslen, char **ptr, char delim) { - +#ifndef HAVE_STRNDUP /* * static char * strndup(const char *str, size_t len) * - * notes: + * notes: \li * * like strdup, except do len bytes instead of the whole string. Always * null-terminates. * - * return: + * return: \li * * The newly malloced string. * @@ -1904,18 +1856,18 @@ strndup(const char *str, size_t len) { p[len] = 0x0; return (p); } - +#endif #if WANT_MAIN -/* +/*% * static int strcmp_nws(const char *a, const char *b) * - * notes: + * notes: \li * * do a strcmp, except uneven lengths of whitespace compare the same * - * return: + * return: \li * */ @@ -1949,14 +1901,10 @@ strcmp_nws(const char *a, const char *b) { #endif - - - - -/* +/*% * static void free_array(char **argv, size_t entries) * - * notes: + * notes: \li * * Free argv and each of the pointers inside it. The end of * the array is when a NULL pointer is found inside. If @@ -1968,12 +1916,12 @@ strcmp_nws(const char *a, const char *b) { static void free_array(char **argv, size_t entries) { char **p = argv; - int useEntries = (entries > 0); + int useEntries = (entries > 0U); if (argv == NULL) return; - while ((useEntries && entries > 0) || *p) { + while ((useEntries && entries > 0U) || *p) { if (*p) free(*p); p++; @@ -1991,7 +1939,7 @@ free_array(char **argv, size_t entries) { #if WANT_MAIN -/* takes an option to indicate what sort of marshalling(read the code) and +/*% takes an option to indicate what sort of marshalling(read the code) and an argument. If the argument looks like a marshalled buffer(has a ':' embedded) then it's unmarshalled and the remarshalled and the new string is compared to the old one. @@ -2349,3 +2297,5 @@ main(int argc, char **argv) { } #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/irs_data.c b/usr/src/lib/libresolv2/common/irs/irs_data.c index 874c25cef8..cd8ba00c50 100644 --- a/usr/src/lib/libresolv2/common/irs/irs_data.c +++ b/usr/src/lib/libresolv2/common/irs/irs_data.c @@ -1,29 +1,22 @@ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: irs_data.c,v 1.22 2003/06/20 07:09:33 marka Exp $"; +static const char rcsid[] = "$Id: irs_data.c,v 1.12 2007/08/27 03:32:26 marka Exp $"; #endif #include "port_before.h" @@ -39,27 +32,30 @@ static const char rcsid[] = "$Id: irs_data.c,v 1.22 2003/06/20 07:09:33 marka Ex #include <stdio.h> #include <string.h> #include <isc/memcluster.h> -#include <stdlib.h> #ifdef DO_PTHREADS #include <pthread.h> #endif #include <irs.h> +#include <stdlib.h> #include "port_after.h" #include "irs_data.h" #undef _res +#if !(__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) #undef h_errno +extern int h_errno; +#endif extern struct __res_state _res; -extern int h_errno; #ifdef DO_PTHREADS -static pthread_key_t key = PTHREAD_ONCE_KEY_NP; +static pthread_key_t key; +static int once = 0; #else -static struct net_data *net_data = NULL; +static struct net_data *net_data; #endif void @@ -117,7 +113,8 @@ net_data_destroy(void *p) { memput(net_data, sizeof *net_data); } -/* applications that need a specific config file other than +/*% + * applications that need a specific config file other than * _PATH_IRS_CONF should call net_data_init directly rather than letting * the various wrapper functions make the first call. - brister */ @@ -125,10 +122,25 @@ net_data_destroy(void *p) { struct net_data * net_data_init(const char *conf_file) { #ifdef DO_PTHREADS +#ifndef LIBBIND_MUTEX_INITIALIZER +#define LIBBIND_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER +#endif + static pthread_mutex_t keylock = LIBBIND_MUTEX_INITIALIZER; struct net_data *net_data; - if (pthread_key_create_once_np(&key, net_data_destroy) != 0) - return (NULL); + if (!once) { + if (pthread_mutex_lock(&keylock) != 0) + return (NULL); + if (!once) { + if (pthread_key_create(&key, net_data_destroy) != 0) { + (void)pthread_mutex_unlock(&keylock); + return (NULL); + } + once = 1; + } + if (pthread_mutex_unlock(&keylock) != 0) + return (NULL); + } net_data = pthread_getspecific(key); #endif @@ -171,7 +183,7 @@ net_data_create(const char *conf_file) { return (NULL); } - if ((net_data->res->options & RES_INIT) == 0 && + if ((net_data->res->options & RES_INIT) == 0U && res_ninit(net_data->res) == -1) { (*net_data->irs->close)(net_data->irs); memput(net_data, sizeof (struct net_data)); @@ -181,8 +193,6 @@ net_data_create(const char *conf_file) { return (net_data); } - - void net_data_minimize(struct net_data *net_data) { res_nclose(net_data->res); @@ -198,6 +208,13 @@ __res_state(void) { return (&_res); } +#else +#ifdef __linux +struct __res_state * +__res_state(void) { + return (&_res); +} +#endif #endif int * @@ -206,13 +223,24 @@ __h_errno(void) { struct net_data *net_data = net_data_init(NULL); if (net_data && net_data->res) return (&net_data->res->res_h_errno); +#if !(__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) + return(&_res.res_h_errno); +#else return (&h_errno); +#endif } void __h_errno_set(struct __res_state *res, int err) { + +#if (__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) + res->res_h_errno = err; +#else h_errno = res->res_h_errno = err; +#endif } #endif /*__BIND_NOSTATIC*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/irs_data.h b/usr/src/lib/libresolv2/common/irs/irs_data.h index 4c5fdf3c64..cb814fd8b1 100644 --- a/usr/src/lib/libresolv2/common/irs/irs_data.h +++ b/usr/src/lib/libresolv2/common/irs/irs_data.h @@ -1,36 +1,26 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* - * $Id: irs_data.h,v 1.12 1999/01/18 07:46:55 vixie Exp $ + * $Id: irs_data.h,v 1.3 2005/04/27 04:56:30 sra Exp $ */ #ifndef __BIND_NOSTATIC -#ifndef _IRS_DATA_H -#define _IRS_DATA_H - #define net_data_init __net_data_init struct net_data { @@ -48,7 +38,7 @@ struct net_data { struct passwd * pw_last; struct servent * sv_last; struct protoent * pr_last; - struct netent * nw_last; /* should have been ne_last */ + struct netent * nw_last; /*%< should have been ne_last */ struct nwent * nww_last; struct hostent * ho_last; @@ -62,13 +52,12 @@ struct net_data { void * nw_data; void * ho_data; - struct __res_state * res; /* for gethostent.c */ - + struct __res_state * res; /*%< for gethostent.c */ }; extern struct net_data * net_data_init(const char *conf_file); extern void net_data_minimize(struct net_data *); -#endif /* _IR_DATA_H */ - #endif /*__BIND_NOSTATIC*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/irs_p.h b/usr/src/lib/libresolv2/common/irs/irs_p.h index 64043b90aa..2a0a933fce 100644 --- a/usr/src/lib/libresolv2/common/irs/irs_p.h +++ b/usr/src/lib/libresolv2/common/irs/irs_p.h @@ -1,29 +1,22 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* - * $Id: irs_p.h,v 1.8 1999/01/08 19:24:42 vixie Exp $ + * $Id: irs_p.h,v 1.3 2005/04/27 04:56:30 sra Exp $ */ #ifndef _IRS_P_H_INCLUDED @@ -54,3 +47,5 @@ extern struct irs_ng * irs_nul_ng(struct irs_acc *); extern struct servent * irs_lclsv_fnxt(struct lcl_sv *); #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/lcl.c b/usr/src/lib/libresolv2/common/irs/lcl.c index 3d86033209..ea78a258a6 100644 --- a/usr/src/lib/libresolv2/common/irs/lcl.c +++ b/usr/src/lib/libresolv2/common/irs/lcl.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: lcl.c,v 1.17 2001/05/29 05:49:02 marka Exp $"; +static const char rcsid[] = "$Id: lcl.c,v 1.4 2005/04/27 04:56:30 sra Exp $"; #endif /* Imports */ @@ -113,7 +106,7 @@ lcl_res_get(struct irs_acc *this) { lcl_res_set(this, res, free); } - if ((lcl->res->options & RES_INIT) == 0 && + if ((lcl->res->options & RES_INIT) == 0U && res_ninit(lcl->res) < 0) return (NULL); @@ -145,3 +138,5 @@ lcl_close(struct irs_acc *this) { } memput(this, sizeof *this); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/lcl_gr.c b/usr/src/lib/libresolv2/common/irs/lcl_gr.c index 0a655f0d8f..ce7e347b2d 100644 --- a/usr/src/lib/libresolv2/common/irs/lcl_gr.c +++ b/usr/src/lib/libresolv2/common/irs/lcl_gr.c @@ -1,9 +1,4 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* * Copyright (c) 1989, 1993, 1995 * The Regents of the University of California. All rights reserved. * @@ -37,26 +32,24 @@ */ /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: lcl_gr.c,v 1.26 2001/05/29 05:49:03 marka Exp $"; +static const char rcsid[] = "$Id: lcl_gr.c,v 1.3 2005/04/27 04:56:30 sra Exp $"; /* from getgrent.c 8.2 (Berkeley) 3/21/94"; */ /* from BSDI Id: getgrent.c,v 2.8 1996/05/28 18:15:14 bostic Exp $ */ #endif /* LIBC_SCCS and not lint */ @@ -97,7 +90,7 @@ static int __bind_irs_gr_unneeded; struct pvt { FILE * fp; - /* + /*%< * Need space to store the entries read from the group file. * The members list also needs space per member, and the * strings making up the user names must be allocated @@ -105,7 +98,7 @@ struct pvt { * we keep one buffer and resize it as needed. */ struct group group; - size_t nmemb; /* Malloc'd max index of gr_mem[]. */ + size_t nmemb; /*%< Malloc'd max index of gr_mem[]. */ char * membuf; size_t membufsize; }; @@ -234,9 +227,8 @@ grstart(struct pvt *pvt) { return (1); } -#define INITIAL_NMEMB 30 /* about 120 bytes */ -#define INITIAL_BUFSIZ (INITIAL_NMEMB * 8) /* about 240 bytes */ - +#define INITIAL_NMEMB 30 /*%< about 120 bytes */ +#define INITIAL_BUFSIZ (INITIAL_NMEMB * 8) /*%< about 240 bytes */ static char * grnext(struct pvt *pvt) { char *w, *e; @@ -359,3 +351,4 @@ grscan(struct irs_gr *this, int search, gid_t gid, const char *name) { } #endif /* WANT_IRS_GR */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/lcl_ho.c b/usr/src/lib/libresolv2/common/irs/lcl_ho.c index 469cbb7f41..6c5246a5c4 100644 --- a/usr/src/lib/libresolv2/common/irs/lcl_ho.c +++ b/usr/src/lib/libresolv2/common/irs/lcl_ho.c @@ -1,9 +1,4 @@ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* * Copyright (c) 1985, 1988, 1993 * The Regents of the University of California. All rights reserved. * @@ -37,29 +32,27 @@ */ /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* from gethostnamadr.c 8.1 (Berkeley) 6/4/93 */ /* BIND Id: gethnamaddr.c,v 8.15 1996/05/22 04:56:30 vixie Exp $ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: lcl_ho.c,v 1.26 2001/05/29 05:49:04 marka Exp $"; +static const char rcsid[] = "$Id: lcl_ho.c,v 1.5 2006/03/09 23:57:56 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports. */ @@ -116,7 +109,7 @@ struct pvt { char * h_addr_ptrs[MAXADDRS + 1]; char * host_aliases[MAXALIASES]; char hostbuf[8*1024]; - u_char host_addr[16]; /* IPv4 or IPv6 */ + u_char host_addr[16]; /*%< IPv4 or IPv6 */ struct __res_state *res; void (*free_res)(void *); }; @@ -440,11 +433,7 @@ ho_rewind(struct irs_ho *this) { return; (void)fclose(pvt->fp); } -#ifdef SUNW_AVOIDSTDIO_FDLIMIT - if (!(pvt->fp = fopen(_PATH_HOSTS, "rF"))) -#else if (!(pvt->fp = fopen(_PATH_HOSTS, "r"))) -#endif return; if (fcntl(fileno(pvt->fp), F_SETFD, 1) < 0) { (void)fclose(pvt->fp); @@ -519,7 +508,7 @@ ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) cur = &sentinel; switch(pai->ai_family) { - case AF_UNSPEC: /* INET6 then INET4 */ + case AF_UNSPEC: /*%< INET6 then INET4 */ q.family = AF_INET6; q.next = &q2; q2.family = AF_INET; @@ -531,7 +520,7 @@ ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) q.family = AF_INET; break; default: - RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); /* ??? */ + RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); /*%< ??? */ return(NULL); } @@ -552,7 +541,7 @@ ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) ai = hostent2addrinfo(hp, pai); if (ai) { cur->ai_next = ai; - while (cur && cur->ai_next) + while (cur->ai_next) cur = cur->ai_next; } } @@ -580,8 +569,10 @@ init(struct irs_ho *this) { if (!pvt->res && !ho_res_get(this)) return (-1); - if (((pvt->res->options & RES_INIT) == 0) && + if (((pvt->res->options & RES_INIT) == 0U) && res_ninit(pvt->res) == -1) return (-1); return (0); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/lcl_ng.c b/usr/src/lib/libresolv2/common/irs/lcl_ng.c index 05adcdf9f9..70e0b4563f 100644 --- a/usr/src/lib/libresolv2/common/irs/lcl_ng.c +++ b/usr/src/lib/libresolv2/common/irs/lcl_ng.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: lcl_ng.c,v 1.17 2001/05/29 05:49:05 marka Exp $"; +static const char rcsid[] = "$Id: lcl_ng.c,v 1.3 2005/04/27 04:56:31 sra Exp $"; #endif /* Imports */ @@ -50,11 +43,10 @@ static const char rcsid[] = "$Id: lcl_ng.c,v 1.17 2001/05/29 05:49:05 marka Exp /* Definitions */ -#define NG_HOST 0 /* Host name */ -#define NG_USER 1 /* User name */ -#define NG_DOM 2 /* and Domain name */ -#define LINSIZ 1024 /* Length of netgroup file line */ - +#define NG_HOST 0 /*%< Host name */ +#define NG_USER 1 /*%< User name */ +#define NG_DOM 2 /*%< and Domain name */ +#define LINSIZ 1024 /*%< Length of netgroup file line */ /* * XXX Warning XXX * This code is a hack-and-slash special. It realy needs to be @@ -62,24 +54,25 @@ static const char rcsid[] = "$Id: lcl_ng.c,v 1.17 2001/05/29 05:49:05 marka Exp * More reasonable data structures would not be a bad thing. */ -/* +/*% * Static Variables and functions used by setnetgrent(), getnetgrent() and * endnetgrent(). + * * There are two linked lists: - * - linelist is just used by setnetgrent() to parse the net group file via. + * \li linelist is just used by setnetgrent() to parse the net group file via. * parse_netgrp() - * - netgrp is the list of entries for the current netgroup + * \li netgrp is the list of entries for the current netgroup */ struct linelist { - struct linelist *l_next; /* Chain ptr. */ - int l_parsed; /* Flag for cycles */ - char * l_groupname; /* Name of netgroup */ - char * l_line; /* Netgroup entrie(s) to be parsed */ + struct linelist *l_next; /*%< Chain ptr. */ + int l_parsed; /*%< Flag for cycles */ + char * l_groupname; /*%< Name of netgroup */ + char * l_line; /*%< Netgroup entrie(s) to be parsed */ }; struct ng_old_struct { - struct ng_old_struct *ng_next; /* Chain ptr */ - char * ng_str[3]; /* Field pointers, see below */ + struct ng_old_struct *ng_next; /*%< Chain ptr */ + char * ng_str[3]; /*%< Field pointers, see below */ }; struct pvt { @@ -149,7 +142,7 @@ ng_close(struct irs_ng *this) { memput(this, sizeof *this); } -/* +/*% * Parse the netgroup file looking for the netgroup and build the list * of netgrp structures. Let parse_netgrp() and read_for_group() do * most of the work. @@ -181,7 +174,7 @@ ng_rewind(struct irs_ng *this, const char *group) { pvt->nextgrp = pvt->grouphead.gr; } -/* +/*% * Get the next netgroup off the list. */ static int @@ -200,7 +193,7 @@ ng_next(struct irs_ng *this, const char **host, const char **user, return (0); } -/* +/*% * Search for a match in a netgroup. */ static int @@ -236,7 +229,7 @@ ng_minimize(struct irs_ng *this) { /* Private */ -/* +/*% * endnetgrent() - cleanup */ static void @@ -273,7 +266,7 @@ freelists(struct irs_ng *this) { pvt->grouphead.gr = NULL; } -/* +/*% * Parse the netgroup file setting up the linked lists. */ static int @@ -356,7 +349,7 @@ parse_netgrp(struct irs_ng *this, const char *group) { return (1); } -/* +/*% * Read the netgroup file and save lines until the line for the netgroup * is found. Return 1 if eof is encountered. */ @@ -449,3 +442,5 @@ read_for_group(struct irs_ng *this, const char *group) { } return (NULL); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/lcl_nw.c b/usr/src/lib/libresolv2/common/irs/lcl_nw.c index 38a7d584a3..79b55a0c04 100644 --- a/usr/src/lib/libresolv2/common/irs/lcl_nw.c +++ b/usr/src/lib/libresolv2/common/irs/lcl_nw.c @@ -1,9 +1,4 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* * Copyright (c) 1989, 1993, 1995 * The Regents of the University of California. All rights reserved. * @@ -37,26 +32,24 @@ */ /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: lcl_nw.c,v 1.22 2001/05/29 05:49:07 marka Exp $"; +static const char rcsid[] = "$Id: lcl_nw.c,v 1.4 2005/04/27 04:56:31 sra Exp $"; /* from getgrent.c 8.2 (Berkeley) 3/21/94"; */ /* from BSDI Id: getgrent.c,v 2.8 1996/05/28 18:15:14 bostic Exp $ */ #endif /* LIBC_SCCS and not lint */ @@ -371,8 +364,10 @@ init(struct irs_nw *this) { if (!pvt->res && !nw_res_get(this)) return (-1); - if (((pvt->res->options & RES_INIT) == 0) && + if (((pvt->res->options & RES_INIT) == 0U) && res_ninit(pvt->res) == -1) return (-1); return (0); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/lcl_p.h b/usr/src/lib/libresolv2/common/irs/lcl_p.h index 061ec1b8ad..e3f4f009cb 100644 --- a/usr/src/lib/libresolv2/common/irs/lcl_p.h +++ b/usr/src/lib/libresolv2/common/irs/lcl_p.h @@ -1,39 +1,33 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* - * $Id: lcl_p.h,v 1.7 1999/01/08 19:24:51 vixie Exp $ + * $Id: lcl_p.h,v 1.3 2005/04/27 04:56:31 sra Exp $ */ -/* +/*! \file + * \brief * lcl_p.h - private include file for the local accessor functions. */ #ifndef _LCL_P_H_INCLUDED #define _LCL_P_H_INCLUDED -/* +/*% * Object state. */ struct lcl_p { diff --git a/usr/src/lib/libresolv2/common/irs/lcl_pr.c b/usr/src/lib/libresolv2/common/irs/lcl_pr.c index f6a8d312c9..622158eb17 100644 --- a/usr/src/lib/libresolv2/common/irs/lcl_pr.c +++ b/usr/src/lib/libresolv2/common/irs/lcl_pr.c @@ -1,9 +1,4 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* * Copyright (c) 1989, 1993, 1995 * The Regents of the University of California. All rights reserved. * @@ -37,26 +32,24 @@ */ /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: lcl_pr.c,v 1.18 1999/10/13 17:11:20 vixie Exp $"; +static const char rcsid[] = "$Id: lcl_pr.c,v 1.4 2006/03/09 23:57:56 marka Exp $"; #endif /* LIBC_SCCS and not lint */ /* extern */ @@ -92,6 +85,7 @@ static const char rcsid[] = "$Id: lcl_pr.c,v 1.18 1999/10/13 17:11:20 vixie Exp struct pvt { FILE * fp; char line[BUFSIZ+1]; + char * dbuf; struct protoent proto; char * proto_aliases[MAXALIASES]; }; @@ -148,6 +142,8 @@ pr_close(struct irs_pr *this) { if (pvt->fp) (void) fclose(pvt->fp); + if (pvt->dbuf) + free(pvt->dbuf); memput(pvt, sizeof *pvt); memput(this, sizeof *this); } @@ -209,6 +205,10 @@ pr_next(struct irs_pr *this) { pr_rewind(this); if (!pvt->fp) return (NULL); + if (pvt->dbuf) { + free(pvt->dbuf); + pvt->dbuf = NULL; + } bufp = pvt->line; bufsiz = BUFSIZ; offset = 0; @@ -277,6 +277,7 @@ pr_next(struct irs_pr *this) { } } *q = NULL; + pvt->dbuf = dbuf; return (&pvt->proto); } @@ -289,3 +290,5 @@ pr_minimize(struct irs_pr *this) { pvt->fp = NULL; } } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/lcl_pw.c b/usr/src/lib/libresolv2/common/irs/lcl_pw.c index 5fa0d965e7..ffca5541bb 100644 --- a/usr/src/lib/libresolv2/common/irs/lcl_pw.c +++ b/usr/src/lib/libresolv2/common/irs/lcl_pw.c @@ -1,9 +1,4 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* * Copyright (c) 1989, 1993, 1995 * The Regents of the University of California. All rights reserved. * @@ -37,26 +32,24 @@ */ /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: lcl_pw.c,v 1.20 2001/05/29 05:49:08 marka Exp $"; +static const char rcsid[] = "$Id: lcl_pw.c,v 1.3 2005/04/27 04:56:31 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* Extern */ @@ -92,7 +85,8 @@ static int __bind_irs_pw_unneeded; #include "irs_p.h" #include "lcl_p.h" -/* +/*! \file + * \brief * The lookup techniques and data extraction code here must be kept * in sync with that in `pwd_mkdb'. */ @@ -101,9 +95,9 @@ static int __bind_irs_pw_unneeded; /* Types */ struct pvt { - struct passwd passwd; /* password structure */ - DB *pw_db; /* password database */ - int pw_keynum; /* key counter */ + struct passwd passwd; /*%< password structure */ + DB *pw_db; /*%< password database */ + int pw_keynum; /*%< key counter */ int warned; u_int max; char * line; diff --git a/usr/src/lib/libresolv2/common/irs/lcl_sv.c b/usr/src/lib/libresolv2/common/irs/lcl_sv.c index afbdf3f3da..8d0049bb46 100644 --- a/usr/src/lib/libresolv2/common/irs/lcl_sv.c +++ b/usr/src/lib/libresolv2/common/irs/lcl_sv.c @@ -1,9 +1,4 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* * Copyright (c) 1989, 1993, 1995 * The Regents of the University of California. All rights reserved. * @@ -37,26 +32,24 @@ */ /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: lcl_sv.c,v 1.22 2001/06/18 14:43:59 marka Exp $"; +static const char rcsid[] = "$Id: lcl_sv.c,v 1.4 2005/04/27 04:56:31 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* extern */ @@ -394,8 +387,7 @@ sv_db_rec(struct lcl_sv *sv, DBT *key, DBT *data) { int n; p = data->data; - p[data->size - 1] = '\0'; /* should be, but we depend on it */ - + p[data->size - 1] = '\0'; /*%< should be, but we depend on it */ if (((char *)key->data)[0] == '\0') { if (key->size < sizeof(u_short)*2 || data->size < 2) return (NULL); @@ -436,3 +428,5 @@ sv_db_rec(struct lcl_sv *sv, DBT *key, DBT *data) { return (&sv->serv); } #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/nis.c b/usr/src/lib/libresolv2/common/irs/nis.c index bdac586cc1..9abc47403a 100644 --- a/usr/src/lib/libresolv2/common/irs/nis.c +++ b/usr/src/lib/libresolv2/common/irs/nis.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis.c,v 1.15 2001/05/29 05:49:11 marka Exp $"; +static const char rcsid[] = "$Id: nis.c,v 1.3 2005/04/27 04:56:32 sra Exp $"; #endif /* Imports */ @@ -43,6 +36,9 @@ static const char rcsid[] = "$Id: nis.c,v 1.15 2001/05/29 05:49:11 marka Exp $"; #include <sys/types.h> #include <netinet/in.h> +#ifdef T_NULL +#undef T_NULL /* Silence re-definition warning of T_NULL. */ +#endif #include <arpa/nameser.h> #include <resolv.h> @@ -156,3 +152,5 @@ nis_close(struct irs_acc *this) { } #endif /*WANT_IRS_NIS*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/nis_gr.c b/usr/src/lib/libresolv2/common/irs/nis_gr.c index 3f9f059db2..c7c8d83043 100644 --- a/usr/src/lib/libresolv2/common/irs/nis_gr.c +++ b/usr/src/lib/libresolv2/common/irs/nis_gr.c @@ -1,9 +1,4 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* * Copyright (c) 1989, 1993, 1995 * The Regents of the University of California. All rights reserved. * @@ -37,26 +32,24 @@ */ /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis_gr.c,v 1.22 2002/07/08 06:26:11 marka Exp $"; +static const char rcsid[] = "$Id: nis_gr.c,v 1.4 2005/04/27 04:56:32 sra Exp $"; /* from getgrent.c 8.2 (Berkeley) 3/21/94"; */ /* from BSDI Id: getgrent.c,v 2.8 1996/05/28 18:15:14 bostic Exp $ */ #endif /* LIBC_SCCS and not lint */ @@ -106,7 +99,7 @@ struct pvt { int curkey_len; char * curval_data; int curval_len; - /* + /*%< * Need space to store the entries read from the group file. * The members list also needs space per member, and the * strings making up the user names must be allocated @@ -114,7 +107,7 @@ struct pvt { * we keep one buffer and resize it as needed. */ struct group group; - size_t nmemb; /* Malloc'd max index of gr_mem[]. */ + size_t nmemb; /*%< Malloc'd max index of gr_mem[]. */ char * membuf; size_t membufsize; }; @@ -358,3 +351,4 @@ nisfree(struct pvt *pvt, enum do_what do_what) { } #endif /* WANT_IRS_GR && WANT_IRS_NIS */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/nis_ho.c b/usr/src/lib/libresolv2/common/irs/nis_ho.c index 7a38d12035..0799613f49 100644 --- a/usr/src/lib/libresolv2/common/irs/nis_ho.c +++ b/usr/src/lib/libresolv2/common/irs/nis_ho.c @@ -1,29 +1,22 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis_ho.c,v 1.19 2003/04/24 04:09:11 marka Exp $"; +static const char rcsid[] = "$Id: nis_ho.c,v 1.5 2005/04/27 04:56:32 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports */ @@ -40,6 +33,9 @@ static int __bind_irs_nis_unneeded; #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> +#ifdef T_NULL +#undef T_NULL /* Silence re-definition warning of T_NULL. */ +#endif #include <rpc/rpc.h> #include <rpc/xdr.h> #include <rpcsvc/yp_prot.h> @@ -83,7 +79,7 @@ struct pvt { char * h_addr_ptrs[MAXADDRS + 1]; char * host_aliases[MAXALIASES + 1]; char hostbuf[8*1024]; - u_char host_addr[16]; /* IPv4 or IPv6 */ + u_char host_addr[16]; /*%< IPv4 or IPv6 */ struct __res_state *res; void (*free_res)(void *); }; @@ -373,7 +369,7 @@ ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) cur = &sentinel; switch(pai->ai_family) { - case AF_UNSPEC: /* INET6 then INET4 */ + case AF_UNSPEC: /*%< INET6 then INET4 */ q.family = AF_INET6; q.next = &q2; q2.family = AF_INET; @@ -385,7 +381,7 @@ ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) q.family = AF_INET; break; default: - RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); /* ??? */ + RES_SET_H_ERRNO(pvt->res, NO_RECOVERY); /*%< ??? */ return(NULL); } @@ -418,7 +414,7 @@ ho_addrinfo(struct irs_ho *this, const char *name, const struct addrinfo *pai) /* Private */ -/* +/*% ipnodes: ::1 localhost 127.0.0.1 localhost @@ -535,3 +531,5 @@ init(struct irs_ho *this) { return (0); } #endif /*WANT_IRS_NIS*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/nis_ng.c b/usr/src/lib/libresolv2/common/irs/nis_ng.c index 109e9cde1f..ac6330536a 100644 --- a/usr/src/lib/libresolv2/common/irs/nis_ng.c +++ b/usr/src/lib/libresolv2/common/irs/nis_ng.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis_ng.c,v 1.17 2001/05/29 05:49:14 marka Exp $"; +static const char rcsid[] = "$Id: nis_ng.c,v 1.4 2005/04/27 04:56:32 sra Exp $"; #endif /* Imports */ @@ -50,6 +43,9 @@ static int __bind_irs_nis_unneeded; #include <string.h> #include <netinet/in.h> +#ifdef T_NULL +#undef T_NULL /* Silence re-definition warning of T_NULL. */ +#endif #include <arpa/nameser.h> #include <resolv.h> @@ -304,3 +300,5 @@ tmpfree(struct pvt *pvt) { } #endif /*WANT_IRS_NIS*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/nis_nw.c b/usr/src/lib/libresolv2/common/irs/nis_nw.c index dae568e54b..c61e871ea9 100644 --- a/usr/src/lib/libresolv2/common/irs/nis_nw.c +++ b/usr/src/lib/libresolv2/common/irs/nis_nw.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis_nw.c,v 1.16 2001/05/29 05:49:15 marka Exp $"; +static const char rcsid[] = "$Id: nis_nw.c,v 1.4 2005/04/27 04:56:33 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports */ @@ -40,7 +33,9 @@ static int __bind_irs_nis_unneeded; #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> - +#ifdef T_NULL +#undef T_NULL /* Silence re-definition warning of T_NULL. */ +#endif #include <rpc/rpc.h> #include <rpc/xdr.h> #include <rpcsvc/yp_prot.h> @@ -386,3 +381,5 @@ init(struct irs_nw *this) { } #endif /*WANT_IRS_NIS*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/nis_p.h b/usr/src/lib/libresolv2/common/irs/nis_p.h index cd80d19235..70e2948d67 100644 --- a/usr/src/lib/libresolv2/common/irs/nis_p.h +++ b/usr/src/lib/libresolv2/common/irs/nis_p.h @@ -1,36 +1,30 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* - * $Id: nis_p.h,v 1.6 1999/01/08 19:25:03 vixie Exp $ + * $Id: nis_p.h,v 1.3 2005/04/27 04:56:33 sra Exp $ */ -/* +/*! \file + * \brief * nis_p.h - private include file for the NIS functions. */ -/* +/*% * Object state. */ struct nis_p { diff --git a/usr/src/lib/libresolv2/common/irs/nis_pr.c b/usr/src/lib/libresolv2/common/irs/nis_pr.c index c4695f3234..4995550f82 100644 --- a/usr/src/lib/libresolv2/common/irs/nis_pr.c +++ b/usr/src/lib/libresolv2/common/irs/nis_pr.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis_pr.c,v 1.14 2001/05/29 05:49:16 marka Exp $"; +static const char rcsid[] = "$Id: nis_pr.c,v 1.4 2005/04/27 04:56:33 sra Exp $"; #endif /* Imports */ @@ -38,6 +31,9 @@ static int __bind_irs_nis_unneeded; #include <netinet/in.h> #include <arpa/nameser.h> #include <resolv.h> +#ifdef T_NULL +#undef T_NULL /* Silence re-definition warning of T_NULL. */ +#endif #include <rpc/rpc.h> #include <rpc/xdr.h> #include <rpcsvc/yp_prot.h> @@ -302,3 +298,5 @@ nisfree(struct pvt *pvt, enum do_what do_what) { } #endif /*WANT_IRS_NIS*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/nis_pw.c b/usr/src/lib/libresolv2/common/irs/nis_pw.c index 5e8c4e76a2..8f27e4bd93 100644 --- a/usr/src/lib/libresolv2/common/irs/nis_pw.c +++ b/usr/src/lib/libresolv2/common/irs/nis_pw.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis_pw.c,v 1.17 2001/05/29 05:49:18 marka Exp $"; +static const char rcsid[] = "$Id: nis_pw.c,v 1.4 2005/04/27 04:56:33 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports */ @@ -237,7 +230,7 @@ makepasswdent(struct irs_pw *this) { if (!(cp = strchr(cp, ':'))) goto cleanup; #ifdef HAS_PW_CLASS - pvt->passwd.pw_class = cp; /* Needs to point at a \0. */ + pvt->passwd.pw_class = cp; /*%< Needs to point at a \0. */ #endif *cp++ = '\0'; @@ -292,3 +285,4 @@ nisfree(struct pvt *pvt, enum do_what do_what) { } #endif /* WANT_IRS_PW && WANT_IRS_NIS */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/nis_sv.c b/usr/src/lib/libresolv2/common/irs/nis_sv.c index da5cf57693..bb24600f0d 100644 --- a/usr/src/lib/libresolv2/common/irs/nis_sv.c +++ b/usr/src/lib/libresolv2/common/irs/nis_sv.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis_sv.c,v 1.15 2001/05/29 05:49:19 marka Exp $"; +static const char rcsid[] = "$Id: nis_sv.c,v 1.4 2005/04/27 04:56:34 sra Exp $"; #endif /* LIBC_SCCS and not lint */ /* Imports */ @@ -39,6 +32,9 @@ static int __bind_irs_nis_unneeded; #include <arpa/nameser.h> #include <resolv.h> #include <sys/socket.h> +#ifdef T_NULL +#undef T_NULL /* Silence re-definition warning of T_NULL. */ +#endif #include <rpc/rpc.h> #include <rpc/xdr.h> #include <rpcsvc/yp_prot.h> @@ -310,3 +306,5 @@ nisfree(struct pvt *pvt, enum do_what do_what) { } #endif /*WANT_IRS_NIS*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/nul_ng.c b/usr/src/lib/libresolv2/common/irs/nul_ng.c index 7aaa760cd3..e5811b563c 100644 --- a/usr/src/lib/libresolv2/common/irs/nul_ng.c +++ b/usr/src/lib/libresolv2/common/irs/nul_ng.c @@ -1,32 +1,26 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nul_ng.c,v 1.11 2001/05/29 05:49:20 marka Exp $"; +static const char rcsid[] = "$Id: nul_ng.c,v 1.3 2005/04/27 04:56:34 sra Exp $"; #endif -/* +/*! \file + * \brief * nul_ng.c - the netgroup accessor null map */ diff --git a/usr/src/lib/libresolv2/common/irs/pathnames.h b/usr/src/lib/libresolv2/common/irs/pathnames.h index c223a6bf53..1646842155 100644 --- a/usr/src/lib/libresolv2/common/irs/pathnames.h +++ b/usr/src/lib/libresolv2/common/irs/pathnames.h @@ -1,29 +1,22 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* - * $Id: pathnames.h,v 1.7 1999/01/08 19:25:10 vixie Exp $ + * $Id: pathnames.h,v 1.3 2005/04/27 04:56:34 sra Exp $ */ #ifndef _PATH_IRS_CONF @@ -55,3 +48,5 @@ #ifndef _PATH_HESIOD_CONF #define _PATH_HESIOD_CONF "/etc/hesiod.conf" #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/irs/util.c b/usr/src/lib/libresolv2/common/irs/util.c index 2f27b2ae34..794c10b107 100644 --- a/usr/src/lib/libresolv2/common/irs/util.c +++ b/usr/src/lib/libresolv2/common/irs/util.c @@ -1,28 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: util.c,v 1.12 2001/05/29 05:49:21 marka Exp $"; +static const char rcsid[] = "$Id: util.c,v 1.3 2005/04/27 04:56:34 sra Exp $"; #endif #include "port_before.h" @@ -111,3 +105,5 @@ make_group_list(struct irs_gr *this, const char *name, *ngroups = ng; return (ret); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/assertions.c b/usr/src/lib/libresolv2/common/isc/assertions.c index 1afff62208..b71e5a32d3 100644 --- a/usr/src/lib/libresolv2/common/isc/assertions.c +++ b/usr/src/lib/libresolv2/common/isc/assertions.c @@ -1,29 +1,22 @@ /* - * Copyright 1998-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Copyright (c) 1997,1999 by Internet Software Consortium. + * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1997, 1999, 2001 Internet Software Consortium. * - * Permission to use, copy, modify, and distribute this software for any + * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: assertions.c,v 8.4 2001/05/29 05:49:22 marka Exp $"; +static const char rcsid[] = "$Id: assertions.c,v 1.5 2008/11/14 02:36:51 marka Exp $"; #endif #include "port_before.h" @@ -85,6 +78,7 @@ assertion_type_to_text(assertion_type type) { * Private. */ +/* coverity[+kill] */ static void default_assertion_failed(const char *file, int line, assertion_type type, const char *cond, int print_errno) @@ -96,3 +90,5 @@ default_assertion_failed(const char *file, int line, assertion_type type, abort(); /* NOTREACHED */ } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/base64.c b/usr/src/lib/libresolv2/common/isc/base64.c index 3e55d161ce..97a6876e4e 100644 --- a/usr/src/lib/libresolv2/common/isc/base64.c +++ b/usr/src/lib/libresolv2/common/isc/base64.c @@ -1,27 +1,26 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. */ + /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* * Portions Copyright (c) 1995 by International Business Machines, Inc. * @@ -48,7 +47,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: base64.c,v 8.7 1999/10/13 16:39:33 vixie Exp $"; +static const char rcsid[] = "$Id: base64.c,v 1.4 2005/04/27 04:56:34 sra Exp $"; #endif /* not lint */ #include "port_before.h" @@ -69,8 +68,7 @@ static const char rcsid[] = "$Id: base64.c,v 8.7 1999/10/13 16:39:33 vixie Exp $ #include "port_after.h" -#ifdef ORIGINAL_ISC_CODE -#else +#ifndef ORIGINAL_ISC_CODE #pragma weak __b64_ntop = b64_ntop #pragma weak __b64_pton = b64_pton #endif /* ORIGINAL_ISC_CODE */ @@ -82,7 +80,7 @@ static const char Base64[] = static const char Pad64 = '='; /* (From RFC1521 and draft-ietf-dnssec-secext-03.txt) - The following encoding technique is taken from RFC 1521 by Borenstein + The following encoding technique is taken from RFC1521 by Borenstein and Freed. It is reproduced here in a slightly edited form for convenience. @@ -151,7 +149,7 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) { u_char output[4]; size_t i; - while (2 < srclength) { + while (2U < srclength) { input[0] = *src++; input[1] = *src++; input[2] = *src++; @@ -175,7 +173,7 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) { } /* Now we worry about padding. */ - if (0 != srclength) { + if (0U != srclength) { /* Get what's left. */ input[0] = input[1] = input[2] = '\0'; for (i = 0; i < srclength; i++) @@ -192,7 +190,7 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) { return (-1); target[datalength++] = Base64[output[0]]; target[datalength++] = Base64[output[1]]; - if (srclength == 1) + if (srclength == 1U) target[datalength++] = Pad64; else target[datalength++] = Base64[output[2]]; @@ -200,7 +198,7 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) { } if (datalength >= targsize) return (-1); - target[datalength] = '\0'; /* Returned value doesn't count \0. */ + target[datalength] = '\0'; /*%< Returned value doesn't count \\0. */ return (datalength); } @@ -223,14 +221,14 @@ b64_pton(src, target, targsize) tarindex = 0; while ((ch = *src++) != '\0') { - if (isspace(ch)) /* Skip whitespace anywhere. */ + if (isspace(ch)) /*%< Skip whitespace anywhere. */ continue; if (ch == Pad64) break; pos = strchr(Base64, ch); - if (pos == 0) /* A non-base64 character. */ + if (pos == 0) /*%< A non-base64 character. */ return (-1); switch (state) { @@ -283,14 +281,14 @@ b64_pton(src, target, targsize) * on a byte boundary, and/or with erroneous trailing characters. */ - if (ch == Pad64) { /* We got a pad char. */ - ch = *src++; /* Skip it, get next. */ + if (ch == Pad64) { /*%< We got a pad char. */ + ch = *src++; /*%< Skip it, get next. */ switch (state) { - case 0: /* Invalid = in first position */ - case 1: /* Invalid = in second position */ + case 0: /*%< Invalid = in first position */ + case 1: /*%< Invalid = in second position */ return (-1); - case 2: /* Valid, means one byte of info */ + case 2: /*%< Valid, means one byte of info */ /* Skip any number of spaces. */ for ((void)NULL; ch != '\0'; ch = *src++) if (!isspace(ch)) @@ -298,11 +296,11 @@ b64_pton(src, target, targsize) /* Make sure there is another trailing = sign. */ if (ch != Pad64) return (-1); - ch = *src++; /* Skip the = */ + ch = *src++; /*%< Skip the = */ /* Fall through to "single trailing =" case. */ /* FALLTHROUGH */ - case 3: /* Valid, means two bytes of info */ + case 3: /*%< Valid, means two bytes of info */ /* * We know this char is an =. Is there anything but * whitespace after it? @@ -331,3 +329,5 @@ b64_pton(src, target, targsize) return (tarindex); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/bitncmp.c b/usr/src/lib/libresolv2/common/isc/bitncmp.c index cc205bdad6..efe5009292 100644 --- a/usr/src/lib/libresolv2/common/isc/bitncmp.c +++ b/usr/src/lib/libresolv2/common/isc/bitncmp.c @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Copyright (c) 1996,1999 by Internet Software Consortium. + * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1996, 1999, 2001 Internet Software Consortium. * - * Permission to use, copy, modify, and distribute this software for any + * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: bitncmp.c,v 1.7 2001/05/29 05:49:23 marka Exp $"; +static const char rcsid[] = "$Id: bitncmp.c,v 1.5 2008/11/14 02:36:51 marka Exp $"; #endif #include "port_before.h" @@ -36,7 +29,7 @@ static const char rcsid[] = "$Id: bitncmp.c,v 1.7 2001/05/29 05:49:23 marka Exp #include <isc/misc.h> -/* +/*% * int * bitncmp(l, r, n) * compare bit masks l and r, for n bits. @@ -55,7 +48,7 @@ bitncmp(const void *l, const void *r, int n) { b = n / 8; x = memcmp(l, r, b); - if (x) + if (x || (n % 8) == 0) return (x); lb = ((const u_char *)l)[b]; @@ -71,3 +64,5 @@ bitncmp(const void *l, const void *r, int n) { } return (0); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/ctl_clnt.c b/usr/src/lib/libresolv2/common/isc/ctl_clnt.c index 5da3f30075..f71001a6d4 100644 --- a/usr/src/lib/libresolv2/common/isc/ctl_clnt.c +++ b/usr/src/lib/libresolv2/common/isc/ctl_clnt.c @@ -1,30 +1,23 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ctl_clnt.c,v 8.18 2002/07/08 05:10:23 marka Exp $"; -#endif /* not lint */ - -/* - * Copyright (c) 1998,1999 by Internet Software Consortium. + * Copyright (C) 2004, 2005, 2007, 2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1998-2003 Internet Software Consortium. * - * Permission to use, copy, modify, and distribute this software for any + * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" +#if !defined(lint) && !defined(SABER) +static const char rcsid[] = "$Id: ctl_clnt.c,v 1.11 2008/11/14 02:36:51 marka Exp $"; +#endif /* not lint */ /* Extern. */ @@ -45,6 +38,9 @@ static const char rcsid[] = "$Id: ctl_clnt.c,v 8.18 2002/07/08 05:10:23 marka Ex #include <string.h> #include <time.h> #include <unistd.h> +#ifdef HAVE_MEMORY_H +#include <memory.h> +#endif #include <isc/assertions.h> #include <isc/ctl.h> @@ -121,6 +117,19 @@ static void touch_timer(struct ctl_cctx *); static void timer(evContext, void *, struct timespec, struct timespec); +#ifndef HAVE_MEMCHR +static void * +memchr(const void *b, int c, size_t len) { + const unsigned char *p = b; + size_t i; + + for (i = 0; i < len; i++, p++) + if (*p == (unsigned char)c) + return ((void *)p); + return (NULL); +} +#endif + /* Private data. */ static const char * const state_names[] = { @@ -129,7 +138,7 @@ static const char * const state_names[] = { /* Public. */ -/* +/*% * void * ctl_client() * create, condition, and connect to a listener on the control port. @@ -205,7 +214,7 @@ ctl_client(evContext lev, const struct sockaddr *cap, size_t cap_len, return (ctx); } -/* +/*% * void * ctl_endclient(ctx) * close a client and release all of its resources. @@ -217,7 +226,7 @@ ctl_endclient(struct ctl_cctx *ctx) { memput(ctx, sizeof *ctx); } -/* +/*% * int * ctl_command(ctx, cmd, len, donefunc, uap) * Queue a transaction, which will begin with sending cmd @@ -241,7 +250,7 @@ ctl_command(struct ctl_cctx *ctx, const char *cmd, size_t len, default: abort(); } - if (len >= MAX_LINELEN) { + if (len >= (size_t)MAX_LINELEN) { errno = EMSGSIZE; return (-1); } @@ -535,7 +544,7 @@ readable(evContext ev, void *uap, int fd, int evmask) { (*tran->donefunc)(ctx, tran->uap, ctx->inbuf.text, (done ? 0 : CTL_MORE)); ctx->inbuf.used -= ((eos - ctx->inbuf.text) + 1); - if (ctx->inbuf.used == 0) + if (ctx->inbuf.used == 0U) ctl_bufput(&ctx->inbuf); else memmove(ctx->inbuf.text, eos + 1, ctx->inbuf.used); @@ -550,7 +559,7 @@ readable(evContext ev, void *uap, int fd, int evmask) { goto again; return; } - if (ctx->inbuf.used == MAX_LINELEN) { + if (ctx->inbuf.used == (size_t)MAX_LINELEN) { (*ctx->logger)(ctl_error, "%s: line too long (%-10s...)", me, ctx->inbuf.text); error(ctx); @@ -607,3 +616,5 @@ timer(evContext ev, void *uap, struct timespec due, struct timespec itv) { ctx->timeout.tv_sec, state_names[ctx->state]); error(ctx); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/ctl_p.c b/usr/src/lib/libresolv2/common/isc/ctl_p.c index ef785e70bd..7ab719a5e6 100644 --- a/usr/src/lib/libresolv2/common/isc/ctl_p.c +++ b/usr/src/lib/libresolv2/common/isc/ctl_p.c @@ -1,31 +1,24 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ctl_p.c,v 8.8 2001/05/29 05:49:26 marka Exp $"; +static const char rcsid[] = "$Id: ctl_p.c,v 1.4 2005/04/27 04:56:35 sra Exp $"; #endif /* not lint */ /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1998,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* Extern. */ #include "port_before.h" @@ -63,7 +56,7 @@ const char * const ctl_sevnames[] = { /* Public. */ -/* +/*% * ctl_logger() * if ctl_startup()'s caller didn't specify a logger, this one * is used. this pollutes stderr with all kinds of trash so it will @@ -85,7 +78,7 @@ int ctl_bufget(struct ctl_buf *buf, ctl_logfunc logger) { static const char me[] = "ctl_bufget"; - REQUIRE(!allocated_p(*buf) && buf->used == 0); + REQUIRE(!allocated_p(*buf) && buf->used == 0U); buf->text = memget(MAX_LINELEN); if (!allocated_p(*buf)) { (*logger)(ctl_error, "%s: getmem: %s", me, strerror(errno)); @@ -191,3 +184,5 @@ ctl_sa_copy(const struct sockaddr *src, struct sockaddr *dst) { break; } } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/ctl_p.h b/usr/src/lib/libresolv2/common/isc/ctl_p.h index df86107f4d..18a52ae39c 100644 --- a/usr/src/lib/libresolv2/common/isc/ctl_p.h +++ b/usr/src/lib/libresolv2/common/isc/ctl_p.h @@ -1,16 +1,9 @@ -/* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - struct ctl_buf { char * text; size_t used; }; -#define MAX_LINELEN 990 /* Like SMTP. */ +#define MAX_LINELEN 990 /*%< Like SMTP. */ #ifndef NO_SOCKADDR_UN #define MAX_NTOP PATH_MAX #else @@ -31,3 +24,5 @@ const char * ctl_sa_ntop(const struct sockaddr *, char *, size_t, ctl_logfunc); void ctl_sa_copy(const struct sockaddr *, struct sockaddr *); + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/ctl_srvr.c b/usr/src/lib/libresolv2/common/isc/ctl_srvr.c index 8593ba9a30..8fd7a21ffa 100644 --- a/usr/src/lib/libresolv2/common/isc/ctl_srvr.c +++ b/usr/src/lib/libresolv2/common/isc/ctl_srvr.c @@ -1,30 +1,23 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: ctl_srvr.c,v 8.26 2002/07/08 05:10:25 marka Exp $"; -#endif /* not lint */ - -/* - * Copyright (c) 1998,1999 by Internet Software Consortium. + * Copyright (C) 2004-2006, 2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1998-2003 Internet Software Consortium. * - * Permission to use, copy, modify, and distribute this software for any + * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" +#if !defined(lint) && !defined(SABER) +static const char rcsid[] = "$Id: ctl_srvr.c,v 1.10 2008/11/14 02:36:51 marka Exp $"; +#endif /* not lint */ /* Extern. */ @@ -47,6 +40,9 @@ static const char rcsid[] = "$Id: ctl_srvr.c,v 8.26 2002/07/08 05:10:25 marka Ex #include <time.h> #include <unistd.h> #include <fcntl.h> +#ifdef HAVE_MEMORY_H +#include <memory.h> +#endif #include <isc/assertions.h> #include <isc/ctl.h> @@ -165,7 +161,7 @@ static const struct ctl_verb fakehelpverb = { /* Public. */ -/* +/*% * void * ctl_server() * create, condition, and start a listener on the control port. @@ -270,7 +266,7 @@ ctl_server(evContext lev, const struct sockaddr *sap, size_t sap_len, return (ctx); } -/* +/*% * void * ctl_endserver(ctx) * if the control listener is open, close it. clean out all eventlib @@ -298,7 +294,7 @@ ctl_endserver(struct ctl_sctx *ctx) { memput(ctx, sizeof *ctx); } -/* +/*% * If body is non-NULL then it we add a "." line after it. * Caller must have escaped lines with leading ".". */ @@ -328,7 +324,7 @@ ctl_response(struct ctl_sess *sess, u_int code, const char *text, me, address_expr); goto untimely; } - if (sizeof "000-\r\n" + strlen(text) > MAX_LINELEN) { + if (sizeof "000-\r\n" + strlen(text) > (size_t)MAX_LINELEN) { (*ctx->logger)(ctl_error, "%s: %s: output buffer ovf, closing", me, address_expr); goto untimely; @@ -571,7 +567,7 @@ static void ctl_readable(evContext lev, void *uap, int fd, int evmask) { static const char me[] = "ctl_readable"; struct ctl_sess *sess = uap; - struct ctl_sctx *ctx = sess->ctx; + struct ctl_sctx *ctx; char *eos, tmp[MAX_NTOP]; ssize_t n; @@ -579,6 +575,8 @@ ctl_readable(evContext lev, void *uap, int fd, int evmask) { REQUIRE(fd >= 0); REQUIRE(evmask == EV_READ); REQUIRE(sess->state == reading || sess->state == reading_data); + + ctx = sess->ctx; evTouchIdleTimer(lev, sess->rdtiID); if (!allocated_p(sess->inbuf) && ctl_bufget(&sess->inbuf, ctx->logger) < 0) { @@ -611,13 +609,13 @@ ctl_readable(evContext lev, void *uap, int fd, int evmask) { ctl_docommand(sess); } sess->inbuf.used -= ((eos - sess->inbuf.text) + 1); - if (sess->inbuf.used == 0) + if (sess->inbuf.used == 0U) ctl_bufput(&sess->inbuf); else memmove(sess->inbuf.text, eos + 1, sess->inbuf.used); return; } - if (sess->inbuf.used == MAX_LINELEN) { + if (sess->inbuf.used == (size_t)MAX_LINELEN) { (*ctx->logger)(ctl_error, "%s: %s: line too long, closing", me, address_expr); ctl_close(sess); @@ -633,7 +631,7 @@ ctl_wrtimeout(evContext lev, void *uap, struct ctl_sess *sess = uap; struct ctl_sctx *ctx = sess->ctx; char tmp[MAX_NTOP]; - + UNUSED(lev); UNUSED(due); UNUSED(itv); @@ -785,3 +783,5 @@ ctl_signal_done(struct ctl_sctx *ctx, struct ctl_sess *sess) { sess->donefunc = NULL; } } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/ev_connects.c b/usr/src/lib/libresolv2/common/isc/ev_connects.c index 533b544a49..38dfdbe512 100644 --- a/usr/src/lib/libresolv2/common/isc/ev_connects.c +++ b/usr/src/lib/libresolv2/common/isc/ev_connects.c @@ -1,33 +1,26 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1995-1999 by Internet Software Consortium * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* ev_connects.c - implement asynch connect/accept for the eventlib * vix 16sep96 [initial] */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: ev_connects.c,v 8.32 2001/07/03 13:26:35 marka Exp $"; +static const char rcsid[] = "$Id: ev_connects.c,v 1.8 2006/03/09 23:57:56 marka Exp $"; #endif /* Import. */ @@ -76,7 +69,7 @@ evListen(evContext opaqueCtx, int fd, int maxconn, OKNEW(new); new->flags = EV_CONN_LISTEN; - OK(mode = fcntl(fd, F_GETFL, NULL)); /* side effect: validate fd. */ + OKFREE(mode = fcntl(fd, F_GETFL, NULL), new); /*%< side effect: validate fd. */ /* * Remember the nonblocking status. We assume that either evSelectFD * has not been done to this fd, or that if it has then the caller @@ -87,13 +80,13 @@ evListen(evContext opaqueCtx, int fd, int maxconn, if ((mode & PORT_NONBLOCK) == 0) { #ifdef USE_FIONBIO_IOCTL int on = 1; - OK(ioctl(fd, FIONBIO, (char *)&on)); + OKFREE(ioctl(fd, FIONBIO, (char *)&on), new); #else - OK(fcntl(fd, F_SETFL, mode | PORT_NONBLOCK)); + OKFREE(fcntl(fd, F_SETFL, mode | PORT_NONBLOCK), new); #endif new->flags |= EV_CONN_BLOCK; } - OK(listen(fd, maxconn)); + OKFREE(listen(fd, maxconn), new); if (evSelectFD(opaqueCtx, fd, EV_READ, listener, new, &new->file) < 0){ int save = errno; @@ -175,10 +168,10 @@ evCancelConn(evContext opaqueCtx, evConnID id) { return (-1); } else { #ifdef USE_FIONBIO_IOCTL - int on = 1; - OK(ioctl(this->fd, FIONBIO, (char *)&on)); + int off = 0; + OK(ioctl(this->fd, FIONBIO, (char *)&off)); #else - OK(fcntl(this->fd, F_SETFL, mode | PORT_NONBLOCK)); + OK(fcntl(this->fd, F_SETFL, mode & ~PORT_NONBLOCK)); #endif } } @@ -330,7 +323,9 @@ connector(evContext opaqueCtx, void *uap, int fd, int evmask) { #endif } la, ra; ISC_SOCKLEN_T lalen, ralen; +#ifndef NETREAD_BROKEN char buf[1]; +#endif void *conn_uap; evConnFunc conn_func; evConnID id; @@ -364,9 +359,11 @@ connector(evContext opaqueCtx, void *uap, int fd, int evmask) { GETXXXNAME(getpeername, fd, ra.sa, ralen) < 0) { int save = errno; - (void) close(fd); /* XXX closing caller's fd */ + (void) close(fd); /*%< XXX closing caller's fd */ errno = save; fd = -1; } (*conn_func)(opaqueCtx, conn_uap, fd, &la.sa, lalen, &ra.sa, ralen); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/ev_files.c b/usr/src/lib/libresolv2/common/isc/ev_files.c index 8c9b1b22d6..b12baf1aaa 100644 --- a/usr/src/lib/libresolv2/common/isc/ev_files.c +++ b/usr/src/lib/libresolv2/common/isc/ev_files.c @@ -1,32 +1,26 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* Copyright (c) 1995-1999 by Internet Software Consortium + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1995-1999 by Internet Software Consortium * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* ev_files.c - implement asynch file IO for the eventlib * vix 11sep95 [initial] */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: ev_files.c,v 1.22 2002/07/08 05:50:07 marka Exp $"; +static const char rcsid[] = "$Id: ev_files.c,v 1.8 2005/07/28 06:51:48 marka Exp $"; #endif #include "port_before.h" @@ -64,24 +58,22 @@ evSelectFD(evContext opaqueCtx, ctx, fd, eventmask, func, uap); if (eventmask == 0 || (eventmask & ~EV_MASK_ALL) != 0) EV_ERR(EINVAL); -#ifdef SUNW_POLL -#else +#ifndef USE_POLL if (fd > ctx->highestFD) EV_ERR(EINVAL); -#endif /* SUNW_POLL */ - OK(mode = fcntl(fd, F_GETFL, NULL)); /* side effect: validate fd. */ - +#endif + OK(mode = fcntl(fd, F_GETFL, NULL)); /*%< side effect: validate fd. */ /* * The first time we touch a file descriptor, we need to check to see * if the application already had it in O_NONBLOCK mode and if so, all * of our deselect()'s have to leave it in O_NONBLOCK. If not, then * all but our last deselect() has to leave it in O_NONBLOCK. */ -#ifdef SUNW_POLL +#ifdef USE_POLL /* Make sure both ctx->pollfds[] and ctx->fdTable[] are large enough */ - if (fd >= ctx->maxnfds) - evPollfdRealloc(ctx, 1, fd); -#endif /* SUNW_POLL */ + if (fd >= ctx->maxnfds && evPollfdRealloc(ctx, 1, fd) != 0) + EV_ERR(ENOMEM); +#endif /* USE_POLL */ id = FindFD(ctx, fd, EV_MASK_ALL); if (id == NULL) { if (mode & PORT_NONBLOCK) @@ -157,16 +149,6 @@ evSelectFD(evContext opaqueCtx, if (opaqueID) opaqueID->opaque = id; -#ifdef SUNW_POLL -#else - evPrintf(ctx, 5, - "evSelectFD(fd %d, mask 0x%x): new masks: 0x%lx 0x%lx 0x%lx\n", - fd, eventmask, - (u_long)ctx->rdNext.fds_bits[0], - (u_long)ctx->wrNext.fds_bits[0], - (u_long)ctx->exNext.fds_bits[0]); -#endif /* SUNW_POLL */ - return (0); } @@ -221,7 +203,7 @@ evDeselectFD(evContext opaqueCtx, evFileID opaqueID) { * and (b) the caller didn't ask us anything about O_NONBLOCK. */ #ifdef USE_FIONBIO_IOCTL - int off = 1; + int off = 0; (void) ioctl(del->fd, FIONBIO, (char *)&off); #else (void) fcntl(del->fd, F_SETFL, mode & ~PORT_NONBLOCK); @@ -276,16 +258,6 @@ evDeselectFD(evContext opaqueCtx, evFileID opaqueID) { if (del == ctx->fdNext) ctx->fdNext = del->next; -#ifdef SUNW_POLL -#else - evPrintf(ctx, 5, - "evDeselectFD(fd %d, mask 0x%x): new masks: 0x%lx 0x%lx 0x%lx\n", - del->fd, eventmask, - (u_long)ctx->rdNext.fds_bits[0], - (u_long)ctx->wrNext.fds_bits[0], - (u_long)ctx->exNext.fds_bits[0]); -#endif /* SUNW_POLL */ - /* Couldn't free it before now since we were using fields out of it. */ FREE(del); @@ -301,3 +273,5 @@ FindFD(const evContext_p *ctx, int fd, int eventmask) { break; return (id); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/ev_streams.c b/usr/src/lib/libresolv2/common/isc/ev_streams.c index 04ac464354..5dad36d04a 100644 --- a/usr/src/lib/libresolv2/common/isc/ev_streams.c +++ b/usr/src/lib/libresolv2/common/isc/ev_streams.c @@ -1,32 +1,26 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* Copyright (c) 1996-1999 by Internet Software Consortium + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1996-1999 by Internet Software Consortium * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* ev_streams.c - implement asynch stream file IO for the eventlib * vix 04mar96 [initial] */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: ev_streams.c,v 8.22 2001/05/29 05:49:29 marka Exp $"; +static const char rcsid[] = "$Id: ev_streams.c,v 1.5 2005/04/27 04:56:36 sra Exp $"; #endif #include "port_before.h" @@ -227,7 +221,7 @@ copyvec(evStream *str, const struct iovec *iov, int iocnt) { /* Pull off or truncate lead iovec(s). */ static void consume(evStream *str, size_t bytes) { - while (bytes > 0) { + while (bytes > 0U) { if (bytes < (size_t)str->iovCur->iov_len) { str->iovCur->iov_len -= bytes; str->iovCur->iov_base = (void *) @@ -310,3 +304,5 @@ readable(evContext opaqueCtx, void *uap, int fd, int evmask) { if (str->ioDone <= 0 || str->ioDone == str->ioTotal) done(opaqueCtx, str); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/ev_timers.c b/usr/src/lib/libresolv2/common/isc/ev_timers.c index 9afc4a0ccd..12ac2cebca 100644 --- a/usr/src/lib/libresolv2/common/isc/ev_timers.c +++ b/usr/src/lib/libresolv2/common/isc/ev_timers.c @@ -1,33 +1,26 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1995-1999 by Internet Software Consortium * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* ev_timers.c - implement timers for the eventlib * vix 09sep95 [initial] */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: ev_timers.c,v 1.33 2002/07/08 05:50:09 marka Exp $"; +static const char rcsid[] = "$Id: ev_timers.c,v 1.6 2005/04/27 04:56:36 sra Exp $"; #endif /* Import. */ @@ -116,7 +109,30 @@ evCmpTime(struct timespec a, struct timespec b) { struct timespec evNowTime() { struct timeval now; +#ifdef CLOCK_REALTIME + struct timespec tsnow; + int m = CLOCK_REALTIME; +#ifdef CLOCK_MONOTONIC + if (__evOptMonoTime) + m = CLOCK_MONOTONIC; +#endif + if (clock_gettime(m, &tsnow) == 0) + return (tsnow); +#endif + if (gettimeofday(&now, NULL) < 0) + return (evConsTime(0, 0)); + return (evTimeSpec(now)); +} + +struct timespec +evUTCTime() { + struct timeval now; +#ifdef CLOCK_REALTIME + struct timespec tsnow; + if (clock_gettime(CLOCK_REALTIME, &tsnow) == 0) + return (tsnow); +#endif if (gettimeofday(&now, NULL) < 0) return (evConsTime(0, 0)); return (evTimeSpec(now)); @@ -164,8 +180,25 @@ evSetTimer(evContext opaqueCtx, (long)due.tv_sec, due.tv_nsec, (long)inter.tv_sec, inter.tv_nsec); +#ifdef __hpux + /* + * tv_sec and tv_nsec are unsigned. + */ + if (due.tv_nsec >= BILLION) + EV_ERR(EINVAL); + + if (inter.tv_nsec >= BILLION) + EV_ERR(EINVAL); +#else + if (due.tv_sec < 0 || due.tv_nsec < 0 || due.tv_nsec >= BILLION) + EV_ERR(EINVAL); + + if (inter.tv_sec < 0 || inter.tv_nsec < 0 || inter.tv_nsec >= BILLION) + EV_ERR(EINVAL); +#endif + /* due={0,0} is a magic cookie meaning "now." */ - if (due.tv_sec == 0 && due.tv_nsec == 0L) + if (due.tv_sec == (time_t)0 && due.tv_nsec == 0L) due = evNowTime(); /* Allocate and fill. */ @@ -223,6 +256,31 @@ evClearTimer(evContext opaqueCtx, evTimerID id) { } int +evConfigTimer(evContext opaqueCtx, + evTimerID id, + const char *param, + int value +) { + evContext_p *ctx = opaqueCtx.opaque; + evTimer *timer = id.opaque; + int result=0; + + UNUSED(value); + + if (heap_element(ctx->timers, timer->index) != timer) + EV_ERR(ENOENT); + + if (strcmp(param, "rate") == 0) + timer->mode |= EV_TMR_RATE; + else if (strcmp(param, "interval") == 0) + timer->mode &= ~EV_TMR_RATE; + else + EV_ERR(EINVAL); + + return (result); +} + +int evResetTimer(evContext opaqueCtx, evTimerID id, evTimerFunc func, @@ -238,6 +296,23 @@ evResetTimer(evContext opaqueCtx, if (heap_element(ctx->timers, timer->index) != timer) EV_ERR(ENOENT); +#ifdef __hpux + /* + * tv_sec and tv_nsec are unsigned. + */ + if (due.tv_nsec >= BILLION) + EV_ERR(EINVAL); + + if (inter.tv_nsec >= BILLION) + EV_ERR(EINVAL); +#else + if (due.tv_sec < 0 || due.tv_nsec < 0 || due.tv_nsec >= BILLION) + EV_ERR(EINVAL); + + if (inter.tv_sec < 0 || inter.tv_nsec < 0 || inter.tv_nsec >= BILLION) + EV_ERR(EINVAL); +#endif + old_due = timer->due; timer->func = func; @@ -420,3 +495,5 @@ idle_timeout(evContext opaqueCtx, this->timer->inter = evSubTime(this->max_idle, idle); } } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/ev_waits.c b/usr/src/lib/libresolv2/common/isc/ev_waits.c index 223915c853..99da1526c7 100644 --- a/usr/src/lib/libresolv2/common/isc/ev_waits.c +++ b/usr/src/lib/libresolv2/common/isc/ev_waits.c @@ -1,33 +1,26 @@ /* - * Copyright 2003 by Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* ev_waits.c - implement deferred function calls for the eventlib * vix 05dec95 [initial] */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: ev_waits.c,v 8.12 2002/07/08 05:50:10 marka Exp $"; +static const char rcsid[] = "$Id: ev_waits.c,v 1.4 2005/04/27 04:56:36 sra Exp $"; #endif #include "port_before.h" @@ -51,7 +44,7 @@ static evWaitList * evGetWaitList(evContext_p *, const void *, int); /* Public. */ -/* +/*% * Enter a new wait function on the queue. */ int @@ -79,7 +72,7 @@ evWaitFor(evContext opaqueCtx, const void *tag, return (0); } -/* +/*% * Mark runnable all waiting functions having a certain tag. */ int @@ -106,7 +99,7 @@ evDo(evContext opaqueCtx, const void *tag) { return (0); } -/* +/*% * Remove a waiting (or ready to run) function from the queue. */ int @@ -250,3 +243,5 @@ evGetWaitList(evContext_p *ctx, const void *tag, int should_create) { this = evNewWaitList(ctx); return (this); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/eventlib.c b/usr/src/lib/libresolv2/common/isc/eventlib.c index beaed1c6bc..be4a7848b9 100644 --- a/usr/src/lib/libresolv2/common/isc/eventlib.c +++ b/usr/src/lib/libresolv2/common/isc/eventlib.c @@ -1,33 +1,26 @@ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1995-1999 by Internet Software Consortium * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* eventlib.c - implement glue for the eventlib * vix 09sep95 [initial] */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: eventlib.c,v 1.48 2002/07/17 07:37:34 marka Exp $"; +static const char rcsid[] = "$Id: eventlib.c,v 1.10 2006/03/09 23:57:56 marka Exp $"; #endif #include "port_before.h" @@ -36,9 +29,9 @@ static const char rcsid[] = "$Id: eventlib.c,v 1.48 2002/07/17 07:37:34 marka Ex #include <sys/types.h> #include <sys/time.h> #include <sys/stat.h> -#ifdef SUNW_POLL +#ifdef SOLARIS2 #include <limits.h> -#endif /* SUNW_POLL */ +#endif /* SOLARIS2 */ #include <errno.h> #include <signal.h> @@ -52,21 +45,22 @@ static const char rcsid[] = "$Id: eventlib.c,v 1.48 2002/07/17 07:37:34 marka Ex #include "port_after.h" -#ifdef SUNW_POLL -#if defined(pselect) -#undef pselect -#endif -#define pselect Pselect -#endif /* SUNW_POLL */ +int __evOptMonoTime; + +#ifdef USE_POLL +#define pselect Pselect +#endif /* USE_POLL */ /* Forward. */ -#ifdef NEED_PSELECT +#if defined(NEED_PSELECT) || defined(USE_POLL) static int pselect(int, void *, void *, void *, struct timespec *, const sigset_t *); #endif +int __evOptMonoTime; + /* Public. */ int @@ -92,8 +86,8 @@ evCreate(evContext *opaqueCtx) { /* Files. */ ctx->files = NULL; -#ifdef SUNW_POLL - ctx->pollfds = 0; +#ifdef USE_POLL + ctx->pollfds = NULL; ctx->maxnfds = 0; ctx->firstfd = 0; emulMaskInit(ctx, rdLast, EV_READ, 1); @@ -103,27 +97,24 @@ evCreate(evContext *opaqueCtx) { emulMaskInit(ctx, exLast, EV_EXCEPT, 1); emulMaskInit(ctx, exNext, EV_EXCEPT, 0); emulMaskInit(ctx, nonblockBefore, EV_WASNONBLOCKING, 0); -#endif /* SUNW_POLL */ +#endif /* USE_POLL */ FD_ZERO(&ctx->rdNext); FD_ZERO(&ctx->wrNext); FD_ZERO(&ctx->exNext); FD_ZERO(&ctx->nonblockBefore); ctx->fdMax = -1; ctx->fdNext = NULL; - ctx->fdCount = 0; /* Invalidate {rd,wr,ex}Last. */ -#ifdef SUNW_POLL - ctx->highestFD = INT_MAX; -#else + ctx->fdCount = 0; /*%< Invalidate {rd,wr,ex}Last. */ +#ifndef USE_POLL ctx->highestFD = FD_SETSIZE - 1; -#endif /* SUNW_POLL */ + memset(ctx->fdTable, 0, sizeof ctx->fdTable); +#else + ctx->highestFD = INT_MAX / sizeof(struct pollfd); + ctx->fdTable = NULL; +#endif /* USE_POLL */ #ifdef EVENTLIB_TIME_CHECKS ctx->lastFdCount = 0; #endif -#ifdef SUNW_POLL - ctx->fdTable = 0; -#else - memset(ctx->fdTable, 0, sizeof ctx->fdTable); -#endif /* SUNW_POLL */ /* Streams. */ ctx->streams = NULL; @@ -159,7 +150,7 @@ evSetDebug(evContext opaqueCtx, int level, FILE *output) { int evDestroy(evContext opaqueCtx) { evContext_p *ctx = opaqueCtx.opaque; - int revs = 424242; /* Doug Adams. */ + int revs = 424242; /*%< Doug Adams. */ evWaitList *this_wl, *next_wl; evWait *this_wait, *next_wait; @@ -275,8 +266,7 @@ evGetNext(evContext opaqueCtx, evEvent *opaqueEv, int options) { nextTime = nextTimer->due; timerPast = (evCmpTime(nextTime, ctx->lastEventTime) <= 0); } else - timerPast = 0; /* Make gcc happy. */ - + timerPast = 0; /*%< Make gcc happy. */ evPrintf(ctx, 9, "evGetNext: fdCount %d\n", ctx->fdCount); if (ctx->fdCount == 0) { static const struct timespec NoTime = {0, 0L}; @@ -309,7 +299,7 @@ evGetNext(evContext opaqueCtx, evEvent *opaqueEv, int options) { if (ctx->debug > 0) { interval = evSubTime(ctx->lastEventTime, ctx->lastSelectTime); - if (interval.tv_sec > 0) + if (interval.tv_sec > 0 || interval.tv_nsec > 0) evPrintf(ctx, 1, "time between pselect() %u.%09u count %d\n", interval.tv_sec, interval.tv_nsec, @@ -317,51 +307,37 @@ evGetNext(evContext opaqueCtx, evEvent *opaqueEv, int options) { } #endif do { -#ifdef SUNW_POLL +#ifndef USE_POLL + /* XXX need to copy only the bits we are using. */ + ctx->rdLast = ctx->rdNext; + ctx->wrLast = ctx->wrNext; + ctx->exLast = ctx->exNext; +#else /* * The pollfd structure uses separate fields for * the input and output events (corresponding to * the ??Next and ??Last fd sets), so there's no * need to copy one to the other. */ -#else - /* XXX need to copy only the bits we are using. */ - ctx->rdLast = ctx->rdNext; - ctx->wrLast = ctx->wrNext; - ctx->exLast = ctx->exNext; -#endif /* SUNW_POLL */ - +#endif /* USE_POLL */ if (m == Timer) { INSIST(tp == &t); t = evSubTime(nextTime, ctx->lastEventTime); } -#ifdef SUNW_POLL -#else - evPrintf(ctx, 4, - "pselect(%d, 0x%lx, 0x%lx, 0x%lx, %ld.%09ld)\n", - ctx->fdMax+1, - (u_long)ctx->rdLast.fds_bits[0], - (u_long)ctx->wrLast.fds_bits[0], - (u_long)ctx->exLast.fds_bits[0], - tp ? (long)tp->tv_sec : -1L, - tp ? tp->tv_nsec : -1); -#endif - /* XXX should predict system's earliness and adjust. */ x = pselect(ctx->fdMax+1, &ctx->rdLast, &ctx->wrLast, &ctx->exLast, tp, NULL); pselect_errno = errno; -#ifdef SUNW_POLL - evPrintf(ctx, 4, "poll() returns %d (err: %s)\n", - x, (x == -1) ? strerror(errno) : "none"); -#else +#ifndef USE_POLL evPrintf(ctx, 4, "select() returns %d (err: %s)\n", x, (x == -1) ? strerror(errno) : "none"); -#endif /* SUNW_POLL */ - +#else + evPrintf(ctx, 4, "poll() returns %d (err: %s)\n", + x, (x == -1) ? strerror(errno) : "none"); +#endif /* USE_POLL */ /* Anything but a poll can change the time. */ if (m != JustPoll) ctx->lastEventTime = evNowTime(); @@ -644,14 +620,17 @@ evDrop(evContext opaqueCtx, evEvent opaqueEv) { * Timer is still there. Delete it if it has expired, * otherwise set it according to its next interval. */ - if (this->inter.tv_sec == 0 && this->inter.tv_nsec == 0L) { + if (this->inter.tv_sec == (time_t)0 && + this->inter.tv_nsec == 0L) { opaque.opaque = this; (void) evClearTimer(opaqueCtx, opaque); } else { opaque.opaque = this; (void) evResetTimer(opaqueCtx, opaque, this->func, this->uap, - evAddTime(ctx->lastEventTime, + evAddTime((this->mode & EV_TMR_RATE) ? + this->due : + ctx->lastEventTime, this->inter), this->inter); } @@ -702,7 +681,56 @@ evPrintf(const evContext_p *ctx, int level, const char *fmt, ...) { va_end(ap); } -#ifdef NEED_PSELECT +int +evSetOption(evContext *opaqueCtx, const char *option, int value) { + /* evContext_p *ctx = opaqueCtx->opaque; */ + + UNUSED(opaqueCtx); + UNUSED(value); +#ifndef CLOCK_MONOTONIC + UNUSED(option); +#endif + +#ifdef CLOCK_MONOTONIC + if (strcmp(option, "monotime") == 0) { + if (opaqueCtx != NULL) + errno = EINVAL; + if (value == 0 || value == 1) { + __evOptMonoTime = value; + return (0); + } else { + errno = EINVAL; + return (-1); + } + } +#endif + errno = ENOENT; + return (-1); +} + +int +evGetOption(evContext *opaqueCtx, const char *option, int *value) { + /* evContext_p *ctx = opaqueCtx->opaque; */ + + UNUSED(opaqueCtx); +#ifndef CLOCK_MONOTONIC + UNUSED(value); + UNUSED(option); +#endif + +#ifdef CLOCK_MONOTONIC + if (strcmp(option, "monotime") == 0) { + if (opaqueCtx != NULL) + errno = EINVAL; + *value = __evOptMonoTime; + return (0); + } +#endif + errno = ENOENT; + return (-1); +} + +#if defined(NEED_PSELECT) || defined(USE_POLL) /* XXX needs to move to the porting library. */ static int pselect(int nfds, void *rfds, void *wfds, void *efds, @@ -712,52 +740,53 @@ pselect(int nfds, void *rfds, void *wfds, void *efds, struct timeval tv, *tvp; sigset_t sigs; int n; -#ifdef SUNW_POLL - int polltimeout = INFTIM; +#ifdef USE_POLL + int polltimeout = INFTIM; evContext_p *ctx; struct pollfd *fds; nfds_t pnfds; -#endif + + UNUSED(nfds); +#endif /* USE_POLL */ if (tsp) { tvp = &tv; tv = evTimeVal(*tsp); -#ifdef SUNW_POLL - polltimeout = 1000*tv.tv_sec + tv.tv_usec/1000; -#endif +#ifdef USE_POLL + polltimeout = 1000 * tv.tv_sec + tv.tv_usec / 1000; +#endif /* USE_POLL */ } else tvp = NULL; if (sigmask) sigprocmask(SIG_SETMASK, sigmask, &sigs); -#ifdef SUNW_POLL - /* +#ifndef USE_POLL + n = select(nfds, rfds, wfds, efds, tvp); +#else + /* * rfds, wfds, and efds should all be from the same evContext_p, * so any of them will do. If they're all NULL, the caller is * presumably calling us to block. */ - if (rfds != 0) + if (rfds != NULL) ctx = ((__evEmulMask *)rfds)->ctx; - else if (wfds != 0) + else if (wfds != NULL) ctx = ((__evEmulMask *)wfds)->ctx; - else if (efds != 0) + else if (efds != NULL) ctx = ((__evEmulMask *)efds)->ctx; else - ctx = 0; - if (ctx != 0) { + ctx = NULL; + if (ctx != NULL && ctx->fdMax != -1) { fds = &(ctx->pollfds[ctx->firstfd]); pnfds = ctx->fdMax - ctx->firstfd + 1; } else { - fds = 0; + fds = NULL; pnfds = 0; } n = poll(fds, pnfds, polltimeout); - /* - * pselect() should return the total number of events on the file - * descriptors, not just the count of fd:s with activity. Hence, - * traverse the pollfds array and count the events. - */ if (n > 0) { - int i, e; + int i, e; + + INSIST(ctx != NULL); for (e = 0, i = ctx->firstfd; i <= ctx->fdMax; i++) { if (ctx->pollfds[i].fd < 0) continue; @@ -770,9 +799,7 @@ pselect(int nfds, void *rfds, void *wfds, void *efds, } n = e; } -#else - n = select(nfds, rfds, wfds, efds, tvp); -#endif /* SUNW_POLL */ +#endif /* USE_POLL */ if (sigmask) sigprocmask(SIG_SETMASK, &sigs, NULL); if (tsp) @@ -781,70 +808,62 @@ pselect(int nfds, void *rfds, void *wfds, void *efds, } #endif -#ifdef SUNW_POLL -void +#ifdef USE_POLL +int evPollfdRealloc(evContext_p *ctx, int pollfd_chunk_size, int fd) { - - int old_maxnfds = ctx->maxnfds; - int i; - - if (fd < old_maxnfds) - return; - + + int i, maxnfds; + void *pollfds, *fdTable; + + if (fd < ctx->maxnfds) + return (0); + /* Don't allow ridiculously small values for pollfd_chunk_size */ if (pollfd_chunk_size < 20) pollfd_chunk_size = 20; - - ctx->maxnfds = (1 + (fd/pollfd_chunk_size)) * pollfd_chunk_size; - - ctx->pollfds = realloc(ctx->pollfds, - ctx->maxnfds * sizeof(*ctx->pollfds)); - ctx->fdTable = realloc(ctx->fdTable, - ctx->maxnfds * sizeof(*ctx->fdTable)); - - if (ctx->pollfds == 0 || ctx->fdTable == 0) { - evPrintf(ctx, 2, "pollfd() realloc (%lu) failed\n", - ctx->maxnfds*sizeof(struct pollfd)); - exit(1); + + maxnfds = (1 + (fd/pollfd_chunk_size)) * pollfd_chunk_size; + + pollfds = realloc(ctx->pollfds, maxnfds * sizeof(*ctx->pollfds)); + if (pollfds != NULL) + ctx->pollfds = pollfds; + fdTable = realloc(ctx->fdTable, maxnfds * sizeof(*ctx->fdTable)); + if (fdTable != NULL) + ctx->fdTable = fdTable; + + if (pollfds == NULL || fdTable == NULL) { + evPrintf(ctx, 2, "pollfd() realloc (%ld) failed\n", + (long)maxnfds*sizeof(struct pollfd)); + return (-1); } - - for (i = old_maxnfds; i < ctx->maxnfds; i++) { + + for (i = ctx->maxnfds; i < maxnfds; i++) { ctx->pollfds[i].fd = -1; ctx->pollfds[i].events = 0; ctx->fdTable[i] = 0; } -} -/* - * Neither evPollfdAdd() nor evPollfdDel() are needed anymore. We keep - * them as no-ops for now so that the in.named code doesn't have to change. - */ -void -evPollfdAdd(evContext opaqueCtx, int pollfd_chunk_size, int fd, short events) -{ -} + ctx->maxnfds = maxnfds; -void -evPollfdDel(evContext opaqueCtx, int fd) -{ + return (0); } - + /* Find the appropriate 'events' or 'revents' field in the pollfds array */ short * __fd_eventfield(int fd, __evEmulMask *maskp) { - - evContext_p *ctx = (evContext_p *)maskp->ctx; - + + evContext_p *ctx = (evContext_p *)maskp->ctx; + if (!maskp->result || maskp->type == EV_WASNONBLOCKING) return (&(ctx->pollfds[fd].events)); else return (&(ctx->pollfds[fd].revents)); } - + /* Translate to poll(2) event */ short __poll_event(__evEmulMask *maskp) { - + switch ((maskp)->type) { case EV_READ: return (POLLRDNORM); @@ -858,7 +877,7 @@ __poll_event(__evEmulMask *maskp) { return (0); } } - + /* * Clear the events corresponding to the specified mask. If this leaves * the events mask empty (apart from the POLLHUP bit), set the fd field @@ -866,20 +885,30 @@ __poll_event(__evEmulMask *maskp) { */ void __fd_clr(int fd, __evEmulMask *maskp) { - - evContext_p *ctx = maskp->ctx; - + + evContext_p *ctx = maskp->ctx; + *__fd_eventfield(fd, maskp) &= ~__poll_event(maskp); if ((ctx->pollfds[fd].events & ~POLLHUP) == 0) { ctx->pollfds[fd].fd = -1; - for ( ; ctx->fdMax > 0 && ctx->pollfds[ctx->fdMax].fd < 0; - ctx->fdMax--); - for ( ; ctx->firstfd <= ctx->fdMax && - ctx->pollfds[ctx->firstfd].fd < 0; - ctx->firstfd++); + if (fd == ctx->fdMax) + while (ctx->fdMax > ctx->firstfd && + ctx->pollfds[ctx->fdMax].fd < 0) + ctx->fdMax--; + if (fd == ctx->firstfd) + while (ctx->firstfd <= ctx->fdMax && + ctx->pollfds[ctx->firstfd].fd < 0) + ctx->firstfd++; + /* + * Do we have a empty set of descriptors? + */ + if (ctx->firstfd > ctx->fdMax) { + ctx->fdMax = -1; + ctx->firstfd = 0; + } } } - + /* * Set the events bit(s) corresponding to the specified mask. If the events * field has any other bits than POLLHUP set, also set the fd field so that @@ -887,16 +916,18 @@ __fd_clr(int fd, __evEmulMask *maskp) { */ void __fd_set(int fd, __evEmulMask *maskp) { - - evContext_p *ctx = maskp->ctx; + + evContext_p *ctx = maskp->ctx; *__fd_eventfield(fd, maskp) |= __poll_event(maskp); if ((ctx->pollfds[fd].events & ~POLLHUP) != 0) { ctx->pollfds[fd].fd = fd; - if (fd < ctx->firstfd || ctx->firstfd == 0) + if (fd < ctx->firstfd || ctx->fdMax == -1) ctx->firstfd = fd; if (fd > ctx->fdMax) ctx->fdMax = fd; } } -#endif +#endif /* USE_POLL */ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/eventlib_p.h b/usr/src/lib/libresolv2/common/isc/eventlib_p.h index 32b47c1c9c..0a3614ab23 100644 --- a/usr/src/lib/libresolv2/common/isc/eventlib_p.h +++ b/usr/src/lib/libresolv2/common/isc/eventlib_p.h @@ -1,31 +1,25 @@ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2005 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1995-1999 by Internet Software Consortium * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - -/* eventlib_p.h - private interfaces for eventlib - * vix 09sep95 [initial] +/*! \file + * \brief private interfaces for eventlib + * \author vix 09sep95 [initial] * - * $Id: eventlib_p.h,v 1.31 2003/04/03 05:37:56 marka Exp $ + * $Id: eventlib_p.h,v 1.9 2006/03/09 23:57:56 marka Exp $ */ #ifndef _EVENTLIB_P_H @@ -52,6 +46,8 @@ #define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT) #define EV_ERR(e) return (errno = (e), -1) #define OK(x) if ((x) < 0) EV_ERR(errno); else (void)NULL +#define OKFREE(x, y) if ((x) < 0) { FREE((y)); EV_ERR(errno); } \ + else (void)NULL #define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \ FILL(p); \ @@ -70,19 +66,21 @@ #define FILL(p) #endif -#ifdef SUNW_POLL +#ifdef USE_POLL +#ifdef HAVE_STROPTS_H #include <stropts.h> -#include <poll.h> #endif +#include <poll.h> +#endif /* USE_POLL */ typedef struct evConn { evConnFunc func; void * uap; int fd; int flags; -#define EV_CONN_LISTEN 0x0001 /* Connection is a listener. */ -#define EV_CONN_SELECTED 0x0002 /* evSelectFD(conn->file). */ -#define EV_CONN_BLOCK 0x0004 /* Listener fd was blocking. */ +#define EV_CONN_LISTEN 0x0001 /*%< Connection is a listener. */ +#define EV_CONN_SELECTED 0x0002 /*%< evSelectFD(conn->file). */ +#define EV_CONN_BLOCK 0x0004 /*%< Listener fd was blocking. */ evFileID file; struct evConn * prev; struct evConn * next; @@ -129,7 +127,7 @@ typedef struct evStream { evFileID file; evTimerID timer; int flags; -#define EV_STR_TIMEROK 0x0001 /* IFF timer valid. */ +#define EV_STR_TIMEROK 0x0001 /*%< IFF timer valid. */ int fd; struct iovec * iovOrig; int iovOrigCount; @@ -147,6 +145,8 @@ typedef struct evTimer { void * uap; struct timespec due, inter; int index; + int mode; +#define EV_TMR_RATE 1 } evTimer; typedef struct evWait { @@ -176,42 +176,39 @@ typedef struct evEvent_p { } u; } evEvent_p; -#ifdef SUNW_POLL -typedef struct { - void *ctx; /* Pointer to the evContext_p */ - uint32_t type; /* READ, WRITE, EXCEPT, nonblk */ - uint32_t result; /* 1 => revents, 0 => events */ -} __evEmulMask; +#ifdef USE_POLL +typedef struct { + void *ctx; /* pointer to the evContext_p */ + uint32_t type; /* READ, WRITE, EXCEPT, nonblk */ + uint32_t result; /* 1 => revents, 0 => events */ +} __evEmulMask; -#define emulMaskInit(ctx, field, ev, lastnext) \ +#define emulMaskInit(ctx, field, ev, lastnext) \ ctx->field.ctx = ctx; \ ctx->field.type = ev; \ - ctx->field.result = lastnext; - -/* Any value other than EV_* values from <isc/eventlib.h> will do */ -#define EV_WASNONBLOCKING 4000000001U - -extern short *__fd_eventfield(int fd, __evEmulMask *maskp); -extern short __poll_event(__evEmulMask *maskp); -extern void __fd_clr(int fd, __evEmulMask *maskp); -extern void __fd_set(int fd, __evEmulMask *maskp); - -#undef FD_ZERO -#define FD_ZERO(maskp) - -#undef FD_SET -#define FD_SET(fd, maskp) \ - __fd_set(fd, maskp) - -#undef FD_CLR -#define FD_CLR(fd, maskp) \ - __fd_clr(fd, maskp) - -#undef FD_ISSET -#define FD_ISSET(fd, maskp) \ - ((*__fd_eventfield(fd, maskp) & __poll_event(maskp)) != 0) - -#endif /* SUNW_POLL */ + ctx->field.result = lastnext; + +extern short *__fd_eventfield(int fd, __evEmulMask *maskp); +extern short __poll_event(__evEmulMask *maskp); +extern void __fd_clr(int fd, __evEmulMask *maskp); +extern void __fd_set(int fd, __evEmulMask *maskp); + +#undef FD_ZERO +#define FD_ZERO(maskp) + +#undef FD_SET +#define FD_SET(fd, maskp) \ + __fd_set(fd, maskp) + +#undef FD_CLR +#define FD_CLR(fd, maskp) \ + __fd_clr(fd, maskp) + +#undef FD_ISSET +#define FD_ISSET(fd, maskp) \ + ((*__fd_eventfield(fd, maskp) & __poll_event(maskp)) != 0) + +#endif /* USE_POLL */ typedef struct { /* Global. */ @@ -224,26 +221,26 @@ typedef struct { LIST(evAccept) accepts; /* Files. */ evFile *files, *fdNext; -#ifdef SUNW_POLL - struct pollfd *pollfds; /* Allocated as needed */ - evFile **fdTable; /* Ditto */ - int maxnfds; /* # elements in above */ - int firstfd; /* First active fd */ - int fdMax; /* Last active fd */ - int fdCount; /* # fd:s with I/O */ - int highestFD; /* Max fd allowed by OS */ - __evEmulMask rdLast, rdNext; - __evEmulMask wrLast, wrNext; - __evEmulMask exLast, exNext; - __evEmulMask nonblockBefore; -#else +#ifndef USE_POLL fd_set rdLast, rdNext; fd_set wrLast, wrNext; fd_set exLast, exNext; fd_set nonblockBefore; int fdMax, fdCount, highestFD; evFile *fdTable[FD_SETSIZE]; -#endif +#else + struct pollfd *pollfds; /* Allocated as needed */ + evFile **fdTable; /* Ditto */ + int maxnfds; /* # elements in above */ + int firstfd; /* First active fd */ + int fdMax; /* Last active fd */ + int fdCount; /* # fd:s with I/O */ + int highestFD; /* max fd allowed by OS */ + __evEmulMask rdLast, rdNext; + __evEmulMask wrLast, wrNext; + __evEmulMask exLast, exNext; + __evEmulMask nonblockBefore; +#endif /* USE_POLL */ #ifdef EVENTLIB_TIME_CHECKS struct timespec lastSelectTime; int lastFdCount; @@ -264,9 +261,9 @@ typedef struct { void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...) ISC_FORMAT_PRINTF(3, 4); -#ifdef SUNW_POLL -extern void evPollfdRealloc(evContext_p *ctx, int pollfd_chunk_size, int fd); -#endif /* SUNW_POLL */ +#ifdef USE_POLL +extern int evPollfdRealloc(evContext_p *ctx, int pollfd_chunk_size, int fd); +#endif /* USE_POLL */ /* ev_timers.c */ #define evCreateTimers __evCreateTimers @@ -278,4 +275,7 @@ void evDestroyTimers(const evContext_p *); #define evFreeWait __evFreeWait evWait *evFreeWait(evContext_p *ctx, evWait *old); +/* Global options */ +extern int __evOptMonoTime; + #endif /*_EVENTLIB_P_H*/ diff --git a/usr/src/lib/libresolv2/common/isc/heap.c b/usr/src/lib/libresolv2/common/isc/heap.c index 72c823d9d8..3d22b6fc71 100644 --- a/usr/src/lib/libresolv2/common/isc/heap.c +++ b/usr/src/lib/libresolv2/common/isc/heap.c @@ -1,28 +1,21 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1997,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - -/* +/*% * Heap implementation of priority queues adapted from the following: * * _Introduction to Algorithms_, Cormen, Leiserson, and Rivest, @@ -33,7 +26,7 @@ */ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: heap.c,v 8.7 1999/10/13 16:39:34 vixie Exp $"; +static const char rcsid[] = "$Id: heap.c,v 1.4 2006/03/09 23:57:56 marka Exp $"; #endif /* not lint */ #include "port_before.h" @@ -46,7 +39,7 @@ static const char rcsid[] = "$Id: heap.c,v 8.7 1999/10/13 16:39:34 vixie Exp $"; #include <isc/heap.h> -/* +/*% * Note: to make heap_parent and heap_left easy to compute, the first * element of the heap array is not used; i.e. heap subscripts are 1-based, * not 0-based. @@ -61,9 +54,13 @@ heap_new(heap_higher_priority_func higher_priority, heap_index_func index, int array_size_increment) { heap_context ctx; + if (higher_priority == NULL) + return (NULL); + ctx = (heap_context)malloc(sizeof (struct heap_context)); - if (ctx == NULL || higher_priority == NULL) + if (ctx == NULL) return (NULL); + ctx->array_size = 0; if (array_size_increment == 0) ctx->array_size_increment = ARRAY_SIZE_INCREMENT; @@ -166,15 +163,24 @@ heap_insert(heap_context ctx, void *elt) { int heap_delete(heap_context ctx, int i) { void *elt; + int less; if (ctx == NULL || i < 1 || i > ctx->heap_size) { errno = EINVAL; return (-1); } - elt = ctx->heap[ctx->heap_size]; - if (--ctx->heap_size > 0) - sink_down(ctx, i, elt); + if (i == ctx->heap_size) { + ctx->heap_size--; + } else { + elt = ctx->heap[ctx->heap_size--]; + less = ctx->higher_priority(elt, ctx->heap[i]); + ctx->heap[i] = elt; + if (less) + float_up(ctx, i, ctx->heap[i]); + else + sink_down(ctx, i, ctx->heap[i]); + } return (0); } @@ -226,3 +232,5 @@ heap_for_each(heap_context ctx, heap_for_each_func action, void *uap) { (action)(ctx->heap[i], uap); return (0); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/hex.c b/usr/src/lib/libresolv2/common/isc/hex.c index 5e1f6e8364..e43be4f3b5 100644 --- a/usr/src/lib/libresolv2/common/isc/hex.c +++ b/usr/src/lib/libresolv2/common/isc/hex.c @@ -1,27 +1,20 @@ /* - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 2001 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <port_before.h> #include <ctype.h> #include <stdio.h> @@ -40,7 +33,7 @@ isc_gethexstring(unsigned char *buf, size_t len, int count, FILE *fp, char *s; int result = count; - x = 0; /* silence compiler */ + x = 0; /*%< silence compiler */ n = 0; while (count > 0) { c = fgetc(fp); @@ -52,8 +45,9 @@ isc_gethexstring(unsigned char *buf, size_t len, int count, FILE *fp, goto formerr; /* comment */ if (c == ';') { - while ((c = fgetc(fp)) != EOF && c != '\n') - /* empty */ + do { + c = fgetc(fp); + } while (c != EOF && c != '\n'); if (c == '\n' && *multiline) continue; goto formerr; @@ -70,7 +64,7 @@ isc_gethexstring(unsigned char *buf, size_t len, int count, FILE *fp, goto formerr; x = (x<<4) | (s - hex); if (++n == 2) { - if (len > 0) { + if (len > 0U) { *buf++ = x; len--; } else @@ -93,11 +87,11 @@ isc_puthexstring(FILE *fp, const unsigned char *buf, size_t buflen, { size_t i = 0; - if (len1 < 4) + if (len1 < 4U) len1 = 4; - if (len2 < 4) + if (len2 < 4U) len2 = 4; - while (buflen > 0) { + while (buflen > 0U) { fputc(hex[(buf[0]>>4)&0xf], fp); fputc(hex[buf[0]&0xf], fp); i += 2; @@ -113,7 +107,7 @@ isc_puthexstring(FILE *fp, const unsigned char *buf, size_t buflen, void isc_tohex(const unsigned char *buf, size_t buflen, char *t) { - while (buflen > 0) { + while (buflen > 0U) { *t++ = hex[(buf[0]>>4)&0xf]; *t++ = hex[buf[0]&0xf]; buf++; @@ -121,3 +115,5 @@ isc_tohex(const unsigned char *buf, size_t buflen, char *t) { } *t = '\0'; } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/logging.c b/usr/src/lib/libresolv2/common/isc/logging.c index f279ea525d..8c2af2b9e3 100644 --- a/usr/src/lib/libresolv2/common/isc/logging.c +++ b/usr/src/lib/libresolv2/common/isc/logging.c @@ -1,29 +1,22 @@ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Copyright (c) 1996-1999 by Internet Software Consortium. + * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1996-1999, 2001, 2003 Internet Software Consortium. * - * Permission to use, copy, modify, and distribute this software for any + * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: logging.c,v 8.32 2003/01/02 00:35:42 marka Exp $"; +static const char rcsid[] = "$Id: logging.c,v 1.9 2008/11/14 02:36:51 marka Exp $"; #endif /* not lint */ #include "port_before.h" @@ -50,12 +43,6 @@ static const char rcsid[] = "$Id: logging.c,v 8.32 2003/01/02 00:35:42 marka Exp #include "port_after.h" -#ifdef VSPRINTF_CHAR -# define VSPRINTF(x) strlen(vsprintf/**/x) -#else -# define VSPRINTF(x) ((size_t)vsprintf x) -#endif - #include "logging_p.h" static const int syslog_priority[] = { LOG_DEBUG, LOG_INFO, LOG_NOTICE, @@ -73,7 +60,7 @@ version_rename(log_channel chan) { unsigned int ver; char old_name[PATH_MAX+1]; char new_name[PATH_MAX+1]; - + ver = chan->out.file.versions; if (ver < 1) return; @@ -82,15 +69,15 @@ version_rename(log_channel chan) { /* * Need to have room for '.nn' (XXX assumes LOG_MAX_VERSIONS < 100) */ - if (strlen(chan->out.file.name) > (PATH_MAX-3)) + if (strlen(chan->out.file.name) > (size_t)(PATH_MAX-3)) return; for (ver--; ver > 0; ver--) { sprintf(old_name, "%s.%d", chan->out.file.name, ver-1); sprintf(new_name, "%s.%d", chan->out.file.name, ver); - (void)rename(old_name, new_name); + (void)isc_movefile(old_name, new_name); } sprintf(new_name, "%s.0", chan->out.file.name); - (void)rename(chan->out.file.name, new_name); + (void)isc_movefile(chan->out.file.name, new_name); } FILE * @@ -104,7 +91,7 @@ log_open_stream(log_channel chan) { errno = EINVAL; return (NULL); } - + /* * Don't open already open streams */ @@ -121,7 +108,7 @@ log_open_stream(log_channel chan) { } regular = 1; } else - regular = S_ISREG(sb.st_mode); + regular = (sb.st_mode & S_IFREG); if (chan->out.file.versions) { if (!regular) { @@ -158,11 +145,7 @@ log_open_stream(log_channel chan) { chan->flags |= LOG_CHANNEL_BROKEN; return (NULL); } -#ifdef SUNW_AVOIDSTDIO_FDLIMIT - stream = fdopen(fd, "aF"); -#else stream = fdopen(fd, "a"); -#endif if (stream == NULL) { syslog(LOG_ERR, "log_open_stream: fdopen() failed"); chan->flags |= LOG_CHANNEL_BROKEN; @@ -253,7 +236,7 @@ log_check_channel(log_context lc, int level, log_channel chan) { return (1); } -int +int log_check(log_context lc, int category, int level) { log_channel_list lcl; int debugging; @@ -269,7 +252,7 @@ log_check(log_context lc, int category, int level) { return (0); if (category < 0 || category > lc->num_categories) - category = 0; /* use default */ + category = 0; /*%< use default */ lcl = lc->categories[category]; if (lcl == NULL) { category = 0; @@ -284,7 +267,7 @@ log_check(log_context lc, int category, int level) { } void -log_vwrite(log_context lc, int category, int level, const char *format, +log_vwrite(log_context lc, int category, int level, const char *format, va_list args) { log_channel_list lcl; int pri, debugging, did_vsprintf = 0; @@ -313,7 +296,7 @@ log_vwrite(log_context lc, int category, int level, const char *format, return; if (category < 0 || category > lc->num_categories) - category = 0; /* use default */ + category = 0; /*%< use default */ original_category = category; lcl = lc->categories[category]; if (lcl == NULL) { @@ -374,8 +357,8 @@ log_vwrite(log_context lc, int category, int level, const char *format, continue; if (!did_vsprintf) { - if (VSPRINTF((lc->buffer, format, args)) > - LOG_BUFFER_SIZE) { + (void)vsprintf(lc->buffer, format, args); + if (strlen(lc->buffer) > (size_t)LOG_BUFFER_SIZE) { syslog(LOG_CRIT, "memory overrun in log_vwrite()"); exit(1); @@ -407,7 +390,7 @@ log_vwrite(log_context lc, int category, int level, const char *format, } if (chan->out.file.max_size != ULONG_MAX) { long pos; - + pos = ftell(stream); if (pos >= 0 && (unsigned long)pos > @@ -425,7 +408,7 @@ log_vwrite(log_context lc, int category, int level, const char *format, break; } } - fprintf(stream, "%s%s%s%s\n", + fprintf(stream, "%s%s%s%s\n", (chan->flags & LOG_TIMESTAMP) ? time_buf : "", (chan->flags & LOG_PRINT_CATEGORY) ? category_name : "", @@ -452,7 +435,7 @@ log_write(log_context lc, int category, int level, const char *format, ...) { va_end(args); } -/* +/*% * Functions to create, set, or destroy contexts */ @@ -626,9 +609,9 @@ log_new_file_channel(unsigned int flags, int level, chan->level = level; if (name != NULL) { size_t len; - + len = strlen(name); - /* + /* * Quantize length to a multiple of 256. There's space for the * NUL, since if len is a multiple of 256, the size chosen will * be the next multiple. @@ -705,7 +688,7 @@ log_dec_references(log_channel chan) { log_channel_type log_get_channel_type(log_channel chan) { REQUIRE(chan != NULL); - + return (chan->type); } @@ -729,3 +712,5 @@ log_free_channel(log_channel chan) { } return (0); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/logging_p.h b/usr/src/lib/libresolv2/common/isc/logging_p.h index d85af6f2fc..5e6314f190 100644 --- a/usr/src/lib/libresolv2/common/isc/logging_p.h +++ b/usr/src/lib/libresolv2/common/isc/logging_p.h @@ -1,27 +1,20 @@ /* - * Copyright (c) 1997-2001 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #ifndef LOGGING_P_H #define LOGGING_P_H @@ -41,7 +34,7 @@ typedef union log_output { } log_output; struct log_channel { - int level; /* don't log messages > level */ + int level; /*%< don't log messages > level */ log_channel_type type; log_output out; unsigned int flags; @@ -65,3 +58,4 @@ struct log_context { }; #endif /* !LOGGING_P_H */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/memcluster.c b/usr/src/lib/libresolv2/common/isc/memcluster.c index 03fb6d3c8b..515793fd6a 100644 --- a/usr/src/lib/libresolv2/common/isc/memcluster.c +++ b/usr/src/lib/libresolv2/common/isc/memcluster.c @@ -1,26 +1,20 @@ /* - * Copyright 1998-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2005 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1997,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" /* When this symbol is defined allocations via memget are made slightly bigger and some debugging info stuck before and after the region given @@ -30,7 +24,7 @@ #if !defined(LINT) && !defined(CODECENTER) -static const char rcsid[] = "$Id: memcluster.c,v 8.23 2001/06/18 14:44:05 marka Exp $"; +static const char rcsid[] = "$Id: memcluster.c,v 1.11 2006/08/30 23:34:38 marka Exp $"; #endif /* not lint */ #include "port_before.h" @@ -96,27 +90,28 @@ struct stats { u_long freefrags; }; -/* Private data. */ - -#ifdef SUNW_MT_RESOLVER -#include <thread.h> -#include <synch.h> -static mutex_t memlock = DEFAULTMUTEX; -#define SUNW_MEMLOCK (void)mutex_lock(&memlock) -#define SUNW_MEMUNLOCK (void)mutex_unlock(&memlock) -#define SUNW_MEMLOCKBLOCK_BEGIN { -#define SUNW_MEMLOCKBLOCK_END } +#ifdef DO_PTHREADS +#include <pthread.h> +static pthread_mutex_t memlock = PTHREAD_MUTEX_INITIALIZER; +#define MEMLOCK (void)pthread_mutex_lock(&memlock) +#define MEMUNLOCK (void)pthread_mutex_unlock(&memlock) #else -#define SUNW_MEMLOCK -#define SUNW_MEMUNLOCK -#define SUNW_MEMLOCKBLOCK_BEGIN -#define SUNW_MEMLOCKBLOCK_END -#endif /* SUNW_MT_RESOLVER */ +/* + * Catch bad lock usage in non threaded build. + */ +static unsigned int memlock = 0; +#define MEMLOCK do { INSIST(memlock == 0); memlock = 1; } while (0) +#define MEMUNLOCK do { INSIST(memlock == 1); memlock = 0; } while (0) +#endif /* DO_PTHEADS */ + +/* Private data. */ static size_t max_size; static size_t mem_target; +#ifndef MEMCLUSTER_BIG_MALLOC static size_t mem_target_half; static size_t mem_target_fudge; +#endif static memcluster_element ** freelists; #ifdef MEMCLUSTER_RECORD static memcluster_element ** activelists; @@ -145,16 +140,18 @@ meminit(size_t init_max_size, size_t target_size) { errno = EEXIST; return (-1); } - if (init_max_size == 0) + if (init_max_size == 0U) max_size = DEF_MAX_SIZE; else max_size = init_max_size; - if (target_size == 0) + if (target_size == 0U) mem_target = DEF_MEM_TARGET; else mem_target = target_size; +#ifndef MEMCLUSTER_BIG_MALLOC mem_target_half = mem_target / 2; mem_target_fudge = mem_target + mem_target / 4; +#endif freelists = malloc(max_size * sizeof (memcluster_element *)); stats = malloc((max_size+1) * sizeof (struct stats)); if (freelists == NULL || stats == NULL) { @@ -194,20 +191,20 @@ __memget_record(size_t size, const char *file, int line) { #endif void *ret; - SUNW_MEMLOCK; + MEMLOCK; #if !defined(MEMCLUSTER_RECORD) UNUSED(file); UNUSED(line); #endif - if (freelists == NULL) - if (meminit(0, 0) == -1) -SUNW_MEMLOCKBLOCK_BEGIN - SUNW_MEMUNLOCK; + if (freelists == NULL) { + if (meminit(0, 0) == -1) { + MEMUNLOCK; return (NULL); -SUNW_MEMLOCKBLOCK_END - if (size == 0) { - SUNW_MEMUNLOCK; + } + } + if (size == 0U) { + MEMUNLOCK; errno = EINVAL; return (NULL); } @@ -218,7 +215,7 @@ SUNW_MEMLOCKBLOCK_END #if defined(DEBUGGING_MEMCLUSTER) e = malloc(new_size); if (e == NULL) { - SUNW_MEMUNLOCK; + MEMUNLOCK; errno = ENOMEM; return (NULL); } @@ -230,13 +227,13 @@ SUNW_MEMLOCKBLOCK_END e->next = activelists[max_size]; activelists[max_size] = e; #endif - SUNW_MEMUNLOCK; + MEMUNLOCK; e->fencepost = FRONT_FENCEPOST; p = (char *)e + sizeof *e + size; memcpy(p, &fp, sizeof fp); return ((char *)e + sizeof *e); #else - SUNW_MEMUNLOCK; + MEMUNLOCK; return (malloc(size)); #endif } @@ -256,7 +253,7 @@ SUNW_MEMLOCKBLOCK_END if (basic_blocks == NULL) { new = malloc(NUM_BASIC_BLOCKS * mem_target); if (new == NULL) { - SUNW_MEMUNLOCK; + MEMUNLOCK; errno = ENOMEM; return (NULL); } @@ -284,7 +281,7 @@ SUNW_MEMLOCKBLOCK_END total_size = mem_target; new = malloc(total_size); if (new == NULL) { - SUNW_MEMUNLOCK; + MEMUNLOCK; errno = ENOMEM; return (NULL); } @@ -350,7 +347,7 @@ SUNW_MEMLOCKBLOCK_END stats[size].gets++; stats[size].totalgets++; stats[new_size].freefrags--; - SUNW_MEMUNLOCK; + MEMUNLOCK; #if defined(DEBUGGING_MEMCLUSTER) return ((char *)e + sizeof *e); #else @@ -358,7 +355,7 @@ SUNW_MEMLOCKBLOCK_END #endif } -/* +/*% * This is a call from an external caller, * so we want to count this as a user "put". */ @@ -380,7 +377,7 @@ __memput_record(void *mem, size_t size, const char *file, int line) { char *p; #endif - SUNW_MEMLOCK; + MEMLOCK; #if !defined (MEMCLUSTER_RECORD) UNUSED(file); @@ -389,8 +386,8 @@ __memput_record(void *mem, size_t size, const char *file, int line) { REQUIRE(freelists != NULL); - if (size == 0) { - SUNW_MEMUNLOCK; + if (size == 0U) { + MEMUNLOCK; errno = EINVAL; return; } @@ -402,7 +399,7 @@ __memput_record(void *mem, size_t size, const char *file, int line) { p = (char *)e + sizeof *e + size; memcpy(&fp, p, sizeof fp); INSIST(fp == BACK_FENCEPOST); - INSIST(((int)mem % 4) == 0); + INSIST(((u_long)mem % 4) == 0); #ifdef MEMCLUSTER_RECORD prev = NULL; if (size == max_size || new_size >= max_size) @@ -413,7 +410,7 @@ __memput_record(void *mem, size_t size, const char *file, int line) { prev = el; el = el->next; } - INSIST(el != NULL); /* double free */ + INSIST(el != NULL); /*%< double free */ if (prev == NULL) { if (size == max_size || new_size >= max_size) activelists[max_size] = el->next; @@ -432,16 +429,16 @@ __memput_record(void *mem, size_t size, const char *file, int line) { free(mem); #endif - INSIST(stats[max_size].gets != 0); + INSIST(stats[max_size].gets != 0U); stats[max_size].gets--; - SUNW_MEMUNLOCK; + MEMUNLOCK; return; } /* The free list uses the "rounded-up" size "new_size": */ #if defined(DEBUGGING_MEMCLUSTER) - memset(mem, 0xa5, new_size - sizeof *e); /* catch write after free */ - e->size = 0; /* catch double memput() */ + memset(mem, 0xa5, new_size - sizeof *e); /*%< catch write after free */ + e->size = 0; /*%< catch double memput() */ #ifdef MEMCLUSTER_RECORD e->file = file; e->line = line; @@ -470,10 +467,10 @@ __memput_record(void *mem, size_t size, const char *file, int line) { * max. size (max_size) ends up getting recorded as a call to * max_size. */ - INSIST(stats[size].gets != 0); + INSIST(stats[size].gets != 0U); stats[size].gets--; stats[new_size].freefrags++; - SUNW_MEMUNLOCK; + MEMUNLOCK; } void * @@ -492,7 +489,7 @@ __memput_debug(void *ptr, size_t size, const char *file, int line) { __memput_record(ptr, size, file, line); } -/* +/*% * Print the stats[] on the stream "out" with suitable formatting. */ void @@ -502,21 +499,21 @@ memstats(FILE *out) { memcluster_element *e; #endif - SUNW_MEMLOCK; - if (freelists == NULL) -SUNW_MEMLOCKBLOCK_BEGIN - SUNW_MEMUNLOCK; + MEMLOCK; + + if (freelists == NULL) { + MEMUNLOCK; return; -SUNW_MEMLOCKBLOCK_END + } for (i = 1; i <= max_size; i++) { const struct stats *s = &stats[i]; - if (s->totalgets == 0 && s->gets == 0) + if (s->totalgets == 0U && s->gets == 0U) continue; - fprintf(out, "%s%5d: %11lu gets, %11lu rem", + fprintf(out, "%s%5lu: %11lu gets, %11lu rem", (i == max_size) ? ">=" : " ", - i, s->totalgets, s->gets); - if (s->blocks != 0) + (unsigned long)i, s->totalgets, s->gets); + if (s->blocks != 0U) fprintf(out, " (%lu bl, %lu ff)", s->blocks, s->freefrags); fputc('\n', out); @@ -526,15 +523,16 @@ SUNW_MEMLOCKBLOCK_END for (i = 1; i <= max_size; i++) { if ((e = activelists[i]) != NULL) while (e != NULL) { - fprintf(out, "%s:%d %p:%d\n", + fprintf(out, "%s:%d %p:%lu\n", e->file != NULL ? e->file : "<UNKNOWN>", e->line, - (char *)e + sizeof *e, e->size); + (char *)e + sizeof *e, + (u_long)e->size); e = e->next; } } #endif - SUNW_MEMUNLOCK; + MEMUNLOCK; } int @@ -544,14 +542,14 @@ memactive(void) { if (stats == NULL) return (0); for (i = 1; i <= max_size; i++) - if (stats[i].gets != 0) + if (stats[i].gets != 0U) return (1); return (0); } /* Private. */ -/* +/*% * Round up size to a multiple of sizeof(void *). This guarantees that a * block is at least sizeof void *, and that we won't violate alignment * restrictions, both of which are needed to make lists of blocks. @@ -586,3 +584,5 @@ check(unsigned char *a, int value, size_t len) { INSIST(a[i] == value); } #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/movefile.c b/usr/src/lib/libresolv2/common/isc/movefile.c new file mode 100644 index 0000000000..0ffc7047e2 --- /dev/null +++ b/usr/src/lib/libresolv2/common/isc/movefile.c @@ -0,0 +1,43 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 2000 by Internet Software Consortium, Inc. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + + +#include <port_before.h> +#include <stdio.h> +#include <isc/misc.h> +#include <port_after.h> +#ifndef HAVE_MOVEFILE +/* + * rename() is lame (can't overwrite an existing file) on some systems. + * use movefile() instead, and let lame OS ports do what they need to. + */ + +int +isc_movefile(const char *oldname, const char *newname) { + return (rename(oldname, newname)); +} +#else + static int os_port_has_isc_movefile = 1; +#endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/isc/tree.c b/usr/src/lib/libresolv2/common/isc/tree.c index fea38085e0..8ba675fbe8 100644 --- a/usr/src/lib/libresolv2/common/isc/tree.c +++ b/usr/src/lib/libresolv2/common/isc/tree.c @@ -1,13 +1,8 @@ -/* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - #ifndef LINT -static const char rcsid[] = "$Id: tree.c,v 8.10 2001/11/01 05:33:46 marka Exp $"; +static const char rcsid[] = "$Id: tree.c,v 1.4 2005/04/27 04:56:39 sra Exp $"; #endif -/* +/*% * tree - balanced binary tree library * * vix 05apr94 [removed vixie.h dependencies; cleaned up formatting, names] @@ -19,7 +14,7 @@ static const char rcsid[] = "$Id: tree.c,v 8.10 2001/11/01 05:33:46 marka Exp $" * vix 14dec85 [written] */ -/* +/*% * This program text was created by Paul Vixie using examples from the book: * "Algorithms & Data Structures," Niklaus Wirth, Prentice-Hall, 1986, ISBN * 0-13-022005-1. Any errors in the conversion from Modula-2 to C are Paul @@ -27,24 +22,22 @@ static const char rcsid[] = "$Id: tree.c,v 8.10 2001/11/01 05:33:46 marka Exp $" */ /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /*#define DEBUG "tree"*/ #include "port_before.h" @@ -209,11 +202,7 @@ sprout(tree **ppr, tree_t p_data, int *pi_balance, (*ppr)->data = p_data; *pi_balance = TRUE; } -#ifdef ORIGINAL_ISC_CODE RET(*ppr); -#else - RET(*ppr) -#endif } /* compare the data using routine passed by caller. @@ -226,7 +215,7 @@ sprout(tree **ppr, tree_t p_data, int *pi_balance, MSG("LESS. sprouting left.") sub = sprout(&(*ppr)->left, p_data, pi_balance, pfi_compare, pfv_delete); - if (sub && *pi_balance) { /* left branch has grown */ + if (sub && *pi_balance) { /*%< left branch has grown */ MSG("LESS: left branch has grown") switch ((*ppr)->bal) { case 1: @@ -244,13 +233,13 @@ sprout(tree **ppr, tree_t p_data, int *pi_balance, /* left branch was already too long. rebal */ MSG("LESS: case -1: rebalancing") p1 = (*ppr)->left; - if (p1->bal == -1) { /* LL */ + if (p1->bal == -1) { /*%< LL */ MSG("LESS: single LL") (*ppr)->left = p1->right; p1->right = *ppr; (*ppr)->bal = 0; *ppr = p1; - } else { /* double LR */ + } else { /*%< double LR */ MSG("LESS: double LR") p2 = p1->right; @@ -300,13 +289,13 @@ sprout(tree **ppr, tree_t p_data, int *pi_balance, case 1: MSG("MORE: balance was off, need to rebalance") p1 = (*ppr)->right; - if (p1->bal == 1) { /* RR */ + if (p1->bal == 1) { /*%< RR */ MSG("MORE: single RR") (*ppr)->right = p1->left; p1->left = *ppr; (*ppr)->bal = 0; *ppr = p1; - } else { /* double RL */ + } else { /*%< double RL */ MSG("MORE: double RL") p2 = p1->left; @@ -541,3 +530,5 @@ bal_R(tree **ppr_p, int *pi_balance) { } RETV } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/mapfile-vers b/usr/src/lib/libresolv2/common/mapfile-vers index cf553919f0..5ef6ef2428 100644 --- a/usr/src/lib/libresolv2/common/mapfile-vers +++ b/usr/src/lib/libresolv2/common/mapfile-vers @@ -114,7 +114,6 @@ SUNWprivate_2.2 { SUNWprivate_2.1 { global: - __areweinnamed; __assertion_failed; assertion_type_to_text; b64_ntop; @@ -134,27 +133,24 @@ SUNWprivate_2.1 { dn_count_labels; __dn_count_labels; dn_skipname; - dst_buffer_to_key; - dst_check_algorithm; - dst_dnskey_to_key; - dst_free_key; - dst_generate_key; - dst_init; - dst_key_to_buffer; - dst_random; - dst_read_key; - dst_s_calculate_bits; - dst_s_conv_bignum_b64_to_u8; - dst_s_conv_bignum_u8_to_b64; - dst_s_dns_key_id; - dst_s_get_int16; - dst_s_id_calc; - dst_sign_data; - dst_s_put_int16; - dst_s_verify_str; + __dst_buffer_to_key; + __dst_check_algorithm; + __dst_dnskey_to_key; + __dst_free_key; + __dst_generate_key; + __dst_init; + __dst_key_to_buffer; + __dst_read_key; + __dst_s_calculate_bits; + __dst_s_dns_key_id; + __dst_s_get_int16; + __dst_s_id_calc; + __dst_sign_data; + __dst_s_put_int16; + __dst_s_verify_str; dst_t_func; - dst_verify_data; - dst_write_key; + __dst_verify_data; + __dst_write_key; __evAddTime; __evCancelConn; __evCancelRW; @@ -187,11 +183,14 @@ SUNWprivate_2.1 { __h_errno; __h_errno_set; hostalias; + inet_cidr_ntop; + inet_cidr_pton; + inet_neta; inet_net_ntop; inet_net_pton; inet_nsap_addr; inet_nsap_ntoa; - irs_destroy; + __irs_destroy; __ISC_res_freeupdrec; __ISC_res_mkupdate; __ISC_res_mkupdrec; @@ -227,7 +226,7 @@ SUNWprivate_2.1 { __memput_record; __memstats; __net_data_init; - net_data_minimize; + __net_data_minimize; __ns_datetosecs; __ns_find_tsig; _ns_flagdata; @@ -237,14 +236,35 @@ SUNWprivate_2.1 { __ns_initparse; __ns_makecanon; __ns_msg_getflag; + __ns_name_compress; + __ns_name_eq; + __ns_name_labels; + __ns_name_length; + __ns_name_map; __ns_name_ntol; __ns_name_ntop; + __ns_name_owned; + __ns_name_pack; __ns_name_pton; __ns_name_rollback; + __ns_name_skip; + __ns_name_uncompress; __ns_name_unpack; + __ns_newmsg_copy; + __ns_newmsg_done; + __ns_newmsg_flag; + __ns_newmsg_id; + __ns_newmsg_init; + __ns_newmsg_q; + __ns_newmsg_rr; __ns_parserr; __ns_parse_ttl; + __ns_parserr2; __ns_put16; + __ns_put32; + __ns_rdata_equal; + __ns_rdata_refers; + __ns_rdata_unpack; __ns_samedomain; __ns_samename; __ns_sign; @@ -264,6 +284,8 @@ SUNWprivate_2.1 { __p_class_syms; p_fqnname; __p_key_syms; + p_option; + __p_option; p_query; p_rcode; p_secstodate; @@ -302,6 +324,9 @@ SUNWprivate_2.1 { res_nameinquery; __res_nameinquery; res_nisourserver; + res_nmkupdate; + res_nupdate; + __res_no_hosts_fallback; _res_opcodes; __res_override_retry; res_ownok; @@ -309,6 +334,7 @@ SUNWprivate_2.1 { res_pquery; res_queriesmatch; __res_queriesmatch; + res_rndinit; res_randomid; __res_randomid; res_sendsigned; @@ -323,11 +349,11 @@ SUNWprivate_2.1 { __sym_ntos; sym_ston; __sym_ston; - tree_add; - tree_init; - tree_mung; - tree_srch; - tree_trav; + __tree_add; + __tree_init; + __tree_mung; + __tree_srch; + __tree_trav; local: *; }; diff --git a/usr/src/lib/libresolv2/common/nameser/ns_date.c b/usr/src/lib/libresolv2/common/nameser/ns_date.c index b089063c71..292375af63 100644 --- a/usr/src/lib/libresolv2/common/nameser/ns_date.c +++ b/usr/src/lib/libresolv2/common/nameser/ns_date.c @@ -1,31 +1,24 @@ /* - * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef lint -static const char rcsid[] = "$Id: ns_date.c,v 1.3 2001/05/29 05:49:34 marka Exp $"; +static const char rcsid[] = "$Id: ns_date.c,v 1.6 2005/04/27 04:56:39 sra Exp $"; #endif -#pragma ident "%Z%%M% %I% %E% SMI" - /* Import. */ #include "port_before.h" @@ -52,9 +45,11 @@ static int datepart(const char *, int, int, int, int *); /* Public. */ -/* Convert a date in ASCII into the number of seconds since - 1 January 1970 (GMT assumed). Format is yyyymmddhhmmss, all - digits required, no spaces allowed. */ +/*% + * Convert a date in ASCII into the number of seconds since + * 1 January 1970 (GMT assumed). Format is yyyymmddhhmmss, all + * digits required, no spaces allowed. + */ u_int32_t ns_datetosecs(const char *cp, int *errp) { @@ -64,7 +59,7 @@ ns_datetosecs(const char *cp, int *errp) { static const int days_per_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - if (strlen(cp) != 14) { + if (strlen(cp) != 14U) { *errp = 1; return (0); } @@ -77,7 +72,7 @@ ns_datetosecs(const char *cp, int *errp) { time.tm_hour = datepart(cp + 8, 2, 00, 23, errp); time.tm_min = datepart(cp + 10, 2, 00, 59, errp); time.tm_sec = datepart(cp + 12, 2, 00, 59, errp); - if (*errp) /* Any parse errors? */ + if (*errp) /*%< Any parse errors? */ return (0); /* @@ -88,32 +83,29 @@ ns_datetosecs(const char *cp, int *errp) { #define SECS_PER_DAY ((u_int32_t)24*60*60) #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) - result = time.tm_sec; /* Seconds */ - result += time.tm_min * 60; /* Minutes */ - result += time.tm_hour * (60*60); /* Hours */ - result += (time.tm_mday - 1) * SECS_PER_DAY; /* Days */ - + result = time.tm_sec; /*%< Seconds */ + result += time.tm_min * 60; /*%< Minutes */ + result += time.tm_hour * (60*60); /*%< Hours */ + result += (time.tm_mday - 1) * SECS_PER_DAY; /*%< Days */ /* Months are trickier. Look without leaping, then leap */ mdays = 0; for (i = 0; i < time.tm_mon; i++) mdays += days_per_month[i]; - result += mdays * SECS_PER_DAY; /* Months */ + result += mdays * SECS_PER_DAY; /*%< Months */ if (time.tm_mon > 1 && isleap(1900+time.tm_year)) - result += SECS_PER_DAY; /* Add leapday for this year */ - + result += SECS_PER_DAY; /*%< Add leapday for this year */ /* First figure years without leapdays, then add them in. */ /* The loop is slow, FIXME, but simple and accurate. */ - result += (time.tm_year - 70) * (SECS_PER_DAY*365); /* Years */ + result += (time.tm_year - 70) * (SECS_PER_DAY*365); /*%< Years */ for (i = 70; i < time.tm_year; i++) if (isleap(1900+i)) - result += SECS_PER_DAY; /* Add leapday for prev year */ - + result += SECS_PER_DAY; /*%< Add leapday for prev year */ return (result); } /* Private. */ -/* +/*% * Parse part of a date. Set error flag if any error. * Don't reset the flag if there is no error. */ @@ -133,3 +125,5 @@ datepart(const char *buf, int size, int min, int max, int *errp) { *errp = 1; return (result); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/nameser/ns_name.c b/usr/src/lib/libresolv2/common/nameser/ns_name.c index fbe2c5ccc7..0c1f93c066 100644 --- a/usr/src/lib/libresolv2/common/nameser/ns_name.c +++ b/usr/src/lib/libresolv2/common/nameser/ns_name.c @@ -1,29 +1,22 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #ifndef lint -static const char rcsid[] = "$Id: ns_name.c,v 8.20 2003/04/03 06:00:07 marka Exp $"; +static const char rcsid[] = "$Id: ns_name.c,v 1.11 2009/01/23 19:59:16 each Exp $"; #endif #include "port_before.h" @@ -48,7 +41,7 @@ static const char rcsid[] = "$Id: ns_name.c,v 8.20 2003/04/03 06:00:07 marka Exp # define SPRINTF(x) ((size_t)sprintf x) #endif -#define NS_TYPE_ELT 0x40 /* EDNS0 extended label type */ +#define NS_TYPE_ELT 0x40 /*%< EDNS0 extended label type */ #define DNS_LABELTYPE_BITSTRING 0x41 /* Data. */ @@ -82,20 +75,23 @@ static int dn_find(const u_char *, const u_char *, const u_char * const *, const u_char * const *); static int encode_bitsring(const char **, const char *, - char **, char **, const char *); + unsigned char **, unsigned char **, + unsigned const char *); static int labellen(const u_char *); -static int decode_bitstring(const char **, char *, const char *); +static int decode_bitstring(const unsigned char **, + char *, const char *); /* Public. */ -/* - * ns_name_ntop(src, dst, dstsiz) +/*% * Convert an encoded domain name to printable ascii as per RFC1035. + * return: - * Number of bytes written to buffer, or -1 (with errno set) + *\li Number of bytes written to buffer, or -1 (with errno set) + * * notes: - * The root is returned as "." - * All other domains are returned in non absolute form + *\li The root is returned as "." + *\li All other domains are returned in non absolute form */ int ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) @@ -124,8 +120,8 @@ ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) *dn++ = '.'; } if ((l = labellen(cp - 1)) < 0) { - errno = EMSGSIZE; /* XXX */ - return(-1); + errno = EMSGSIZE; /*%< XXX */ + return (-1); } if (dn + l >= eom) { errno = EMSGSIZE; @@ -137,12 +133,12 @@ ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) if (n != DNS_LABELTYPE_BITSTRING) { /* XXX: labellen should reject this case */ errno = EINVAL; - return(-1); + return (-1); } - if ((m = decode_bitstring((const char **)&cp, dn, eom)) < 0) + if ((m = decode_bitstring(&cp, dn, eom)) < 0) { errno = EMSGSIZE; - return(-1); + return (-1); } dn += m; continue; @@ -189,20 +185,37 @@ ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) return (dn - dst); } +/*% + * Convert a ascii string into an encoded domain name as per RFC1035. + * + * return: + * + *\li -1 if it fails + *\li 1 if string was fully qualified + *\li 0 is string was not fully qualified + * + * notes: + *\li Enforces label and domain length limits. + */ +int +ns_name_pton(const char *src, u_char *dst, size_t dstsiz) { + return (ns_name_pton2(src, dst, dstsiz, NULL)); +} + /* - * ns_name_pton(src, dst, dstsiz) + * ns_name_pton2(src, dst, dstsiz, *dstlen) * Convert a ascii string into an encoded domain name as per RFC1035. * return: * -1 if it fails * 1 if string was fully qualified * 0 is string was not fully qualified + * side effects: + * fills in *dstlen (if non-NULL) * notes: * Enforces label and domain length limits. */ - int -ns_name_pton(const char *src, u_char *dst, size_t dstsiz) -{ +ns_name_pton2(const char *src, u_char *dst, size_t dstsiz, size_t *dstlen) { u_char *label, *bp, *eom; int c, n, escaped, e = 0; char *cp; @@ -214,19 +227,16 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) while ((c = *src++) != 0) { if (escaped) { - if (c == '[') { /* start a bit string label */ + if (c == '[') { /*%< start a bit string label */ if ((cp = strchr(src, ']')) == NULL) { - errno = EINVAL; /* ??? */ - return(-1); + errno = EINVAL; /*%< ??? */ + return (-1); } - if ((e = encode_bitsring(&src, - cp + 2, - (char **)&label, - (char **)&bp, - (const char *)eom)) + if ((e = encode_bitsring(&src, cp + 2, + &label, &bp, eom)) != 0) { errno = e; - return(-1); + return (-1); } escaped = 0; label = bp++; @@ -234,7 +244,7 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) goto done; else if (c != '.') { errno = EINVAL; - return(-1); + return (-1); } continue; } @@ -264,7 +274,7 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) continue; } else if (c == '.') { c = (bp - label - 1); - if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */ + if ((c & NS_CMPRSFLGS) != 0) { /*%< Label too big. */ errno = EMSGSIZE; return (-1); } @@ -286,6 +296,8 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) errno = EMSGSIZE; return (-1); } + if (dstlen != NULL) + *dstlen = (bp - dst); return (1); } if (c == 0 || *src == '.') { @@ -302,7 +314,7 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) *bp++ = (u_char)c; } c = (bp - label - 1); - if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */ + if ((c & NS_CMPRSFLGS) != 0) { /*%< Label too big. */ errno = EMSGSIZE; return (-1); } @@ -319,20 +331,23 @@ ns_name_pton(const char *src, u_char *dst, size_t dstsiz) } *bp++ = 0; } - if ((bp - dst) > MAXCDNAME) { /* src too big */ + if ((bp - dst) > MAXCDNAME) { /*%< src too big */ errno = EMSGSIZE; return (-1); } + if (dstlen != NULL) + *dstlen = (bp - dst); return (0); } -/* - * ns_name_ntol(src, dst, dstsiz) +/*% * Convert a network strings labels into all lowercase. + * * return: - * Number of bytes written to buffer, or -1 (with errno set) + *\li Number of bytes written to buffer, or -1 (with errno set) + * * notes: - * Enforces label and domain length limits. + *\li Enforces label and domain length limits. */ int @@ -369,7 +384,7 @@ ns_name_ntol(const u_char *src, u_char *dst, size_t dstsiz) } for ((void)NULL; l > 0; l--) { c = *cp++; - if (isupper(c)) + if (isascii(c) && isupper(c)) *dn++ = tolower(c); else *dn++ = c; @@ -379,16 +394,31 @@ ns_name_ntol(const u_char *src, u_char *dst, size_t dstsiz) return (dn - dst); } -/* - * ns_name_unpack(msg, eom, src, dst, dstsiz) +/*% * Unpack a domain name from a message, source may be compressed. + * * return: - * -1 if it fails, or consumed octets if it succeeds. + *\li -1 if it fails, or consumed octets if it succeeds. */ int ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src, u_char *dst, size_t dstsiz) { + return (ns_name_unpack2(msg, eom, src, dst, dstsiz, NULL)); +} + +/* + * ns_name_unpack2(msg, eom, src, dst, dstsiz, *dstlen) + * Unpack a domain name from a message, source may be compressed. + * return: + * -1 if it fails, or consumed octets if it succeeds. + * side effect: + * fills in *dstlen (if non-NULL). + */ +int +ns_name_unpack2(const u_char *msg, const u_char *eom, const u_char *src, + u_char *dst, size_t dstsiz, size_t *dstlen) +{ const u_char *srcp, *dstlim; u_char *dstp; int n, len, checked, l; @@ -411,7 +441,7 @@ ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src, /* Limit checks. */ if ((l = labellen(srcp - 1)) < 0) { errno = EMSGSIZE; - return(-1); + return (-1); } if (dstp + l + 1 >= dstlim || srcp + l >= eom) { errno = EMSGSIZE; @@ -432,7 +462,7 @@ ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src, if (len < 0) len = srcp - src + 1; srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff)); - if (srcp < msg || srcp >= eom) { /* Out of range. */ + if (srcp < msg || srcp >= eom) { /*%< Out of range. */ errno = EMSGSIZE; return (-1); } @@ -450,28 +480,32 @@ ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src, default: errno = EMSGSIZE; - return (-1); /* flag error */ + return (-1); /*%< flag error */ } } - *dstp = '\0'; + *dstp++ = 0; + if (dstlen != NULL) + *dstlen = dstp - dst; if (len < 0) len = srcp - src; return (len); } -/* - * ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr) +/*% * Pack domain name 'domain' into 'comp_dn'. + * * return: - * Size of the compressed name, or -1. + *\li Size of the compressed name, or -1. + * * notes: - * 'dnptrs' is an array of pointers to previous compressed names. - * dnptrs[0] is a pointer to the beginning of the message. The array + *\li 'dnptrs' is an array of pointers to previous compressed names. + *\li dnptrs[0] is a pointer to the beginning of the message. The array * ends with NULL. - * 'lastdnptr' is a pointer to the end of the array pointed to + *\li 'lastdnptr' is a pointer to the end of the array pointed to * by 'dnptrs'. + * * Side effects: - * The list of pointers in dnptrs is updated for labels inserted into + *\li The list of pointers in dnptrs is updated for labels inserted into * the message as we compress the name. If 'dnptr' is NULL, we don't * try to compress names. If 'lastdnptr' is NULL, we don't update the * list. @@ -493,7 +527,7 @@ ns_name_pack(const u_char *src, u_char *dst, int dstsiz, if ((msg = *dnptrs++) != NULL) { for (cpp = dnptrs; *cpp != NULL; cpp++) (void)NULL; - lpp = cpp; /* end of list to search */ + lpp = cpp; /*%< end of list to search */ } } else msg = NULL; @@ -510,7 +544,7 @@ ns_name_pack(const u_char *src, u_char *dst, int dstsiz, } if ((l0 = labellen(srcp)) < 0) { errno = EINVAL; - return(-1); + return (-1); } l += l0 + 1; if (l > MAXCDNAME) { @@ -568,13 +602,14 @@ cleanup: return (dstp - dst); } -/* - * ns_name_uncompress(msg, eom, src, dst, dstsiz) +/*% * Expand compressed domain name to presentation format. + * * return: - * Number of bytes read out of `src', or -1 (with errno set). + *\li Number of bytes read out of `src', or -1 (with errno set). + * * note: - * Root domain returns as "." not "". + *\li Root domain returns as "." not "". */ int ns_name_uncompress(const u_char *msg, const u_char *eom, const u_char *src, @@ -590,18 +625,19 @@ ns_name_uncompress(const u_char *msg, const u_char *eom, const u_char *src, return (n); } -/* - * ns_name_compress(src, dst, dstsiz, dnptrs, lastdnptr) +/*% * Compress a domain name into wire format, using compression pointers. + * * return: - * Number of bytes consumed in `dst' or -1 (with errno set). + *\li Number of bytes consumed in `dst' or -1 (with errno set). + * * notes: - * 'dnptrs' is an array of pointers to previous compressed names. - * dnptrs[0] is a pointer to the beginning of the message. - * The list ends with NULL. 'lastdnptr' is a pointer to the end of the + *\li 'dnptrs' is an array of pointers to previous compressed names. + *\li dnptrs[0] is a pointer to the beginning of the message. + *\li The list ends with NULL. 'lastdnptr' is a pointer to the end of the * array pointed to by 'dnptrs'. Side effect is to update the list of * pointers for labels inserted into the message as we compress the name. - * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr' + *\li If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr' * is NULL, we don't update the list. */ int @@ -615,7 +651,7 @@ ns_name_compress(const char *src, u_char *dst, size_t dstsiz, return (ns_name_pack(tmp, dst, dstsiz, dnptrs, lastdnptr)); } -/* +/*% * Reset dnptrs so that there are no active references to pointers at or * after src. */ @@ -632,11 +668,11 @@ ns_name_rollback(const u_char *src, const u_char **dnptrs, } } -/* - * ns_name_skip(ptrptr, eom) +/*% * Advance *ptrptr to skip over the compressed name it points at. + * * return: - * 0 on success, -1 (with errno set) on failure. + *\li 0 on success, -1 (with errno set) on failure. */ int ns_name_skip(const u_char **ptrptr, const u_char *eom) @@ -649,20 +685,20 @@ ns_name_skip(const u_char **ptrptr, const u_char *eom) while (cp < eom && (n = *cp++) != 0) { /* Check for indirection. */ switch (n & NS_CMPRSFLGS) { - case 0: /* normal case, n == len */ + case 0: /*%< normal case, n == len */ cp += n; continue; - case NS_TYPE_ELT: /* EDNS0 extended label */ + case NS_TYPE_ELT: /*%< EDNS0 extended label */ if ((l = labellen(cp - 1)) < 0) { - errno = EMSGSIZE; /* XXX */ - return(-1); + errno = EMSGSIZE; /*%< XXX */ + return (-1); } cp += l; continue; - case NS_CMPRSFLGS: /* indirection */ + case NS_CMPRSFLGS: /*%< indirection */ cp++; break; - default: /* illegal type */ + default: /*%< illegal type */ errno = EMSGSIZE; return (-1); } @@ -676,46 +712,190 @@ ns_name_skip(const u_char **ptrptr, const u_char *eom) return (0); } +/* Find the number of octets an nname takes up, including the root label. + * (This is basically ns_name_skip() without compression-pointer support.) + * ((NOTE: can only return zero if passed-in namesiz argument is zero.)) + */ +ssize_t +ns_name_length(ns_nname_ct nname, size_t namesiz) { + ns_nname_ct orig = nname; + u_int n; + + while (namesiz-- > 0 && (n = *nname++) != 0) { + if ((n & NS_CMPRSFLGS) != 0) { + errno = EISDIR; + return (-1); + } + if (n > namesiz) { + errno = EMSGSIZE; + return (-1); + } + nname += n; + namesiz -= n; + } + return (nname - orig); +} + +/* Compare two nname's for equality. Return -1 on error (setting errno). + */ +int +ns_name_eq(ns_nname_ct a, size_t as, ns_nname_ct b, size_t bs) { + ns_nname_ct ae = a + as, be = b + bs; + int ac, bc; + + while (ac = *a, bc = *b, ac != 0 && bc != 0) { + if ((ac & NS_CMPRSFLGS) != 0 || (bc & NS_CMPRSFLGS) != 0) { + errno = EISDIR; + return (-1); + } + if (a + ac >= ae || b + bc >= be) { + errno = EMSGSIZE; + return (-1); + } + if (ac != bc || strncasecmp((const char *) ++a, + (const char *) ++b, ac) != 0) + return (0); + a += ac, b += bc; + } + return (ac == 0 && bc == 0); +} + +/* Is domain "A" owned by (at or below) domain "B"? + */ +int +ns_name_owned(ns_namemap_ct a, int an, ns_namemap_ct b, int bn) { + /* If A is shorter, it cannot be owned by B. */ + if (an < bn) + return (0); + + /* If they are unequal before the length of the shorter, A cannot... */ + while (bn > 0) { + if (a->len != b->len || + strncasecmp((const char *) a->base, + (const char *) b->base, a->len) != 0) + return (0); + a++, an--; + b++, bn--; + } + + /* A might be longer or not, but either way, B owns it. */ + return (1); +} + +/* Build an array of <base,len> tuples from an nname, top-down order. + * Return the number of tuples (labels) thus discovered. + */ +int +ns_name_map(ns_nname_ct nname, size_t namelen, ns_namemap_t map, int mapsize) { + u_int n; + int l; + + n = *nname++; + namelen--; + + /* Root zone? */ + if (n == 0) { + /* Extra data follows name? */ + if (namelen > 0) { + errno = EMSGSIZE; + return (-1); + } + return (0); + } + + /* Compression pointer? */ + if ((n & NS_CMPRSFLGS) != 0) { + errno = EISDIR; + return (-1); + } + + /* Label too long? */ + if (n > namelen) { + errno = EMSGSIZE; + return (-1); + } + + /* Recurse to get rest of name done first. */ + l = ns_name_map(nname + n, namelen - n, map, mapsize); + if (l < 0) + return (-1); + + /* Too many labels? */ + if (l >= mapsize) { + errno = ENAMETOOLONG; + return (-1); + } + + /* We're on our way back up-stack, store current map data. */ + map[l].base = nname; + map[l].len = n; + return (l + 1); +} + +/* Count the labels in a domain name. Root counts, so COM. has two. This + * is to make the result comparable to the result of ns_name_map(). + */ +int +ns_name_labels(ns_nname_ct nname, size_t namesiz) { + int ret = 0; + u_int n; + + while (namesiz-- > 0 && (n = *nname++) != 0) { + if ((n & NS_CMPRSFLGS) != 0) { + errno = EISDIR; + return (-1); + } + if (n > namesiz) { + errno = EMSGSIZE; + return (-1); + } + nname += n; + namesiz -= n; + ret++; + } + return (ret + 1); +} + /* Private. */ -/* - * special(ch) +/*% * Thinking in noninternationalized USASCII (per the DNS spec), * is this characted special ("in need of quoting") ? + * * return: - * boolean. + *\li boolean. */ static int special(int ch) { switch (ch) { - case 0x22: /* '"' */ - case 0x2E: /* '.' */ - case 0x3B: /* ';' */ - case 0x5C: /* '\\' */ - case 0x28: /* '(' */ - case 0x29: /* ')' */ + case 0x22: /*%< '"' */ + case 0x2E: /*%< '.' */ + case 0x3B: /*%< ';' */ + case 0x5C: /*%< '\\' */ + case 0x28: /*%< '(' */ + case 0x29: /*%< ')' */ /* Special modifiers in zone files. */ - case 0x40: /* '@' */ - case 0x24: /* '$' */ + case 0x40: /*%< '@' */ + case 0x24: /*%< '$' */ return (1); default: return (0); } } -/* - * printable(ch) +/*% * Thinking in noninternationalized USASCII (per the DNS spec), * is this character visible and not a space when printed ? + * * return: - * boolean. + *\li boolean. */ static int printable(int ch) { return (ch > 0x20 && ch < 0x7f); } -/* +/*% * Thinking in noninternationalized USASCII (per the DNS spec), * convert this character to lower case if it's upper case. */ @@ -726,14 +906,15 @@ mklower(int ch) { return (ch); } -/* - * dn_find(domain, msg, dnptrs, lastdnptr) +/*% * Search for the counted-label name in an array of compressed names. + * * return: - * offset from msg if found, or -1. + *\li offset from msg if found, or -1. + * * notes: - * dnptrs is the pointer to the first name on the list, - * not the pointer to the start of the message. + *\li dnptrs is the pointer to the first name on the list, + *\li not the pointer to the start of the message. */ static int dn_find(const u_char *domain, const u_char *msg, @@ -761,9 +942,8 @@ dn_find(const u_char *domain, const u_char *msg, * check for indirection */ switch (n & NS_CMPRSFLGS) { - case 0: /* normal case, n == len */ - n = labellen(cp - 1); /* XXX */ - + case 0: /*%< normal case, n == len */ + n = labellen(cp - 1); /*%< XXX */ if (n != *dn++) goto next; @@ -777,11 +957,11 @@ dn_find(const u_char *domain, const u_char *msg, if (*dn) continue; goto next; - case NS_CMPRSFLGS: /* indirection */ + case NS_CMPRSFLGS: /*%< indirection */ cp = msg + (((n & 0x3f) << 8) | *cp); break; - default: /* illegal type */ + default: /*%< illegal type */ errno = EMSGSIZE; return (-1); } @@ -795,9 +975,9 @@ dn_find(const u_char *domain, const u_char *msg, } static int -decode_bitstring(const char **cpp, char *dn, const char *eom) +decode_bitstring(const unsigned char **cpp, char *dn, const char *eom) { - const char *cp = *cpp; + const unsigned char *cp = *cpp; char *beg = dn, tc; int b, blen, plen, i; @@ -806,7 +986,7 @@ decode_bitstring(const char **cpp, char *dn, const char *eom) plen = (blen + 3) / 4; plen += sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1); if (dn + plen >= eom) - return(-1); + return (-1); cp++; i = SPRINTF((dn, "\\[x")); @@ -839,16 +1019,17 @@ decode_bitstring(const char **cpp, char *dn, const char *eom) dn += i; *cpp = cp; - return(dn - beg); + return (dn - beg); } static int -encode_bitsring(const char **bp, const char *end, char **labelp, - char ** dst, const char *eom) +encode_bitsring(const char **bp, const char *end, unsigned char **labelp, + unsigned char ** dst, unsigned const char *eom) { int afterslash = 0; const char *cp = *bp; - char *tp, c; + unsigned char *tp; + char c; const char *beg_blen; char *end_blen = NULL; int value = 0, count = 0, tbcount = 0, blen = 0; @@ -857,27 +1038,27 @@ encode_bitsring(const char **bp, const char *end, char **labelp, /* a bitstring must contain at least 2 characters */ if (end - cp < 2) - return(EINVAL); + return (EINVAL); /* XXX: currently, only hex strings are supported */ if (*cp++ != 'x') - return(EINVAL); - if (!isxdigit((*cp) & 0xff)) /* reject '\[x/BLEN]' */ - return(EINVAL); + return (EINVAL); + if (!isxdigit((*cp) & 0xff)) /*%< reject '\[x/BLEN]' */ + return (EINVAL); for (tp = *dst + 1; cp < end && tp < eom; cp++) { switch((c = *cp)) { - case ']': /* end of the bitstring */ + case ']': /*%< end of the bitstring */ if (afterslash) { if (beg_blen == NULL) - return(EINVAL); + return (EINVAL); blen = (int)strtol(beg_blen, &end_blen, 10); if (*end_blen != ']') - return(EINVAL); + return (EINVAL); } if (count) *tp++ = ((value << 4) & 0xff); - cp++; /* skip ']' */ + cp++; /*%< skip ']' */ goto done; case '/': afterslash = 1; @@ -885,24 +1066,24 @@ encode_bitsring(const char **bp, const char *end, char **labelp, default: if (afterslash) { if (!isdigit(c&0xff)) - return(EINVAL); + return (EINVAL); if (beg_blen == NULL) { if (c == '0') { /* blen never begings with 0 */ - return(EINVAL); + return (EINVAL); } beg_blen = cp; } } else { if (!isxdigit(c&0xff)) - return(EINVAL); + return (EINVAL); value <<= 4; value += digitvalue[(int)c]; count += 4; tbcount += 4; if (tbcount > 256) - return(EINVAL); + return (EINVAL); if (count == 8) { *tp++ = value; count = 0; @@ -913,7 +1094,7 @@ encode_bitsring(const char **bp, const char *end, char **labelp, } done: if (cp >= end || tp >= eom) - return(EMSGSIZE); + return (EMSGSIZE); /* * bit length validation: @@ -921,16 +1102,16 @@ encode_bitsring(const char **bp, const char *end, char **labelp, * MUST be just sufficient to contain the number of bits specified * by the <length>. If there are insignificant bits in a final * hexadecimal or octal digit, they MUST be zero. - * RFC 2673, Section 3.2. + * RFC2673, Section 3.2. */ if (blen > 0) { int traillen; if (((blen + 3) & ~3) != tbcount) - return(EINVAL); - traillen = tbcount - blen; /* between 0 and 3 */ + return (EINVAL); + traillen = tbcount - blen; /*%< between 0 and 3 */ if (((value << (8 - traillen)) & 0xff) != 0) - return(EINVAL); + return (EINVAL); } else blen = tbcount; @@ -944,7 +1125,7 @@ encode_bitsring(const char **bp, const char *end, char **labelp, *bp = cp; *dst = tp; - return(0); + return (0); } static int @@ -955,16 +1136,18 @@ labellen(const u_char *lp) if ((l & NS_CMPRSFLGS) == NS_CMPRSFLGS) { /* should be avoided by the caller */ - return(-1); + return (-1); } if ((l & NS_CMPRSFLGS) == NS_TYPE_ELT) { if (l == DNS_LABELTYPE_BITSTRING) { if ((bitlen = *(lp + 1)) == 0) bitlen = 256; - return((bitlen + 7 ) / 8 + 1); + return ((bitlen + 7 ) / 8 + 1); } - return(-1); /* unknwon ELT */ + return (-1); /*%< unknwon ELT */ } - return(l); + return (l); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/nameser/ns_netint.c b/usr/src/lib/libresolv2/common/nameser/ns_netint.c index e753ce9809..559c9d5bd5 100644 --- a/usr/src/lib/libresolv2/common/nameser/ns_netint.c +++ b/usr/src/lib/libresolv2/common/nameser/ns_netint.c @@ -1,29 +1,22 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #ifndef lint -static const char rcsid[] = "$Id: ns_netint.c,v 8.4 1999/10/13 16:39:35 vixie Exp $"; +static const char rcsid[] = "$Id: ns_netint.c,v 1.3 2005/04/27 04:56:40 sra Exp $"; #endif /* Import. */ @@ -61,3 +54,5 @@ void ns_put32(u_long src, u_char *dst) { NS_PUT32(src, dst); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/nameser/ns_newmsg.c b/usr/src/lib/libresolv2/common/nameser/ns_newmsg.c new file mode 100644 index 0000000000..c18dd060e1 --- /dev/null +++ b/usr/src/lib/libresolv2/common/nameser/ns_newmsg.c @@ -0,0 +1,273 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +/* + * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC") + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef lint +static const char rcsid[] = "$Id: ns_newmsg.c,v 1.3 2009/02/26 10:48:57 marka Exp $"; +#endif + +#include <port_before.h> + +#include <arpa/nameser.h> + +#include <assert.h> +#include <errno.h> +#include <string.h> + +#include <port_after.h> + +static int rdcpy(ns_newmsg *, ns_type, const u_char *, size_t); + +/* Initialize a "newmsg" object to empty. + */ +int +ns_newmsg_init(u_char *buffer, size_t bufsiz, ns_newmsg *handle) { + ns_msg *msg = &handle->msg; + + memset(handle, 0, sizeof *handle); + msg->_msg = buffer; + msg->_eom = buffer + bufsiz; + msg->_sect = ns_s_qd; + msg->_rrnum = 0; + msg->_msg_ptr = buffer + NS_HFIXEDSZ; + handle->dnptrs[0] = msg->_msg; + handle->dnptrs[1] = NULL; + handle->lastdnptr = &handle->dnptrs[sizeof handle->dnptrs / + sizeof handle->dnptrs[0] - 1]; + return (0); +} + +/* Initialize a "newmsg" object by copying an existing parsed message. + */ +int +ns_newmsg_copy(ns_newmsg *handle, ns_msg *msg) { + ns_flag flag; + ns_sect sect; + + ns_newmsg_id(handle, ns_msg_id(*msg)); + for (flag = ns_f_qr; flag < ns_f_max; flag++) + ns_newmsg_flag(handle, flag, ns_msg_getflag(*msg, flag)); + for (sect = ns_s_qd; sect < ns_s_max; sect++) { + int i, count; + + count = ns_msg_count(*msg, sect); + for (i = 0; i < count; i++) { + ns_rr2 rr; + int x; + + if (ns_parserr2(msg, sect, i, &rr) < 0) + return (-1); + if (sect == ns_s_qd) + x = ns_newmsg_q(handle, + ns_rr_nname(rr), + ns_rr_type(rr), + ns_rr_class(rr)); + else + x = ns_newmsg_rr(handle, sect, + ns_rr_nname(rr), + ns_rr_type(rr), + ns_rr_class(rr), + ns_rr_ttl(rr), + ns_rr_rdlen(rr), + ns_rr_rdata(rr)); + if (x < 0) + return (-1); + } + } + return (0); +} + +/* Set the message-ID in a "newmsg" object. + */ +void +ns_newmsg_id(ns_newmsg *handle, u_int16_t id) { + ns_msg *msg = &handle->msg; + + msg->_id = id; +} + +/* Set a flag (including rcode or opcode) in a "newmsg" object. + */ +void +ns_newmsg_flag(ns_newmsg *handle, ns_flag flag, u_int value) { + extern struct _ns_flagdata _ns_flagdata[16]; + struct _ns_flagdata *fd = &_ns_flagdata[flag]; + ns_msg *msg = &handle->msg; + + assert(flag < ns_f_max); + msg->_flags &= (~fd->mask); + msg->_flags |= (value << fd->shift); +} + +/* Add a question (or zone, if it's an update) to a "newmsg" object. + */ +int +ns_newmsg_q(ns_newmsg *handle, ns_nname_ct qname, + ns_type qtype, ns_class qclass) +{ + ns_msg *msg = &handle->msg; + u_char *t; + int n; + + if (msg->_sect != ns_s_qd) { + errno = ENODEV; + return (-1); + } + t = (u_char *) (unsigned long) msg->_msg_ptr; + if (msg->_rrnum == 0) + msg->_sections[ns_s_qd] = t; + n = ns_name_pack(qname, t, msg->_eom - t, + handle->dnptrs, handle->lastdnptr); + if (n < 0) + return (-1); + t += n; + if (t + QFIXEDSZ >= msg->_eom) { + errno = EMSGSIZE; + return (-1); + } + NS_PUT16(qtype, t); + NS_PUT16(qclass, t); + msg->_msg_ptr = t; + msg->_counts[ns_s_qd] = ++msg->_rrnum; + return (0); +} + +/* Add an RR to a "newmsg" object. + */ +int +ns_newmsg_rr(ns_newmsg *handle, ns_sect sect, + ns_nname_ct name, ns_type type, + ns_class rr_class, u_int32_t ttl, + u_int16_t rdlen, const u_char *rdata) +{ + ns_msg *msg = &handle->msg; + u_char *t; + int n; + + if (sect < msg->_sect) { + errno = ENODEV; + return (-1); + } + t = (u_char *) (unsigned long) msg->_msg_ptr; + if (sect > msg->_sect) { + msg->_sect = sect; + msg->_sections[sect] = t; + msg->_rrnum = 0; + } + n = ns_name_pack(name, t, msg->_eom - t, + handle->dnptrs, handle->lastdnptr); + if (n < 0) + return (-1); + t += n; + if (t + RRFIXEDSZ + rdlen >= msg->_eom) { + errno = EMSGSIZE; + return (-1); + } + NS_PUT16(type, t); + NS_PUT16(rr_class, t); + NS_PUT32(ttl, t); + msg->_msg_ptr = t; + if (rdcpy(handle, type, rdata, rdlen) < 0) + return (-1); + msg->_counts[sect] = ++msg->_rrnum; + return (0); +} + +/* Complete a "newmsg" object and return its size for use in write(). + * (Note: the "newmsg" object is also made ready for ns_parserr() etc.) + */ +size_t +ns_newmsg_done(ns_newmsg *handle) { + ns_msg *msg = &handle->msg; + ns_sect sect; + u_char *t; + + t = (u_char *) (unsigned long) msg->_msg; + NS_PUT16(msg->_id, t); + NS_PUT16(msg->_flags, t); + for (sect = 0; sect < ns_s_max; sect++) + NS_PUT16(msg->_counts[sect], t); + msg->_eom = msg->_msg_ptr; + msg->_sect = ns_s_max; + msg->_rrnum = -1; + msg->_msg_ptr = NULL; + return (msg->_eom - msg->_msg); +} + +/* Private. */ + +/* Copy an RDATA, using compression pointers where RFC1035 permits. + */ +static int +rdcpy(ns_newmsg *handle, ns_type type, const u_char *rdata, size_t rdlen) { + ns_msg *msg = &handle->msg; + u_char *p = (u_char *) (unsigned long) msg->_msg_ptr; + u_char *t = p + NS_INT16SZ; + u_char *s = t; + int n; + + switch (type) { + case ns_t_soa: + /* MNAME. */ + n = ns_name_pack(rdata, t, msg->_eom - t, + handle->dnptrs, handle->lastdnptr); + if (n < 0) + return (-1); + t += n; + if (ns_name_skip(&rdata, msg->_eom) < 0) + return (-1); + + /* ANAME. */ + n = ns_name_pack(rdata, t, msg->_eom - t, + handle->dnptrs, handle->lastdnptr); + if (n < 0) + return (-1); + t += n; + if (ns_name_skip(&rdata, msg->_eom) < 0) + return (-1); + + /* Serial, Refresh, Retry, Expiry, and Minimum. */ + if ((msg->_eom - t) < (NS_INT32SZ * 5)) { + errno = EMSGSIZE; + return (-1); + } + memcpy(t, rdata, NS_INT32SZ * 5); + t += (NS_INT32SZ * 5); + break; + case ns_t_ptr: + case ns_t_cname: + case ns_t_ns: + /* PTRDNAME, CNAME, or NSDNAME. */ + n = ns_name_pack(rdata, t, msg->_eom - t, + handle->dnptrs, handle->lastdnptr); + if (n < 0) + return (-1); + t += n; + break; + default: + memcpy(t, rdata, rdlen); + t += rdlen; + } + NS_PUT16(t - s, p); + msg->_msg_ptr = t; + return (0); +} + diff --git a/usr/src/lib/libresolv2/common/nameser/ns_parse.c b/usr/src/lib/libresolv2/common/nameser/ns_parse.c index 65476deeb2..1e92d3c9ac 100644 --- a/usr/src/lib/libresolv2/common/nameser/ns_parse.c +++ b/usr/src/lib/libresolv2/common/nameser/ns_parse.c @@ -1,29 +1,22 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #ifndef lint -static const char rcsid[] = "$Id: ns_parse.c,v 8.18 2003/04/03 06:10:10 marka Exp $"; +static const char rcsid[] = "$Id: ns_parse.c,v 1.10 2009/01/23 19:59:16 each Exp $"; #endif /* Import. */ @@ -47,32 +40,36 @@ static void setsection(ns_msg *msg, ns_sect sect); /* Macros. */ -#ifdef ORIGINAL_ISC_CODE +#if !defined(SOLARIS2) || defined(__COVERITY__) #define RETERR(err) do { errno = (err); return (-1); } while (0) #else -#define RETERR(err) { errno = (err); return (-1); } +#define RETERR(err) \ + do { errno = (err); if (errno == errno) return (-1); } while (0) #endif +#define PARSE_FMT_PRESO 0 /* Parse using presentation-format names */ +#define PARSE_FMT_WIRE 1 /* Parse using network-format names */ + /* Public. */ /* These need to be in the same order as the nres.h:ns_flag enum. */ struct _ns_flagdata _ns_flagdata[16] = { - { 0x8000, 15 }, /* qr. */ - { 0x7800, 11 }, /* opcode. */ - { 0x0400, 10 }, /* aa. */ - { 0x0200, 9 }, /* tc. */ - { 0x0100, 8 }, /* rd. */ - { 0x0080, 7 }, /* ra. */ - { 0x0040, 6 }, /* z. */ - { 0x0020, 5 }, /* ad. */ - { 0x0010, 4 }, /* cd. */ - { 0x000f, 0 }, /* rcode. */ - { 0x0000, 0 }, /* expansion (1/6). */ - { 0x0000, 0 }, /* expansion (2/6). */ - { 0x0000, 0 }, /* expansion (3/6). */ - { 0x0000, 0 }, /* expansion (4/6). */ - { 0x0000, 0 }, /* expansion (5/6). */ - { 0x0000, 0 }, /* expansion (6/6). */ + { 0x8000, 15 }, /*%< qr. */ + { 0x7800, 11 }, /*%< opcode. */ + { 0x0400, 10 }, /*%< aa. */ + { 0x0200, 9 }, /*%< tc. */ + { 0x0100, 8 }, /*%< rd. */ + { 0x0080, 7 }, /*%< ra. */ + { 0x0040, 6 }, /*%< z. */ + { 0x0020, 5 }, /*%< ad. */ + { 0x0010, 4 }, /*%< cd. */ + { 0x000f, 0 }, /*%< rcode. */ + { 0x0000, 0 }, /*%< expansion (1/6). */ + { 0x0000, 0 }, /*%< expansion (2/6). */ + { 0x0000, 0 }, /*%< expansion (3/6). */ + { 0x0000, 0 }, /*%< expansion (4/6). */ + { 0x0000, 0 }, /*%< expansion (5/6). */ + { 0x0000, 0 }, /*%< expansion (6/6). */ }; int ns_msg_getflag(ns_msg handle, int flag) { @@ -108,7 +105,6 @@ ns_initparse(const u_char *msg, int msglen, ns_msg *handle) { const u_char *eom = msg + msglen; int i; - memset(handle, 0x5e, sizeof *handle); handle->_msg = msg; handle->_eom = eom; if (msg + NS_INT16SZ > eom) @@ -146,7 +142,8 @@ ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) { int tmp; /* Make section right. */ - if ((tmp = section) < 0 || section >= ns_s_max) + tmp = section; + if (tmp < 0 || section >= ns_s_max) RETERR(ENODEV); if (section != handle->_sect) setsection(handle, section); @@ -199,6 +196,68 @@ ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) { return (0); } +/* + * This is identical to the above but uses network-format (uncompressed) names. + */ +int +ns_parserr2(ns_msg *handle, ns_sect section, int rrnum, ns_rr2 *rr) { + int b; + int tmp; + + /* Make section right. */ + if ((tmp = section) < 0 || section >= ns_s_max) + RETERR(ENODEV); + if (section != handle->_sect) + setsection(handle, section); + + /* Make rrnum right. */ + if (rrnum == -1) + rrnum = handle->_rrnum; + if (rrnum < 0 || rrnum >= handle->_counts[(int)section]) + RETERR(ENODEV); + if (rrnum < handle->_rrnum) + setsection(handle, section); + if (rrnum > handle->_rrnum) { + b = ns_skiprr(handle->_msg_ptr, handle->_eom, section, + rrnum - handle->_rrnum); + + if (b < 0) + return (-1); + handle->_msg_ptr += b; + handle->_rrnum = rrnum; + } + + /* Do the parse. */ + b = ns_name_unpack2(handle->_msg, handle->_eom, handle->_msg_ptr, + rr->nname, NS_MAXNNAME, &rr->nnamel); + if (b < 0) + return (-1); + handle->_msg_ptr += b; + if (handle->_msg_ptr + NS_INT16SZ + NS_INT16SZ > handle->_eom) + RETERR(EMSGSIZE); + NS_GET16(rr->type, handle->_msg_ptr); + NS_GET16(rr->rr_class, handle->_msg_ptr); + if (section == ns_s_qd) { + rr->ttl = 0; + rr->rdlength = 0; + rr->rdata = NULL; + } else { + if (handle->_msg_ptr + NS_INT32SZ + NS_INT16SZ > handle->_eom) + RETERR(EMSGSIZE); + NS_GET32(rr->ttl, handle->_msg_ptr); + NS_GET16(rr->rdlength, handle->_msg_ptr); + if (handle->_msg_ptr + rr->rdlength > handle->_eom) + RETERR(EMSGSIZE); + rr->rdata = handle->_msg_ptr; + handle->_msg_ptr += rr->rdlength; + } + if (++handle->_rrnum > handle->_counts[(int)section]) + setsection(handle, (ns_sect)((int)section + 1)); + + /* All done. */ + return (0); +} + /* Private. */ static void @@ -212,3 +271,5 @@ setsection(ns_msg *msg, ns_sect sect) { msg->_msg_ptr = msg->_sections[(int)sect]; } } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/nameser/ns_print.c b/usr/src/lib/libresolv2/common/nameser/ns_print.c index ced16b0828..cde5d8e2d7 100644 --- a/usr/src/lib/libresolv2/common/nameser/ns_print.c +++ b/usr/src/lib/libresolv2/common/nameser/ns_print.c @@ -1,29 +1,22 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #ifndef lint -static const char rcsid[] = "$Id: ns_print.c,v 8.26 2003/02/24 23:56:35 vixie Exp $"; +static const char rcsid[] = "$Id: ns_print.c,v 1.12 2009/03/03 05:29:58 each Exp $"; #endif /* Import. */ @@ -66,13 +59,6 @@ static int addstr(const char *src, size_t len, static int addtab(size_t len, size_t target, int spaced, char **buf, size_t *buflen); -#ifdef ORIGINAL_ISC_CODE -#else -/* Proto. */ - -u_int16_t dst_s_dns_key_id(const u_char *, const int); -#endif - /* Macros. */ #define T(x) \ @@ -81,14 +67,16 @@ u_int16_t dst_s_dns_key_id(const u_char *, const int); return (-1); \ } while (0) +static const char base32hex[] = + "0123456789ABCDEFGHIJKLMNOPQRSTUV=0123456789abcdefghijklmnopqrstuv"; + /* Public. */ -/* - * int - * ns_sprintrr(handle, rr, name_ctx, origin, buf, buflen) +/*% * Convert an RR to presentation format. + * * return: - * Number of characters written to buf, or -1 (check errno). + *\li Number of characters written to buf, or -1 (check errno). */ int ns_sprintrr(const ns_msg *handle, const ns_rr *rr, @@ -104,13 +92,11 @@ ns_sprintrr(const ns_msg *handle, const ns_rr *rr, return (n); } -/* - * int - * ns_sprintrrf(msg, msglen, name, class, type, ttl, rdata, rdlen, - * name_ctx, origin, buf, buflen) +/*% * Convert the fields of an RR into presentation format. + * * return: - * Number of characters written to buf, or -1 (check errno). + *\li Number of characters written to buf, or -1 (check errno). */ int ns_sprintrrf(const u_char *msg, size_t msglen, @@ -159,8 +145,6 @@ ns_sprintrrf(const u_char *msg, size_t msglen, addlen(x, &buf, &buflen); len = SPRINTF((tmp, " %s %s", p_class(class), p_type(type))); T(addstr(tmp, len, &buf, &buflen)); - if (rdlen == 0) - return (buf - obuf); T(spaced = addtab(x + len, 16, spaced, &buf, &buflen)); /* @@ -168,7 +152,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, */ switch (type) { case ns_t_a: - if (rdlen != NS_INADDRSZ) + if (rdlen != (size_t)NS_INADDRSZ) goto formerr; (void) inet_ntop(AF_INET, rdata, buf, buflen); addlen(strlen(buf), &buf, &buflen); @@ -269,10 +253,11 @@ ns_sprintrrf(const u_char *msg, size_t msglen, case ns_t_mx: case ns_t_afsdb: - case ns_t_rt: { + case ns_t_rt: + case ns_t_kx: { u_int t; - if (rdlen < NS_INT16SZ) + if (rdlen < (size_t)NS_INT16SZ) goto formerr; /* Priority. */ @@ -290,7 +275,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, case ns_t_px: { u_int t; - if (rdlen < NS_INT16SZ) + if (rdlen < (size_t)NS_INT16SZ) goto formerr; /* Priority. */ @@ -317,6 +302,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, break; case ns_t_txt: + case ns_t_spf: while (rdata < edata) { T(len = charstr(rdata, edata, &buf, &buflen)); if (len == 0) @@ -336,7 +322,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, } case ns_t_aaaa: - if (rdlen != NS_IN6ADDRSZ) + if (rdlen != (size_t)NS_IN6ADDRSZ) goto formerr; (void) inet_ntop(AF_INET6, rdata, buf, buflen); addlen(strlen(buf), &buf, &buflen); @@ -355,7 +341,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, u_int order, preference; char t[50]; - if (rdlen < 2*NS_INT16SZ) + if (rdlen < 2U*NS_INT16SZ) goto formerr; /* Order, Precedence. */ @@ -396,7 +382,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, u_int priority, weight, port; char t[50]; - if (rdlen < NS_INT16SZ*3) + if (rdlen < 3U*NS_INT16SZ) goto formerr; /* Priority, Weight, Port. */ @@ -425,7 +411,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, case ns_t_wks: { int n, lcnt; - if (rdlen < NS_INT32SZ + 1) + if (rdlen < 1U + NS_INT32SZ) goto formerr; /* Address. */ @@ -463,13 +449,14 @@ ns_sprintrrf(const u_char *msg, size_t msglen, break; } - case ns_t_key: { + case ns_t_key: + case ns_t_dnskey: { char base64_key[NS_MD5RSA_MAX_BASE64]; u_int keyflags, protocol, algorithm, key_id; const char *leader; int n; - if (rdlen < NS_INT16SZ + NS_INT8SZ + NS_INT8SZ) + if (rdlen < 0U + NS_INT16SZ + NS_INT8SZ + NS_INT8SZ) goto formerr; /* Key flags, Protocol, Algorithm. */ @@ -505,18 +492,19 @@ ns_sprintrrf(const u_char *msg, size_t msglen, break; } - case ns_t_sig: { + case ns_t_sig: + case ns_t_rrsig: { char base64_key[NS_MD5RSA_MAX_BASE64]; u_int type, algorithm, labels, footprint; const char *leader; u_long t; int n; - if (rdlen < 22) + if (rdlen < 22U) goto formerr; /* Type covered, Algorithm, Label count, Original TTL. */ - type = ns_get16(rdata); rdata += NS_INT16SZ; + type = ns_get16(rdata); rdata += NS_INT16SZ; algorithm = *rdata++; labels = *rdata++; t = ns_get32(rdata); rdata += NS_INT32SZ; @@ -651,7 +639,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, len = SPRINTF((tmp, "%u %u %u ", mode, err, keysize)); T(addstr(tmp, len, &buf, &buflen)); - /* need to dump key, print otherdata length & other data */ + /* XXX need to dump key, print otherdata length & other data */ break; } @@ -661,10 +649,10 @@ ns_sprintrrf(const u_char *msg, size_t msglen, T(len = addname(msg, msglen, &rdata, origin, &buf, &buflen)); T(addstr(" ", 1, &buf, &buflen)); - rdata += 8; /* time */ + rdata += 8; /*%< time */ n = ns_get16(rdata); rdata += INT16SZ; - rdata += n; /* sig */ - n = ns_get16(rdata); rdata += INT16SZ; /* original id */ + rdata += n; /*%< sig */ + n = ns_get16(rdata); rdata += INT16SZ; /*%< original id */ sprintf(buf, "%d", ns_get16(rdata)); rdata += INT16SZ; addlen(strlen(buf), &buf, &buflen); @@ -676,7 +664,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, int pbyte, pbit; /* prefix length */ - if (rdlen == 0) goto formerr; + if (rdlen == 0U) goto formerr; len = SPRINTF((tmp, "%d ", *rdata)); T(addstr(tmp, len, &buf, &buflen)); pbit = *rdata; @@ -702,12 +690,350 @@ ns_sprintrrf(const u_char *msg, size_t msglen, T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); break; - } + } case ns_t_opt: { len = SPRINTF((tmp, "%u bytes", class)); T(addstr(tmp, len, &buf, &buflen)); break; + } + + case ns_t_ds: + case ns_t_dlv: + case ns_t_sshfp: { + u_int t; + + if (type == ns_t_ds || type == ns_t_dlv) { + if (rdlen < 4U) goto formerr; + t = ns_get16(rdata); + rdata += NS_INT16SZ; + len = SPRINTF((tmp, "%u ", t)); + T(addstr(tmp, len, &buf, &buflen)); + } else + if (rdlen < 2U) goto formerr; + + len = SPRINTF((tmp, "%u ", *rdata)); + T(addstr(tmp, len, &buf, &buflen)); + rdata++; + + len = SPRINTF((tmp, "%u ", *rdata)); + T(addstr(tmp, len, &buf, &buflen)); + rdata++; + + while (rdata < edata) { + len = SPRINTF((tmp, "%02X", *rdata)); + T(addstr(tmp, len, &buf, &buflen)); + rdata++; + } + break; + } + + case ns_t_nsec3: + case ns_t_nsec3param: { + u_int t, w, l, j, k, c; + + len = SPRINTF((tmp, "%u ", *rdata)); + T(addstr(tmp, len, &buf, &buflen)); + rdata++; + + len = SPRINTF((tmp, "%u ", *rdata)); + T(addstr(tmp, len, &buf, &buflen)); + rdata++; + + t = ns_get16(rdata); + rdata += NS_INT16SZ; + len = SPRINTF((tmp, "%u ", t)); + T(addstr(tmp, len, &buf, &buflen)); + + t = *rdata++; + if (t == 0) { + T(addstr("-", 1, &buf, &buflen)); + } else { + while (t-- > 0) { + len = SPRINTF((tmp, "%02X", *rdata)); + T(addstr(tmp, len, &buf, &buflen)); + rdata++; + } + } + if (type == ns_t_nsec3param) + break; + T(addstr(" ", 1, &buf, &buflen)); + + t = *rdata++; + while (t > 0) { + switch (t) { + case 1: + tmp[0] = base32hex[((rdata[0]>>3)&0x1f)]; + tmp[1] = base32hex[((rdata[0]<<2)&0x1c)]; + tmp[2] = tmp[3] = tmp[4] = '='; + tmp[5] = tmp[6] = tmp[7] = '='; + break; + case 2: + tmp[0] = base32hex[((rdata[0]>>3)&0x1f)]; + tmp[1] = base32hex[((rdata[0]<<2)&0x1c)| + ((rdata[1]>>6)&0x03)]; + tmp[2] = base32hex[((rdata[1]>>1)&0x1f)]; + tmp[3] = base32hex[((rdata[1]<<4)&0x10)]; + tmp[4] = tmp[5] = tmp[6] = tmp[7] = '='; + break; + case 3: + tmp[0] = base32hex[((rdata[0]>>3)&0x1f)]; + tmp[1] = base32hex[((rdata[0]<<2)&0x1c)| + ((rdata[1]>>6)&0x03)]; + tmp[2] = base32hex[((rdata[1]>>1)&0x1f)]; + tmp[3] = base32hex[((rdata[1]<<4)&0x10)| + ((rdata[2]>>4)&0x0f)]; + tmp[4] = base32hex[((rdata[2]<<1)&0x1e)]; + tmp[5] = tmp[6] = tmp[7] = '='; + break; + case 4: + tmp[0] = base32hex[((rdata[0]>>3)&0x1f)]; + tmp[1] = base32hex[((rdata[0]<<2)&0x1c)| + ((rdata[1]>>6)&0x03)]; + tmp[2] = base32hex[((rdata[1]>>1)&0x1f)]; + tmp[3] = base32hex[((rdata[1]<<4)&0x10)| + ((rdata[2]>>4)&0x0f)]; + tmp[4] = base32hex[((rdata[2]<<1)&0x1e)| + ((rdata[3]>>7)&0x01)]; + tmp[5] = base32hex[((rdata[3]>>2)&0x1f)]; + tmp[6] = base32hex[(rdata[3]<<3)&0x18]; + tmp[7] = '='; + break; + default: + tmp[0] = base32hex[((rdata[0]>>3)&0x1f)]; + tmp[1] = base32hex[((rdata[0]<<2)&0x1c)| + ((rdata[1]>>6)&0x03)]; + tmp[2] = base32hex[((rdata[1]>>1)&0x1f)]; + tmp[3] = base32hex[((rdata[1]<<4)&0x10)| + ((rdata[2]>>4)&0x0f)]; + tmp[4] = base32hex[((rdata[2]<<1)&0x1e)| + ((rdata[3]>>7)&0x01)]; + tmp[5] = base32hex[((rdata[3]>>2)&0x1f)]; + tmp[6] = base32hex[((rdata[3]<<3)&0x18)| + ((rdata[4]>>5)&0x07)]; + tmp[7] = base32hex[(rdata[4]&0x1f)]; + break; + } + T(addstr(tmp, 8, &buf, &buflen)); + if (t >= 5) { + rdata += 5; + t -= 5; + } else { + rdata += t; + t -= t; + } + } + + while (rdata < edata) { + w = *rdata++; + l = *rdata++; + for (j = 0; j < l; j++) { + if (rdata[j] == 0) + continue; + for (k = 0; k < 8; k++) { + if ((rdata[j] & (0x80 >> k)) == 0) + continue; + c = w * 256 + j * 8 + k; + len = SPRINTF((tmp, " %s", p_type(c))); + T(addstr(tmp, len, &buf, &buflen)); + } + } + rdata += l; + } + break; + } + + case ns_t_nsec: { + u_int w, l, j, k, c; + + T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); + + while (rdata < edata) { + w = *rdata++; + l = *rdata++; + for (j = 0; j < l; j++) { + if (rdata[j] == 0) + continue; + for (k = 0; k < 8; k++) { + if ((rdata[j] & (0x80 >> k)) == 0) + continue; + c = w * 256 + j * 8 + k; + len = SPRINTF((tmp, " %s", p_type(c))); + T(addstr(tmp, len, &buf, &buflen)); + } + } + rdata += l; + } + break; + } + + case ns_t_dhcid: { + int n; + unsigned int siz; + char base64_dhcid[8192]; + const char *leader; + + siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ + if (siz > sizeof(base64_dhcid) * 3/4) { + const char *str = "record too long to print"; + T(addstr(str, strlen(str), &buf, &buflen)); + } else { + len = b64_ntop(rdata, edata-rdata, base64_dhcid, siz); + + if (len < 0) + goto formerr; + + else if (len > 15) { + T(addstr(" (", 2, &buf, &buflen)); + leader = "\n\t\t"; + spaced = 0; + } + else + leader = " "; + + for (n = 0; n < len; n += 48) { + T(addstr(leader, strlen(leader), + &buf, &buflen)); + T(addstr(base64_dhcid + n, MIN(len - n, 48), + &buf, &buflen)); + } + if (len > 15) + T(addstr(" )", 2, &buf, &buflen)); + } + } + + case ns_t_ipseckey: { + int n; + unsigned int siz; + char base64_key[8192]; + const char *leader; + + if (rdlen < 2) + goto formerr; + + switch (rdata[1]) { + case 0: + case 3: + if (rdlen < 3) + goto formerr; + break; + case 1: + if (rdlen < 7) + goto formerr; + break; + case 2: + if (rdlen < 19) + goto formerr; + break; + default: + comment = "unknown IPSECKEY gateway type"; + goto hexify; + } + + len = SPRINTF((tmp, "%u ", *rdata)); + T(addstr(tmp, len, &buf, &buflen)); + rdata++; + + len = SPRINTF((tmp, "%u ", *rdata)); + T(addstr(tmp, len, &buf, &buflen)); + rdata++; + + len = SPRINTF((tmp, "%u ", *rdata)); + T(addstr(tmp, len, &buf, &buflen)); + rdata++; + + switch (rdata[-2]) { + case 0: + T(addstr(".", 1, &buf, &buflen)); + break; + case 1: + (void) inet_ntop(AF_INET, rdata, buf, buflen); + addlen(strlen(buf), &buf, &buflen); + rdata += 4; + break; + case 2: + (void) inet_ntop(AF_INET6, rdata, buf, buflen); + addlen(strlen(buf), &buf, &buflen); + rdata += 16; + break; + case 3: + T(addname(msg, msglen, &rdata, origin, &buf, &buflen)); + break; + } + + if (rdata >= edata) + break; + + siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */ + if (siz > sizeof(base64_key) * 3/4) { + const char *str = "record too long to print"; + T(addstr(str, strlen(str), &buf, &buflen)); + } else { + len = b64_ntop(rdata, edata-rdata, base64_key, siz); + + if (len < 0) + goto formerr; + + else if (len > 15) { + T(addstr(" (", 2, &buf, &buflen)); + leader = "\n\t\t"; + spaced = 0; + } + else + leader = " "; + + for (n = 0; n < len; n += 48) { + T(addstr(leader, strlen(leader), + &buf, &buflen)); + T(addstr(base64_key + n, MIN(len - n, 48), + &buf, &buflen)); + } + if (len > 15) + T(addstr(" )", 2, &buf, &buflen)); + } + } + + case ns_t_hip: { + unsigned int i, hip_len, algorithm, key_len; + char base64_key[NS_MD5RSA_MAX_BASE64]; + unsigned int siz; + const char *leader = "\n\t\t\t\t\t"; + + hip_len = *rdata++; + algorithm = *rdata++; + key_len = ns_get16(rdata); + rdata += NS_INT16SZ; + + siz = key_len*4/3 + 4; /* "+4" accounts for trailing \0 */ + if (siz > sizeof(base64_key) * 3/4) { + const char *str = "record too long to print"; + T(addstr(str, strlen(str), &buf, &buflen)); + } else { + len = sprintf(tmp, "( %u ", algorithm); + T(addstr(tmp, len, &buf, &buflen)); + + for (i = 0; i < hip_len; i++) { + len = sprintf(tmp, "%02X", *rdata); + T(addstr(tmp, len, &buf, &buflen)); + rdata++; + } + T(addstr(leader, strlen(leader), &buf, &buflen)); + + len = b64_ntop(rdata, key_len, base64_key, siz); + if (len < 0) + goto formerr; + + T(addstr(base64_key, len, &buf, &buflen)); + + rdata += key_len; + while (rdata < edata) { + T(addstr(leader, strlen(leader), &buf, &buflen)); + T(addname(msg, msglen, &rdata, origin, + &buf, &buflen)); + } + T(addstr(" )", 2, &buf, &buflen)); + } + break; } default: @@ -721,7 +1047,8 @@ ns_sprintrrf(const u_char *msg, size_t msglen, int n, m; char *p; - len = SPRINTF((tmp, "\\# %u (\t; %s", edata - rdata, comment)); + len = SPRINTF((tmp, "\\# %u%s\t; %s", (unsigned)(edata - rdata), + rdlen != 0U ? " (" : "", comment)); T(addstr(tmp, len, &buf, &buflen)); while (rdata < edata) { p = tmp; @@ -750,7 +1077,7 @@ ns_sprintrrf(const u_char *msg, size_t msglen, /* Private. */ -/* +/*% * size_t * prune_origin(name, origin) * Find out if the name is at or under the current origin. @@ -783,7 +1110,7 @@ prune_origin(const char *name, const char *origin) { return (name - oname); } -/* +/*% * int * charstr(rdata, edata, buf, buflen) * Format a <character-string> into the presentation buffer. @@ -839,11 +1166,11 @@ addname(const u_char *msg, size_t msglen, n = dn_expand(msg, msg + msglen, *pp, *buf, *buflen); if (n < 0) - goto enospc; /* Guess. */ + goto enospc; /*%< Guess. */ newlen = prune_origin(*buf, origin); if (**buf == '\0') { goto root; - } else if (newlen == 0) { + } else if (newlen == 0U) { /* Use "@" instead of name. */ if (newlen + 2 > *buflen) goto enospc; /* No room for "@\0". */ @@ -911,3 +1238,5 @@ addtab(size_t len, size_t target, int spaced, char **buf, size_t *buflen) { } return (spaced); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/nameser/ns_rdata.c b/usr/src/lib/libresolv2/common/nameser/ns_rdata.c new file mode 100644 index 0000000000..d0e318ed31 --- /dev/null +++ b/usr/src/lib/libresolv2/common/nameser/ns_rdata.c @@ -0,0 +1,300 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +/* + * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC") + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef lint +static const char rcsid[] = "$Id: ns_rdata.c,v 1.2 2009/01/23 23:49:15 tbox Exp $"; +#endif + +#include "port_before.h" + +#if __OpenBSD__ +#include <sys/types.h> +#endif +#include <netinet/in.h> +#include <arpa/nameser.h> + +#include <errno.h> +#include <resolv.h> +#include <string.h> + +#include "port_after.h" + +#define CONSUME_SRC \ + do { \ + rdata += n, rdlen -= n; \ + } while (0) + +#define CONSUME_DST \ + do { \ + nrdata += n, nrdsiz -= n, nrdlen += n; \ + } while (0) + +#define UNPACK_DNAME \ + do { \ + size_t t; \ + \ + if ((n = ns_name_unpack2(msg,eom,rdata,nrdata,nrdsiz,&t))<0) {\ + errno = EMSGSIZE; \ + return (-1); \ + } \ + CONSUME_SRC; \ + n = t; \ + CONSUME_DST; \ + } while (0) + +#define UNPACK_SOME(x) \ + do { \ + n = (x); \ + if ((size_t)n > rdlen || (size_t)n > nrdsiz) { \ + errno = EMSGSIZE; \ + return (-1); \ + } \ + memcpy(nrdata, rdata, n); \ + CONSUME_SRC; CONSUME_DST; \ + } while (0) + +#define UNPACK_REST(x) \ + do { \ + n = (x); \ + if ((size_t)n != rdlen) { \ + errno = EMSGSIZE; \ + return (-1); \ + } \ + memcpy(nrdata, rdata, n); \ + CONSUME_SRC; CONSUME_DST; \ + } while (0) + +ssize_t +ns_rdata_unpack(const u_char *msg, const u_char *eom, + ns_type type, const u_char *rdata, size_t rdlen, + u_char *nrdata, size_t nrdsiz) +{ + size_t nrdlen = 0; + int n; + + switch (type) { + case ns_t_a: + UNPACK_REST(NS_INADDRSZ); + break; + case ns_t_aaaa: + UNPACK_REST(NS_IN6ADDRSZ); + break; + case ns_t_cname: + case ns_t_mb: + case ns_t_mg: + case ns_t_mr: + case ns_t_ns: + case ns_t_ptr: + case ns_t_dname: + UNPACK_DNAME; + break; + case ns_t_soa: + UNPACK_DNAME; + UNPACK_DNAME; + UNPACK_SOME(NS_INT32SZ * 5); + break; + case ns_t_mx: + case ns_t_afsdb: + case ns_t_rt: + UNPACK_SOME(NS_INT16SZ); + UNPACK_DNAME; + break; + case ns_t_px: + UNPACK_SOME(NS_INT16SZ); + UNPACK_DNAME; + UNPACK_DNAME; + break; + case ns_t_srv: + UNPACK_SOME(NS_INT16SZ * 3); + UNPACK_DNAME; + break; + case ns_t_minfo: + case ns_t_rp: + UNPACK_DNAME; + UNPACK_DNAME; + break; + default: + UNPACK_SOME(rdlen); + break; + } + if (rdlen > 0) { + errno = EMSGSIZE; + return (-1); + } + return (nrdlen); +} + +#define EQUAL_CONSUME \ + do { \ + rdata1 += n, rdlen1 -= n; \ + rdata2 += n, rdlen2 -= n; \ + } while (0) + +#define EQUAL_DNAME \ + do { \ + ssize_t n; \ + \ + if (rdlen1 != rdlen2) \ + return (0); \ + n = ns_name_eq(rdata1, rdlen1, rdata2, rdlen2); \ + if (n <= 0) \ + return (n); \ + n = rdlen1; \ + EQUAL_CONSUME; \ + } while (0) + +#define EQUAL_SOME(x) \ + do { \ + size_t n = (x); \ + \ + if (n > rdlen1 || n > rdlen2) { \ + errno = EMSGSIZE; \ + return (-1); \ + } \ + if (memcmp(rdata1, rdata2, n) != 0) \ + return (0); \ + EQUAL_CONSUME; \ + } while (0) + +int +ns_rdata_equal(ns_type type, + const u_char *rdata1, size_t rdlen1, + const u_char *rdata2, size_t rdlen2) +{ + switch (type) { + case ns_t_cname: + case ns_t_mb: + case ns_t_mg: + case ns_t_mr: + case ns_t_ns: + case ns_t_ptr: + case ns_t_dname: + EQUAL_DNAME; + break; + case ns_t_soa: + /* "There can be only one." --Highlander */ + break; + case ns_t_mx: + case ns_t_afsdb: + case ns_t_rt: + EQUAL_SOME(NS_INT16SZ); + EQUAL_DNAME; + break; + case ns_t_px: + EQUAL_SOME(NS_INT16SZ); + EQUAL_DNAME; + EQUAL_DNAME; + break; + case ns_t_srv: + EQUAL_SOME(NS_INT16SZ * 3); + EQUAL_DNAME; + break; + case ns_t_minfo: + case ns_t_rp: + EQUAL_DNAME; + EQUAL_DNAME; + break; + default: + EQUAL_SOME(rdlen1); + break; + } + if (rdlen1 != 0 || rdlen2 != 0) + return (0); + return (1); +} + +#define REFERS_DNAME \ + do { \ + int n; \ + \ + n = ns_name_eq(rdata, rdlen, nname, NS_MAXNNAME); \ + if (n < 0) \ + return (-1); \ + if (n > 0) \ + return (1); \ + n = dn_skipname(rdata, rdata + rdlen); \ + if (n < 0) \ + return (-1); \ + CONSUME_SRC; \ + } while (0) + +#define REFERS_SOME(x) \ + do { \ + size_t n = (x); \ + \ + if (n > rdlen) { \ + errno = EMSGSIZE; \ + return (-1); \ + } \ + CONSUME_SRC; \ + } while (0) + +int +ns_rdata_refers(ns_type type, + const u_char *rdata, size_t rdlen, + const u_char *nname) +{ + switch (type) { + case ns_t_cname: + case ns_t_mb: + case ns_t_mg: + case ns_t_mr: + case ns_t_ns: + case ns_t_ptr: + case ns_t_dname: + REFERS_DNAME; + break; + case ns_t_soa: + REFERS_DNAME; + REFERS_DNAME; + REFERS_SOME(NS_INT32SZ * 5); + break; + case ns_t_mx: + case ns_t_afsdb: + case ns_t_rt: + REFERS_SOME(NS_INT16SZ); + REFERS_DNAME; + break; + case ns_t_px: + REFERS_SOME(NS_INT16SZ); + REFERS_DNAME; + REFERS_DNAME; + break; + case ns_t_srv: + REFERS_SOME(NS_INT16SZ * 3); + REFERS_DNAME; + break; + case ns_t_minfo: + case ns_t_rp: + REFERS_DNAME; + REFERS_DNAME; + break; + default: + REFERS_SOME(rdlen); + break; + } + if (rdlen != 0) { + errno = EMSGSIZE; + return (-1); + } + return (0); +} diff --git a/usr/src/lib/libresolv2/common/nameser/ns_samedomain.c b/usr/src/lib/libresolv2/common/nameser/ns_samedomain.c index 9ae0195f27..5e9f5cab54 100644 --- a/usr/src/lib/libresolv2/common/nameser/ns_samedomain.c +++ b/usr/src/lib/libresolv2/common/nameser/ns_samedomain.c @@ -1,29 +1,22 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1995,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef lint -static const char rcsid[] = "$Id: ns_samedomain.c,v 8.11 2003/04/14 14:52:48 vixie Exp $"; +static const char rcsid[] = "$Id: ns_samedomain.c,v 1.6 2005/04/27 04:56:40 sra Exp $"; #endif #include "port_before.h" @@ -35,21 +28,22 @@ static const char rcsid[] = "$Id: ns_samedomain.c,v 8.11 2003/04/14 14:52:48 vix #include "port_after.h" -/* - * int - * ns_samedomain(a, b) +/*% * Check whether a name belongs to a domain. + * * Inputs: - * a - the domain whose ancestory is being verified - * b - the potential ancestor we're checking against + *\li a - the domain whose ancestory is being verified + *\li b - the potential ancestor we're checking against + * * Return: - * boolean - is a at or below b? + *\li boolean - is a at or below b? + * * Notes: - * Trailing dots are first removed from name and domain. + *\li Trailing dots are first removed from name and domain. * Always compare complete subdomains, not only whether the * domain name is the trailing string of the given name. * - * "host.foobar.top" lies in "foobar.top" and in "top" and in "" + *\li "host.foobar.top" lies in "foobar.top" and in "top" and in "" * but NOT in "bar.top" */ @@ -63,7 +57,7 @@ ns_samedomain(const char *a, const char *b) { lb = strlen(b); /* Ignore a trailing label separator (i.e. an unescaped dot) in 'a'. */ - if (la != 0 && a[la - 1] == '.') { + if (la != 0U && a[la - 1] == '.') { escaped = 0; /* Note this loop doesn't get executed if la==1. */ for (i = la - 2; i >= 0; i--) @@ -79,7 +73,7 @@ ns_samedomain(const char *a, const char *b) { } /* Ignore a trailing label separator (i.e. an unescaped dot) in 'b'. */ - if (lb != 0 && b[lb - 1] == '.') { + if (lb != 0U && b[lb - 1] == '.') { escaped = 0; /* note this loop doesn't get executed if lb==1 */ for (i = lb - 2; i >= 0; i--) @@ -95,7 +89,7 @@ ns_samedomain(const char *a, const char *b) { } /* lb == 0 means 'b' is the root domain, so 'a' must be in 'b'. */ - if (lb == 0) + if (lb == 0U) return (1); /* 'b' longer than 'a' means 'a' can't be in 'b'. */ @@ -147,9 +141,7 @@ ns_samedomain(const char *a, const char *b) { return (strncasecmp(cp, b, lb) == 0); } -/* - * int - * ns_subdomain(a, b) +/*% * is "a" a subdomain of "b"? */ int @@ -157,30 +149,31 @@ ns_subdomain(const char *a, const char *b) { return (ns_samename(a, b) != 1 && ns_samedomain(a, b)); } -/* - * int - * ns_makecanon(src, dst, dstsize) +/*% * make a canonical copy of domain name "src" + * * notes: + * \code * foo -> foo. * foo. -> foo. * foo.. -> foo. * foo\. -> foo\.. * foo\\. -> foo\\. + * \endcode */ int ns_makecanon(const char *src, char *dst, size_t dstsize) { size_t n = strlen(src); - if (n + sizeof "." > dstsize) { /* Note: sizeof == 2 */ + if (n + sizeof "." > dstsize) { /*%< Note: sizeof == 2 */ errno = EMSGSIZE; return (-1); } strcpy(dst, src); - while (n >= 1 && dst[n - 1] == '.') /* Ends in "." */ - if (n >= 2 && dst[n - 2] == '\\' && /* Ends in "\." */ - (n < 3 || dst[n - 3] != '\\')) /* But not "\\." */ + while (n >= 1U && dst[n - 1] == '.') /*%< Ends in "." */ + if (n >= 2U && dst[n - 2] == '\\' && /*%< Ends in "\." */ + (n < 3U || dst[n - 3] != '\\')) /*%< But not "\\." */ break; else dst[--n] = '\0'; @@ -189,14 +182,13 @@ ns_makecanon(const char *src, char *dst, size_t dstsize) { return (0); } -/* - * int - * ns_samename(a, b) +/*% * determine whether domain name "a" is the same as domain name "b" + * * return: - * -1 on error - * 0 if names differ - * 1 if names are the same + *\li -1 on error + *\li 0 if names differ + *\li 1 if names are the same */ int @@ -211,3 +203,5 @@ ns_samename(const char *a, const char *b) { else return (0); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/nameser/ns_sign.c b/usr/src/lib/libresolv2/common/nameser/ns_sign.c index 74674134c5..5748a090d9 100644 --- a/usr/src/lib/libresolv2/common/nameser/ns_sign.c +++ b/usr/src/lib/libresolv2/common/nameser/ns_sign.c @@ -1,29 +1,22 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1999 by Internet Software Consortium, Inc. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef lint -static const char rcsid[] = "$Id: ns_sign.c,v 8.12 2002/10/01 06:48:37 marka Exp $"; +static const char rcsid[] = "$Id: ns_sign.c,v 1.6 2006/03/09 23:57:56 marka Exp $"; #endif /* Import. */ @@ -60,24 +53,26 @@ static const char rcsid[] = "$Id: ns_sign.c,v 8.12 2002/10/01 06:48:37 marka Exp } \ } while (0) -/* ns_sign +/*% + * ns_sign + * * Parameters: - * msg message to be sent - * msglen input - length of message + *\li msg message to be sent + *\li msglen input - length of message * output - length of signed message - * msgsize length of buffer containing message - * error value to put in the error field - * key tsig key used for signing - * querysig (response), the signature in the query - * querysiglen (response), the length of the signature in the query - * sig a buffer to hold the generated signature - * siglen input - length of signature buffer + *\li msgsize length of buffer containing message + *\li error value to put in the error field + *\li key tsig key used for signing + *\li querysig (response), the signature in the query + *\li querysiglen (response), the length of the signature in the query + *\li sig a buffer to hold the generated signature + *\li siglen input - length of signature buffer * output - length of signature * * Errors: - * - bad input data (-1) - * - bad key / sign failed (-BADKEY) - * - not enough space (NS_TSIG_ERROR_NO_SPACE) + *\li - bad input data (-1) + *\li - bad key / sign failed (-BADKEY) + *\li - not enough space (NS_TSIG_ERROR_NO_SPACE) */ int ns_sign(u_char *msg, int *msglen, int msgsize, int error, void *k, @@ -96,24 +91,27 @@ ns_sign2(u_char *msg, int *msglen, int msgsize, int error, void *k, { HEADER *hp = (HEADER *)msg; DST_KEY *key = (DST_KEY *)k; - u_char *cp = msg + *msglen, *eob = msg + msgsize; + u_char *cp, *eob; u_char *lenp; u_char *alg; int n; time_t timesigned; - u_char name[NS_MAXCDNAME]; + u_char name[NS_MAXCDNAME]; dst_init(); if (msg == NULL || msglen == NULL || sig == NULL || siglen == NULL) return (-1); + cp = msg + *msglen; + eob = msg + msgsize; + /* Name. */ if (key != NULL && error != ns_r_badsig && error != ns_r_badkey) { n = ns_name_pton(key->dk_key_name, name, sizeof name); if (n != -1) n = ns_name_pack(name, cp, eob - cp, - (const u_char **)dnptrs, - (const u_char **)lastdnptr); + (const u_char **)dnptrs, + (const u_char **)lastdnptr); } else { n = ns_name_pton("", name, sizeof name); @@ -128,7 +126,7 @@ ns_sign2(u_char *msg, int *msglen, int msgsize, int error, void *k, BOUNDS_CHECK(cp, INT16SZ + INT16SZ + INT32SZ + INT16SZ); PUTSHORT(ns_t_tsig, cp); PUTSHORT(ns_c_any, cp); - PUTLONG(0, cp); /* TTL */ + PUTLONG(0, cp); /*%< TTL */ lenp = cp; cp += 2; @@ -195,18 +193,18 @@ ns_sign2(u_char *msg, int *msglen, int msgsize, int error, void *k, /* Digest the time signed, fudge, error, and other data */ cp2 = buf; - PUTSHORT(0, cp2); /* Top 16 bits of time */ + PUTSHORT(0, cp2); /*%< Top 16 bits of time */ if (error != ns_r_badtime) PUTLONG(timesigned, cp2); else PUTLONG(in_timesigned, cp2); PUTSHORT(NS_TSIG_FUDGE, cp2); - PUTSHORT(error, cp2); /* Error */ + PUTSHORT(error, cp2); /*%< Error */ if (error != ns_r_badtime) - PUTSHORT(0, cp2); /* Other data length */ + PUTSHORT(0, cp2); /*%< Other data length */ else { - PUTSHORT(INT16SZ+INT32SZ, cp2); /* Other data length */ - PUTSHORT(0, cp2); /* Top 16 bits of time */ + PUTSHORT(INT16SZ+INT32SZ, cp2); /*%< Other data length */ + PUTSHORT(0, cp2); /*%< Top 16 bits of time */ PUTLONG(timesigned, cp2); } dst_sign_data(SIG_MODE_UPDATE, key, &ctx, buf, cp2-buf, @@ -228,17 +226,17 @@ ns_sign2(u_char *msg, int *msglen, int msgsize, int error, void *k, /* The original message ID & error. */ BOUNDS_CHECK(cp, INT16SZ + INT16SZ); - PUTSHORT(ntohs(hp->id), cp); /* already in network order */ + PUTSHORT(ntohs(hp->id), cp); /*%< already in network order */ PUTSHORT(error, cp); /* Other data. */ BOUNDS_CHECK(cp, INT16SZ); if (error != ns_r_badtime) - PUTSHORT(0, cp); /* Other data length */ + PUTSHORT(0, cp); /*%< Other data length */ else { - PUTSHORT(INT16SZ+INT32SZ, cp); /* Other data length */ + PUTSHORT(INT16SZ+INT32SZ, cp); /*%< Other data length */ BOUNDS_CHECK(cp, INT32SZ+INT16SZ); - PUTSHORT(0, cp); /* Top 16 bits of time */ + PUTSHORT(0, cp); /*%< Top 16 bits of time */ PUTLONG(timesigned, cp); } @@ -327,7 +325,7 @@ ns_sign_tcp2(u_char *msg, int *msglen, int msgsize, int error, BOUNDS_CHECK(cp, INT16SZ + INT16SZ + INT32SZ + INT16SZ); PUTSHORT(ns_t_tsig, cp); PUTSHORT(ns_c_any, cp); - PUTLONG(0, cp); /* TTL */ + PUTLONG(0, cp); /*%< TTL */ lenp = cp; cp += 2; @@ -350,7 +348,7 @@ ns_sign_tcp2(u_char *msg, int *msglen, int msgsize, int error, /* Digest the time signed and fudge. */ cp2 = buf; - PUTSHORT(0, cp2); /* Top 16 bits of time */ + PUTSHORT(0, cp2); /*%< Top 16 bits of time */ PUTLONG(timesigned, cp2); PUTSHORT(NS_TSIG_FUDGE, cp2); @@ -371,7 +369,7 @@ ns_sign_tcp2(u_char *msg, int *msglen, int msgsize, int error, /* The original message ID & error. */ BOUNDS_CHECK(cp, INT16SZ + INT16SZ); - PUTSHORT(ntohs(hp->id), cp); /* already in network order */ + PUTSHORT(ntohs(hp->id), cp); /*%< already in network order */ PUTSHORT(error, cp); /* Other data. */ @@ -385,3 +383,5 @@ ns_sign_tcp2(u_char *msg, int *msglen, int msgsize, int error, *msglen = (cp - msg); return (0); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/nameser/ns_ttl.c b/usr/src/lib/libresolv2/common/nameser/ns_ttl.c index 274359036f..69c2f83f57 100644 --- a/usr/src/lib/libresolv2/common/nameser/ns_ttl.c +++ b/usr/src/lib/libresolv2/common/nameser/ns_ttl.c @@ -1,29 +1,22 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #ifndef lint -static const char rcsid[] = "$Id: ns_ttl.c,v 8.8 1999/10/13 16:39:36 vixie Exp $"; +static const char rcsid[] = "$Id: ns_ttl.c,v 1.4 2005/07/28 06:51:49 marka Exp $"; #endif /* Import. */ @@ -140,7 +133,8 @@ ns_parse_ttl(const char *src, u_long *dst) { goto einval; else ttl += tmp; - } + } else if (!dirty) + goto einval; *dst = ttl; return (0); @@ -164,3 +158,5 @@ fmt1(int t, char s, char **buf, size_t *buflen) { *buflen -= len; return (0); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/nameser/ns_verify.c b/usr/src/lib/libresolv2/common/nameser/ns_verify.c index c8ccf219d5..97c012db8f 100644 --- a/usr/src/lib/libresolv2/common/nameser/ns_verify.c +++ b/usr/src/lib/libresolv2/common/nameser/ns_verify.c @@ -1,29 +1,22 @@ /* - * Copyright 2001-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1999 by Internet Software Consortium, Inc. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef lint -static const char rcsid[] = "$Id: ns_verify.c,v 8.14 2001/05/29 05:49:40 marka Exp $"; +static const char rcsid[] = "$Id: ns_verify.c,v 1.5 2006/03/09 23:57:56 marka Exp $"; #endif /* Import. */ @@ -114,28 +107,29 @@ ns_find_tsig(u_char *msg, u_char *eom) { } /* ns_verify + * * Parameters: - * statp res stuff - * msg received message - * msglen length of message - * key tsig key used for verifying. - * querysig (response), the signature in the query - * querysiglen (response), the length of the signature in the query - * sig (query), a buffer to hold the signature - * siglen (query), input - length of signature buffer + *\li statp res stuff + *\li msg received message + *\li msglen length of message + *\li key tsig key used for verifying. + *\li querysig (response), the signature in the query + *\li querysiglen (response), the length of the signature in the query + *\li sig (query), a buffer to hold the signature + *\li siglen (query), input - length of signature buffer * output - length of signature * * Errors: - * - bad input (-1) - * - invalid dns message (NS_TSIG_ERROR_FORMERR) - * - TSIG is not present (NS_TSIG_ERROR_NO_TSIG) - * - key doesn't match (-ns_r_badkey) - * - TSIG verification fails with BADKEY (-ns_r_badkey) - * - TSIG verification fails with BADSIG (-ns_r_badsig) - * - TSIG verification fails with BADTIME (-ns_r_badtime) - * - TSIG verification succeeds, error set to BAKEY (ns_r_badkey) - * - TSIG verification succeeds, error set to BADSIG (ns_r_badsig) - * - TSIG verification succeeds, error set to BADTIME (ns_r_badtime) + *\li - bad input (-1) + *\li - invalid dns message (NS_TSIG_ERROR_FORMERR) + *\li - TSIG is not present (NS_TSIG_ERROR_NO_TSIG) + *\li - key doesn't match (-ns_r_badkey) + *\li - TSIG verification fails with BADKEY (-ns_r_badkey) + *\li - TSIG verification fails with BADSIG (-ns_r_badsig) + *\li - TSIG verification fails with BADTIME (-ns_r_badtime) + *\li - TSIG verification succeeds, error set to BAKEY (ns_r_badkey) + *\li - TSIG verification succeeds, error set to BADSIG (ns_r_badsig) + *\li - TSIG verification succeeds, error set to BADTIME (ns_r_badtime) */ int ns_verify(u_char *msg, int *msglen, void *k, @@ -151,7 +145,7 @@ ns_verify(u_char *msg, int *msglen, void *k, int n; int error; u_int16_t type, length; - u_int16_t fudge, sigfieldlen, id, otherfieldlen; + u_int16_t fudge, sigfieldlen, otherfieldlen; dst_init(); if (msg == NULL || msglen == NULL || *msglen < 0) @@ -205,9 +199,9 @@ ns_verify(u_char *msg, int *msglen, void *k, sigstart = cp; cp += sigfieldlen; - /* Read the original id and error. */ + /* Skip id and read error. */ BOUNDS_CHECK(cp, 2*INT16SZ); - GETSHORT(id, cp); + cp += INT16SZ; GETSHORT(error, cp); /* Parse the other data. */ @@ -348,17 +342,19 @@ ns_verify_tcp(u_char *msg, int *msglen, ns_tcp_tsig_state *state, int required) { HEADER *hp = (HEADER *)msg; - u_char *recstart, *rdatastart, *sigstart; + u_char *recstart, *sigstart; unsigned int sigfieldlen, otherfieldlen; - u_char *cp, *eom = msg + *msglen, *cp2; + u_char *cp, *eom, *cp2; char name[MAXDNAME], alg[MAXDNAME]; u_char buf[MAXDNAME]; - int n, type, length, fudge, id, error; + int n, type, length, fudge, error; time_t timesigned; if (msg == NULL || msglen == NULL || state == NULL) return (-1); + eom = msg + *msglen; + state->counter++; if (state->counter == 0) return (ns_verify(msg, msglen, state->key, @@ -410,7 +406,6 @@ ns_verify_tcp(u_char *msg, int *msglen, ns_tcp_tsig_state *state, return (NS_TSIG_ERROR_FORMERR); /* Read the algorithm name. */ - rdatastart = cp; n = dn_expand(msg, eom, cp, alg, MAXDNAME); if (n < 0) return (NS_TSIG_ERROR_FORMERR); @@ -436,9 +431,9 @@ ns_verify_tcp(u_char *msg, int *msglen, ns_tcp_tsig_state *state, sigstart = cp; cp += sigfieldlen; - /* Read the original id and error. */ + /* Skip id and read error. */ BOUNDS_CHECK(cp, 2*INT16SZ); - GETSHORT(id, cp); + cp += INT16SZ; GETSHORT(error, cp); /* Parse the other data. */ @@ -456,7 +451,7 @@ ns_verify_tcp(u_char *msg, int *msglen, ns_tcp_tsig_state *state, /* Digest the time signed and fudge. */ cp2 = buf; - PUTSHORT(0, cp2); /* Top 16 bits of time. */ + PUTSHORT(0, cp2); /*%< Top 16 bits of time. */ PUTLONG(timesigned, cp2); PUTSHORT(NS_TSIG_FUDGE, cp2); @@ -485,3 +480,5 @@ ns_verify_tcp(u_char *msg, int *msglen, ns_tcp_tsig_state *state, return (0); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/resolv/herror.c b/usr/src/lib/libresolv2/common/resolv/herror.c index 1101057748..703ab8fe4d 100644 --- a/usr/src/lib/libresolv2/common/resolv/herror.c +++ b/usr/src/lib/libresolv2/common/resolv/herror.c @@ -1,9 +1,4 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* * Copyright (c) 1987, 1993 * The Regents of the University of California. All rights reserved. * @@ -37,27 +32,25 @@ */ /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: herror.c,v 8.13 2001/06/18 14:44:06 marka Exp $"; +static const char rcsid[] = "$Id: herror.c,v 1.4 2005/04/27 04:56:41 sra Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -76,20 +69,22 @@ static const char rcsid[] = "$Id: herror.c,v 8.13 2001/06/18 14:44:06 marka Exp #include <irs.h> #include "port_after.h" -#undef h_errno const char *h_errlist[] = { "Resolver Error 0 (no error)", - "Unknown host", /* 1 HOST_NOT_FOUND */ - "Host name lookup failure", /* 2 TRY_AGAIN */ - "Unknown server error", /* 3 NO_RECOVERY */ - "No address associated with name", /* 4 NO_ADDRESS */ + "Unknown host", /*%< 1 HOST_NOT_FOUND */ + "Host name lookup failure", /*%< 2 TRY_AGAIN */ + "Unknown server error", /*%< 3 NO_RECOVERY */ + "No address associated with name", /*%< 4 NO_ADDRESS */ }; int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] }; +#if !(__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) +#undef h_errno int h_errno; +#endif -/* +/*% * herror -- * print the error indicated by the h_errno value. */ @@ -118,7 +113,7 @@ herror(const char *s) { writev(STDERR_FILENO, iov, (v - iov) + 1); } -/* +/*% * hstrerror -- * return the string associated with a given "host" errno value. */ @@ -130,3 +125,5 @@ hstrerror(int err) { return (h_errlist[err]); return ("Unknown resolver error"); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/resolv/mtctxres.c b/usr/src/lib/libresolv2/common/resolv/mtctxres.c new file mode 100644 index 0000000000..2e79b1e7b4 --- /dev/null +++ b/usr/src/lib/libresolv2/common/resolv/mtctxres.c @@ -0,0 +1,135 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +#include <port_before.h> +#ifdef DO_PTHREADS +#include <pthread.h> +#endif +#include <errno.h> +#include <netdb.h> +#include <stdlib.h> +#include <string.h> +#include <resolv_mt.h> +#include <irs.h> +#include <port_after.h> + +#ifdef DO_PTHREADS +static pthread_key_t key; +static int mt_key_initialized = 0; + +static int __res_init_ctx(void); +static void __res_destroy_ctx(void *); + +#if defined(sun) && !defined(__GNUC__) +#pragma init (_mtctxres_init) +#endif +#endif + +static mtctxres_t sharedctx; + +#ifdef DO_PTHREADS +/* + * Initialize the TSD key. By doing this at library load time, we're + * implicitly running without interference from other threads, so there's + * no need for locking. + */ +static void +_mtctxres_init(void) { + int pthread_keycreate_ret; + + pthread_keycreate_ret = pthread_key_create(&key, __res_destroy_ctx); + if (pthread_keycreate_ret == 0) + mt_key_initialized = 1; +} +#endif + +/* + * To support binaries that used the private MT-safe interface in + * Solaris 8, we still need to provide the __res_enable_mt() + * and __res_disable_mt() entry points. They're do-nothing routines. + */ +int +__res_enable_mt(void) { + return (-1); +} + +int +__res_disable_mt(void) { + return (0); +} + +#ifdef DO_PTHREADS +static int +__res_init_ctx(void) { + + mtctxres_t *mt; + int ret; + + + if (pthread_getspecific(key) != 0) { + /* Already exists */ + return (0); + } + + if ((mt = malloc(sizeof (mtctxres_t))) == 0) { + errno = ENOMEM; + return (-1); + } + + memset(mt, 0, sizeof (mtctxres_t)); + + if ((ret = pthread_setspecific(key, mt)) != 0) { + free(mt); + errno = ret; + return (-1); + } + + return (0); +} + +static void +__res_destroy_ctx(void *value) { + + mtctxres_t *mt = (mtctxres_t *)value; + + if (mt != 0) + free(mt); +} +#endif + +mtctxres_t * +___mtctxres(void) { +#ifdef DO_PTHREADS + mtctxres_t *mt; + + /* + * This if clause should only be executed if we are linking + * statically. When linked dynamically _mtctxres_init() should + * be called at binding time due the #pragma above. + */ + if (!mt_key_initialized) { + static pthread_mutex_t keylock = PTHREAD_MUTEX_INITIALIZER; + if (pthread_mutex_lock(&keylock) == 0) { + _mtctxres_init(); + (void) pthread_mutex_unlock(&keylock); + } + } + + /* + * If we have already been called in this thread return the existing + * context. Otherwise recreat a new context and return it. If + * that fails return a global context. + */ + if (mt_key_initialized) { + if (((mt = pthread_getspecific(key)) != 0) || + (__res_init_ctx() == 0 && + (mt = pthread_getspecific(key)) != 0)) { + return (mt); + } + } +#endif + return (&sharedctx); +} diff --git a/usr/src/lib/libresolv2/common/resolv/res_comp.c b/usr/src/lib/libresolv2/common/resolv/res_comp.c index a0a3d9abb2..59d5acc8ca 100644 --- a/usr/src/lib/libresolv2/common/resolv/res_comp.c +++ b/usr/src/lib/libresolv2/common/resolv/res_comp.c @@ -1,8 +1,9 @@ /* - * Copyright 2003 by Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ + /* * Copyright (c) 1985, 1993 * The Regents of the University of California. All rights reserved. @@ -57,27 +58,25 @@ */ /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: res_comp.c,v 8.16 2002/08/07 03:47:34 marka Exp $"; +static const char rcsid[] = "$Id: res_comp.c,v 1.5 2005/07/28 06:51:50 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -92,20 +91,21 @@ static const char rcsid[] = "$Id: res_comp.c,v 8.16 2002/08/07 03:47:34 marka Ex #include <unistd.h> #include "port_after.h" -#ifdef ORIGINAL_ISC_CODE -#else +#ifndef ORIGINAL_ISC_CODE #pragma weak __dn_skipname = dn_skipname #pragma weak __res_dnok = res_dnok #pragma weak __res_hnok = res_hnok #pragma weak __res_mailok = res_mailok #pragma weak __res_ownok = res_ownok #endif /* ORIGINAL_ISC_CODE */ -/* + +/*% * Expand compressed domain name 'src' to full domain name. - * 'msg' is a pointer to the begining of the message, - * 'eom' points to the first location after the message, - * 'dst' is a pointer to a buffer of size 'dstsiz' for the result. - * Return size of compressed name or -1 if there was an error. + * + * \li 'msg' is a pointer to the begining of the message, + * \li 'eom' points to the first location after the message, + * \li 'dst' is a pointer to a buffer of size 'dstsiz' for the result. + * \li Return size of compressed name or -1 if there was an error. */ int dn_expand(const u_char *msg, const u_char *eom, const u_char *src, @@ -118,10 +118,11 @@ dn_expand(const u_char *msg, const u_char *eom, const u_char *src, return (n); } -/* +/*% * Pack domain name 'exp_dn' in presentation form into 'comp_dn'. - * Return the size of the compressed name or -1. - * 'length' is the size of the array pointed to by 'comp_dn'. + * + * \li Return the size of the compressed name or -1. + * \li 'length' is the size of the array pointed to by 'comp_dn'. */ int dn_comp(const char *src, u_char *dst, int dstsiz, @@ -132,7 +133,8 @@ dn_comp(const char *src, u_char *dst, int dstsiz, (const u_char **)lastdnptr)); } -/* + +/*% * Skip over a compressed domain name. Return the size or -1. */ int @@ -144,11 +146,9 @@ dn_skipname(const u_char *ptr, const u_char *eom) { return (ptr - saveptr); } -/* +/*% * Verify that a domain name uses an acceptable character set. - */ - -/* + * * Note the conspicuous absence of ctype macros in these definitions. On * non-ASCII hosts, we can't depend on string literals or ctype macros to * tell us anything about network-format data. The rest of the BIND system @@ -176,7 +176,7 @@ dn_skipname(const u_char *ptr, const u_char *eom) { int res_hnok(const char *dn) { - int ppch = '\0', pch = PERIOD, ch = *dn++; + int pch = PERIOD, ch = *dn++; while (ch != '\0') { int nch = *dn++; @@ -193,12 +193,12 @@ res_hnok(const char *dn) { if (!middlechar(ch)) return (0); } - ppch = pch, pch = ch, ch = nch; + pch = ch, ch = nch; } return (1); } -/* +/*% * hostname-like (A, MX, WKS) owners can have "*" as their first label * but must otherwise be as a host name. */ @@ -213,7 +213,7 @@ res_ownok(const char *dn) { return (res_hnok(dn)); } -/* +/*% * SOA RNAMEs and RP RNAMEs can have any printable character in their first * label, but the rest of the name has to look like a host name. */ @@ -241,8 +241,8 @@ res_mailok(const char *dn) { return (0); } -/* - * This function is quite liberal, since RFC 1034's character sets are only +/*% + * This function is quite liberal, since RFC1034's character sets are only * recommendations. */ int @@ -256,7 +256,7 @@ res_dnok(const char *dn) { } #ifdef BIND_4_COMPAT -/* +/*% * This module must export the following externally-visible symbols: * ___putlong * ___putshort @@ -264,17 +264,18 @@ res_dnok(const char *dn) { * __getshort * Note that one _ comes from C and the others come from us. */ -#ifdef ORIGINAL_ISC_CODE -#else -#ifdef __putlong -#undef __putlong + +#ifdef SOLARIS2 +#ifdef __putlong +#undef __putlong #endif -#ifdef __putshort -#undef __putshort +#ifdef __putshort +#undef __putshort #endif -#pragma weak putlong = __putlong -#pragma weak putshort = __putshort -#endif /* ORIGINAL_ISC_CODE */ +#pragma weak putlong = __putlong +#pragma weak putshort = __putshort +#endif /* SOLARIS2 */ + void __putlong(u_int32_t src, u_char *dst) { ns_put32(src, dst); } void __putshort(u_int16_t src, u_char *dst) { ns_put16(src, dst); } #ifndef __ultrix__ @@ -282,3 +283,5 @@ u_int32_t _getlong(const u_char *src) { return (ns_get32(src)); } u_int16_t _getshort(const u_char *src) { return (ns_get16(src)); } #endif /*__ultrix__*/ #endif /*BIND_4_COMPAT*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/resolv/res_data.c b/usr/src/lib/libresolv2/common/resolv/res_data.c index 50368f6600..9297fe311f 100644 --- a/usr/src/lib/libresolv2/common/resolv/res_data.c +++ b/usr/src/lib/libresolv2/common/resolv/res_data.c @@ -1,29 +1,28 @@ /* - * Copyright 2003 by Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ + /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1995-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: res_data.c,v 8.18 2000/12/23 08:14:58 vixie Exp $"; +static const char rcsid[] = "$Id: res_data.c,v 1.7 2008/12/11 09:59:00 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -47,22 +46,21 @@ static const char rcsid[] = "$Id: res_data.c,v 8.18 2000/12/23 08:14:58 vixie Ex #include <unistd.h> #include "port_after.h" -#undef _res -#ifdef ORIGINAL_ISC_CODE -#else +#ifndef ORIGINAL_ISC_CODE #pragma weak __fp_nquery = fp_nquery #pragma weak __fp_query = fp_query #pragma weak __p_query = p_query #pragma weak __hostalias = hostalias +#pragma weak __res_randomid = res_randomid #endif const char *_res_opcodes[] = { "QUERY", "IQUERY", "CQUERYM", - "CQUERYU", /* experimental */ - "NOTIFY", /* experimental */ + "CQUERYU", /*%< experimental */ + "NOTIFY", /*%< experimental */ "UPDATE", "6", "7", @@ -85,13 +83,18 @@ const char *_res_sectioncodes[] = { }; #endif +#undef _res #ifndef __BIND_NOSTATIC struct __res_state _res # if defined(__BIND_RES_TEXT) - = { RES_TIMEOUT, } /* Motorola, et al. */ + = { RES_TIMEOUT, } /*%< Motorola, et al. */ # endif ; +#if defined(DO_PTHREADS) || defined(__linux) +#define _res (*__res_state()) +#endif + /* Proto. */ int res_ourserver_p(const res_state, const struct sockaddr_in *); @@ -131,7 +134,7 @@ res_init(void) { * has set it to something in particular, we can randomize it now. */ if (!_res.id) - _res.id = res_randomid(); + _res.id = res_nrandomid(&_res); return (__res_vinit(&_res, 1)); } @@ -148,23 +151,23 @@ fp_query(const u_char *msg, FILE *file) { void fp_nquery(const u_char *msg, int len, FILE *file) { - if ((_res.options & RES_INIT) == 0 && res_init() == -1) + if ((_res.options & RES_INIT) == 0U && res_init() == -1) return; res_pquery(&_res, msg, len, file); } int -res_mkquery(int op, /* opcode of query */ - const char *dname, /* domain name */ - int class, int type, /* class and type of query */ - const u_char *data, /* resource record data */ - int datalen, /* length of data */ - const u_char *newrr_in, /* new rr for modify or append */ - u_char *buf, /* buffer to put query */ - int buflen) /* size of buffer */ +res_mkquery(int op, /*!< opcode of query */ + const char *dname, /*!< domain name */ + int class, int type, /*!< class and type of query */ + const u_char *data, /*!< resource record data */ + int datalen, /*!< length of data */ + const u_char *newrr_in, /*!< new rr for modify or append */ + u_char *buf, /*!< buffer to put query */ + int buflen) /*!< size of buffer */ { - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + if ((_res.options & RES_INIT) == 0U && res_init() == -1) { RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); return (-1); } @@ -175,7 +178,7 @@ res_mkquery(int op, /* opcode of query */ int res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) { - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + if ((_res.options & RES_INIT) == 0U && res_init() == -1) { RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); return (-1); } @@ -184,12 +187,12 @@ res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) { } int -res_query(const char *name, /* domain name */ - int class, int type, /* class and type of query */ - u_char *answer, /* buffer to put answer */ - int anslen) /* size of answer buffer */ +res_query(const char *name, /*!< domain name */ + int class, int type, /*!< class and type of query */ + u_char *answer, /*!< buffer to put answer */ + int anslen) /*!< size of answer buffer */ { - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + if ((_res.options & RES_INIT) == 0U && res_init() == -1) { RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); return (-1); } @@ -213,7 +216,7 @@ res_isourserver(const struct sockaddr_in *inp) { int res_send(const u_char *buf, int buflen, u_char *ans, int anssiz) { - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + if ((_res.options & RES_INIT) == 0U && res_init() == -1) { /* errno should have been set by res_init() in this case. */ return (-1); } @@ -225,7 +228,7 @@ int res_sendsigned(const u_char *buf, int buflen, ns_tsig_key *key, u_char *ans, int anssiz) { - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + if ((_res.options & RES_INIT) == 0U && res_init() == -1) { /* errno should have been set by res_init() in this case. */ return (-1); } @@ -240,7 +243,7 @@ res_close(void) { int res_update(ns_updrec *rrecp_in) { - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + if ((_res.options & RES_INIT) == 0U && res_init() == -1) { RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); return (-1); } @@ -249,12 +252,12 @@ res_update(ns_updrec *rrecp_in) { } int -res_search(const char *name, /* domain name */ - int class, int type, /* class and type of query */ - u_char *answer, /* buffer to put answer */ - int anslen) /* size of answer */ +res_search(const char *name, /*!< domain name */ + int class, int type, /*!< class and type of query */ + u_char *answer, /*!< buffer to put answer */ + int anslen) /*!< size of answer */ { - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + if ((_res.options & RES_INIT) == 0U && res_init() == -1) { RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); return (-1); } @@ -265,11 +268,11 @@ res_search(const char *name, /* domain name */ int res_querydomain(const char *name, const char *domain, - int class, int type, /* class and type of query */ - u_char *answer, /* buffer to put answer */ - int anslen) /* size of answer */ + int class, int type, /*!< class and type of query */ + u_char *answer, /*!< buffer to put answer */ + int anslen) /*!< size of answer */ { - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { + if ((_res.options & RES_INIT) == 0U && res_init() == -1) { RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); return (-1); } @@ -279,6 +282,16 @@ res_querydomain(const char *name, answer, anslen)); } +u_int +res_randomid(void) { + if ((_res.options & RES_INIT) == 0U && res_init() == -1) { + RES_SET_H_ERRNO(&_res, NETDB_INTERNAL); + return (-1); + } + + return (res_nrandomid(&_res)); +} + const char * hostalias(const char *name) { static char abuf[MAXDNAME]; @@ -304,3 +317,5 @@ local_hostname_length(const char *hostname) { #endif /*ultrix*/ #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/resolv/res_debug.c b/usr/src/lib/libresolv2/common/resolv/res_debug.c index 838ed3fd8a..4300ea2722 100644 --- a/usr/src/lib/libresolv2/common/resolv/res_debug.c +++ b/usr/src/lib/libresolv2/common/resolv/res_debug.c @@ -1,12 +1,30 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ + +/* + * Portions Copyright (C) 2004, 2005, 2008, 2009 Internet Systems Consortium, Inc. ("ISC") + * Portions Copyright (C) 1996-2003 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + /* * Copyright (c) 1985 * The Regents of the University of California. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -22,7 +40,7 @@ * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -38,14 +56,14 @@ /* * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * + * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies, and that * the name of Digital Equipment Corporation not be used in advertising or * publicity pertaining to distribution of the document or software without * specific, written prior permission. - * + * * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT @@ -81,28 +99,9 @@ * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. */ -/* - * Portions Copyright (c) 1996-1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: res_debug.c,v 8.50 2003/04/16 04:55:40 marka Exp $"; +static const char rcsid[] = "$Id: res_debug.c,v 1.19 2009/02/26 11:20:20 tbox Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -120,6 +119,7 @@ static const char rcsid[] = "$Id: res_debug.c,v 8.50 2003/04/16 04:55:40 marka E #include <math.h> #include <netdb.h> #include <resolv.h> +#include <resolv_mt.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -136,15 +136,13 @@ static const char rcsid[] = "$Id: res_debug.c,v 8.50 2003/04/16 04:55:40 marka E extern const char *_res_opcodes[]; extern const char *_res_sectioncodes[]; -#ifdef ORIGINAL_ISC_CODE -#else +#ifndef ORIGINAL_ISC_CODE #pragma weak __dn_count_labels = dn_count_labels #pragma weak __fp_resstat = fp_resstat #pragma weak __loc_aton = loc_aton #pragma weak __loc_ntoa = loc_ntoa #pragma weak __p_cdname = p_cdname #pragma weak __p_class = p_class -#pragma weak __p_secstodate = p_secstodate #pragma weak __p_section = p_section #pragma weak __p_time = p_time #pragma weak __p_type = p_type @@ -153,7 +151,7 @@ extern const char *_res_sectioncodes[]; #pragma weak __sym_ston = sym_ston #endif /* ORIGINAL_ISC_CODE */ -/* +/*% * Print the current options. */ void @@ -161,7 +159,7 @@ fp_resstat(const res_state statp, FILE *file) { u_long mask; fprintf(file, ";; res options:"); - for (mask = 1; mask != 0; mask <<= 1) + for (mask = 1; mask != 0U; mask <<= 1) if (statp->options & mask) fprintf(file, " %s", p_option(mask)); putc('\n', file); @@ -212,10 +210,56 @@ do_section(const res_state statp, p_type(ns_rr_type(rr)), p_class(ns_rr_class(rr))); else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) { + u_int16_t optcode, optlen, rdatalen = ns_rr_rdlen(rr); u_int32_t ttl = ns_rr_ttl(rr); + fprintf(file, "; EDNS: version: %u, udp=%u, flags=%04x\n", (ttl>>16)&0xff, ns_rr_class(rr), ttl&0xffff); + + while (rdatalen >= 4) { + const u_char *cp = ns_rr_rdata(rr); + int i; + + GETSHORT(optcode, cp); + GETSHORT(optlen, cp); + + if (optcode == NS_OPT_NSID) { + fputs("; NSID: ", file); + if (optlen == 0) { + fputs("; NSID\n", file); + } else { + fputs("; NSID: ", file); + for (i = 0; i < optlen; i++) + fprintf(file, "%02x ", + cp[i]); + fputs(" (",file); + for (i = 0; i < optlen; i++) + fprintf(file, "%c", + isprint(cp[i])? + cp[i] : '.'); + fputs(")\n", file); + } + } else { + if (optlen == 0) { + fprintf(file, "; OPT=%u\n", + optcode); + } else { + fprintf(file, "; OPT=%u: ", + optcode); + for (i = 0; i < optlen; i++) + fprintf(file, "%02x ", + cp[i]); + fputs(" (",file); + for (i = 0; i < optlen; i++) + fprintf(file, "%c", + isprint(cp[i]) ? + cp[i] : '.'); + fputs(")\n", file); + } + } + rdatalen -= 4 + optlen; + } } else { n = ns_sprintrr(handle, &rr, NULL, NULL, buf, buflen); @@ -227,7 +271,7 @@ do_section(const res_state statp, buf = malloc(buflen += 1024); if (buf == NULL) { fprintf(file, - ";; memory allocation failure\n"); + ";; memory allocation failure\n"); return; } continue; @@ -246,7 +290,7 @@ do_section(const res_state statp, free(buf); } -/* +/*% * Print the contents of a query. * This is intended to be primarily a debugging routine. */ @@ -306,7 +350,7 @@ res_pquery(const res_state statp, const u_char *msg, int len, FILE *file) { fprintf(file, ", %s: %d", p_section(ns_s_ar, opcode), arcount); } - if ((!statp->pfcode) || (statp->pfcode & + if ((!statp->pfcode) || (statp->pfcode & (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) { putc('\n',file); } @@ -341,7 +385,8 @@ p_cdname(const u_char *cp, const u_char *msg, FILE *file) { return (p_cdnname(cp, msg, PACKETSZ, file)); } -/* Return a fully-qualified domain name from a compressed name (with +/*% + * Return a fully-qualified domain name from a compressed name (with length supplied). */ const u_char * @@ -357,7 +402,7 @@ p_fqnname(cp, msg, msglen, name, namelen) return (NULL); newlen = strlen(name); if (newlen == 0 || name[newlen - 1] != '.') { - if (newlen + 1 >= namelen) /* Lack space for final dot */ + if (newlen + 1 >= namelen) /*%< Lack space for final dot */ return (NULL); else strcpy(name + newlen, "."); @@ -379,13 +424,14 @@ p_fqname(const u_char *cp, const u_char *msg, FILE *file) { return (n); } -/* +/*% * Names of RR classes and qclasses. Classes and qclasses are the same, except * that C_ANY is a qclass but not a class. (You can ask for records of class * C_ANY, but you can't have any records of that class in the database.) */ const struct res_sym __p_class_syms[] = { {C_IN, "IN", (char *)0}, + {C_CHAOS, "CH", (char *)0}, {C_CHAOS, "CHAOS", (char *)0}, {C_HS, "HS", (char *)0}, {C_HS, "HESIOD", (char *)0}, @@ -394,7 +440,7 @@ const struct res_sym __p_class_syms[] = { {C_IN, (char *)0, (char *)0} }; -/* +/*% * Names of message sections. */ const struct res_sym __p_default_section_syms[] = { @@ -402,7 +448,7 @@ const struct res_sym __p_default_section_syms[] = { {ns_s_an, "ANSWER", (char *)0}, {ns_s_ns, "AUTHORITY", (char *)0}, {ns_s_ar, "ADDITIONAL", (char *)0}, - {0, (char *)0, (char *)0} + {0, (char *)0, (char *)0} }; const struct res_sym __p_update_section_syms[] = { @@ -410,7 +456,7 @@ const struct res_sym __p_update_section_syms[] = { {S_PREREQ, "PREREQUISITE", (char *)0}, {S_UPDATE, "UPDATE", (char *)0}, {S_ADDT, "ADDITIONAL", (char *)0}, - {0, (char *)0, (char *)0} + {0, (char *)0, (char *)0} }; const struct res_sym __p_key_syms[] = { @@ -431,7 +477,7 @@ const struct res_sym __p_cert_syms[] = { {0, NULL, NULL} }; -/* +/*% * Names of RR types and qtypes. Types and qtypes are the same, except * that T_ANY is a qtype but not a type. (You can ask for records of type * T_ANY, but you can't have any records of that type in the database.) @@ -471,6 +517,24 @@ const struct res_sym __p_type_syms[] = { {ns_t_nimloc, "NIMLOC", "NIMROD locator (unimplemented)"}, {ns_t_srv, "SRV", "server selection"}, {ns_t_atma, "ATMA", "ATM address (unimplemented)"}, + {ns_t_naptr, "NAPTR", "naptr"}, + {ns_t_kx, "KX", "key exchange"}, + {ns_t_cert, "CERT", "certificate"}, + {ns_t_a6, "A", "IPv6 address (experminental)"}, + {ns_t_dname, "DNAME", "non-terminal redirection"}, + {ns_t_opt, "OPT", "opt"}, + {ns_t_apl, "apl", "apl"}, + {ns_t_ds, "DS", "delegation signer"}, + {ns_t_sshfp, "SSFP", "SSH fingerprint"}, + {ns_t_ipseckey, "IPSECKEY", "IPSEC key"}, + {ns_t_rrsig, "RRSIG", "rrsig"}, + {ns_t_nsec, "NSEC", "nsec"}, + {ns_t_dnskey, "DNSKEY", "DNS key"}, + {ns_t_dhcid, "DHCID", "dynamic host configuration identifier"}, + {ns_t_nsec3, "NSEC3", "nsec3"}, + {ns_t_nsec3param, "NSEC3PARAM", "NSEC3 parameters"}, + {ns_t_hip, "HIP", "host identity protocol"}, + {ns_t_spf, "SPF", "sender policy framework"}, {ns_t_tkey, "TKEY", "tkey"}, {ns_t_tsig, "TSIG", "transaction signature"}, {ns_t_ixfr, "IXFR", "incremental zone transfer"}, @@ -486,10 +550,11 @@ const struct res_sym __p_type_syms[] = { {ns_t_sink, "SINK", "Kitchen Sink (experimental)"}, {ns_t_opt, "OPT", "EDNS Options"}, {ns_t_any, "ANY", "\"any\""}, + {ns_t_dlv, "DLV", "DNSSEC look-aside validation"}, {0, NULL, NULL} }; -/* +/*% * Names of DNS rcodes. */ const struct res_sym __p_rcode_syms[] = { @@ -522,16 +587,12 @@ sym_ston(const struct res_sym *syms, const char *name, int *success) { } if (success) *success = 0; - return (syms->number); /* The default value. */ + return (syms->number); /*%< The default value. */ } const char * sym_ntos(const struct res_sym *syms, int number, int *success) { -#ifdef SUNW_MT_RESOLVER - char *unname = sym_ntos_unname; -#else - static char unname[20]; -#endif /* SUNW_MT_RESOLVER */ + char *unname = sym_ntos_unname; for ((void)NULL; syms->name != 0; syms++) { if (number == syms->number) { @@ -541,7 +602,7 @@ sym_ntos(const struct res_sym *syms, int number, int *success) { } } - sprintf(unname, "%d", number); /* XXX nonreentrant */ + sprintf(unname, "%d", number); /*%< XXX nonreentrant */ if (success) *success = 0; return (unname); @@ -549,11 +610,7 @@ sym_ntos(const struct res_sym *syms, int number, int *success) { const char * sym_ntop(const struct res_sym *syms, int number, int *success) { -#ifdef SUNW_MT_RESOLVER - char *unname = sym_ntop_unname; -#else - static char unname[20]; -#endif /* SUNW_MT_RESOLVER */ + char *unname = sym_ntop_unname; for ((void)NULL; syms->name != 0; syms++) { if (number == syms->number) { @@ -562,13 +619,13 @@ sym_ntop(const struct res_sym *syms, int number, int *success) { return (syms->humanname); } } - sprintf(unname, "%d", number); /* XXX nonreentrant */ + sprintf(unname, "%d", number); /*%< XXX nonreentrant */ if (success) *success = 0; return (unname); } -/* +/*% * Return a string for the type. */ const char * @@ -580,13 +637,13 @@ p_type(int type) { result = sym_ntos(__p_type_syms, type, &success); if (success) return (result); - if (type < 0 || type > 0xfff) + if (type < 0 || type > 0xffff) return ("BADTYPE"); sprintf(typebuf, "TYPE%d", type); return (typebuf); } -/* +/*% * Return a string for the type. */ const char * @@ -604,7 +661,7 @@ p_section(int section, int opcode) { return (sym_ntos(symbols, section, (int *)0)); } -/* +/*% * Return a mnemonic for class. */ const char * @@ -616,26 +673,18 @@ p_class(int class) { result = sym_ntos(__p_class_syms, class, &success); if (success) return (result); - if (class < 0 || class > 0xfff) + if (class < 0 || class > 0xffff) return ("BADCLASS"); sprintf(classbuf, "CLASS%d", class); return (classbuf); } -/* +/*% * Return a mnemonic for an option */ const char * -#ifdef ORIGINAL_ISC_CODE p_option(u_long option) { -#else -p_option(u_int option) { -#endif -#ifdef SUNW_MT_RESOLVER - char *nbuf = p_option_nbuf; -#else - static char nbuf[40]; -#endif /* SUNW_MT_RESOLVER */ + char *nbuf = p_option_nbuf; switch (option) { case RES_INIT: return "init"; @@ -652,8 +701,9 @@ p_option(u_int option) { case RES_INSECURE2: return "insecure2"; case RES_NOALIASES: return "noaliases"; case RES_USE_INET6: return "inet6"; -#ifdef RES_USE_EDNS0 /* KAME extension */ +#ifdef RES_USE_EDNS0 /*%< KAME extension */ case RES_USE_EDNS0: return "edns0"; + case RES_NSID: return "nsid"; #endif #ifdef RES_USE_DNAME case RES_USE_DNAME: return "dname"; @@ -664,33 +714,28 @@ p_option(u_int option) { #ifdef RES_NOTLDQUERY case RES_NOTLDQUERY: return "no-tld-query"; #endif -#ifdef ORIGINAL_ISC_CODE +#ifdef RES_NO_NIBBLE2 + case RES_NO_NIBBLE2: return "no-nibble2"; +#endif /* XXX nonreentrant */ default: sprintf(nbuf, "?0x%lx?", (u_long)option); -#else - default: sprintf(nbuf, "?0x%x?", (u_int)option); -#endif return (nbuf); } } -/* +/*% * Return a mnemonic for a time to live. */ const char * p_time(u_int32_t value) { -#ifdef SUNW_MT_RESOLVER - char *nbuf = p_time_nbuf; -#else - static char nbuf[40]; /* XXX nonreentrant */ -#endif /* SUNW_MT_RESOLVER */ + char *nbuf = p_time_nbuf; if (ns_format_ttl(value, nbuf, sizeof nbuf) < 0) sprintf(nbuf, "%u", value); return (nbuf); } -/* +/*% * Return a string for the rcode. */ const char * @@ -698,7 +743,7 @@ p_rcode(int rcode) { return (sym_ntos(__p_rcode_syms, rcode, (int *)0)); } -/* +/*% * Return a string for a res_sockaddr_union. */ const char * @@ -718,14 +763,14 @@ p_sockun(union res_sockaddr_union u, char *buf, size_t size) { sprintf(ret, "[af%d]", u.sin.sin_family); break; } - if (size > 0) { + if (size > 0U) { strncpy(buf, ret, size - 1); buf[size - 1] = '0'; } return (buf); } -/* +/*% * routines to convert between on-the-wire RR format and zone file format. * Does not contain conversion to/from decimal degrees; divide or multiply * by 60*60*1000 for that. @@ -734,16 +779,12 @@ p_sockun(union res_sockaddr_union u, char *buf, size_t size) { static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000, 1000000,10000000,100000000,1000000000}; -/* takes an XeY precision/size value, returns a string representation. */ +/*% takes an XeY precision/size value, returns a string representation. */ static const char * precsize_ntoa(prec) u_int8_t prec; { -#ifdef SUNW_MT_RESOLVER - char *retbuf = precsize_ntoa_retbuf; -#else - static char retbuf[sizeof "90000000.00"]; /* XXX nonreentrant */ -#endif /* SUNW_MT_RESOLVER */ + char *retbuf = precsize_ntoa_retbuf; unsigned long val; int mantissa, exponent; @@ -756,7 +797,7 @@ precsize_ntoa(prec) return (retbuf); } -/* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */ +/*% converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */ static u_int8_t precsize_aton(const char **strptr) { unsigned int mval = 0, cmval = 0; @@ -770,7 +811,7 @@ precsize_aton(const char **strptr) { while (isdigit((unsigned char)*cp)) mval = mval * 10 + (*cp++ - '0'); - if (*cp == '.') { /* centimeters */ + if (*cp == '.') { /*%< centimeters */ cp++; if (isdigit((unsigned char)*cp)) { cmval = (*cp++ - '0') * 10; @@ -796,7 +837,7 @@ precsize_aton(const char **strptr) { return (retval); } -/* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */ +/*% converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */ static u_int32_t latlon2ul(const char **latlonstrptr, int *which) { const char *cp; @@ -826,7 +867,7 @@ latlon2ul(const char **latlonstrptr, int *which) { while (isdigit((unsigned char)*cp)) secs = secs * 10 + (*cp++ - '0'); - if (*cp == '.') { /* decimal seconds */ + if (*cp == '.') { /*%< decimal seconds */ cp++; if (isdigit((unsigned char)*cp)) { secsfrac = (*cp++ - '0') * 100; @@ -839,7 +880,7 @@ latlon2ul(const char **latlonstrptr, int *which) { } } - while (!isspace((unsigned char)*cp)) /* if any trailing garbage */ + while (!isspace((unsigned char)*cp)) /*%< if any trailing garbage */ cp++; while (isspace((unsigned char)*cp)) @@ -860,30 +901,29 @@ latlon2ul(const char **latlonstrptr, int *which) { - secsfrac; break; default: - retval = 0; /* invalid value -- indicates error */ + retval = 0; /*%< invalid value -- indicates error */ break; } switch (*cp) { case 'N': case 'n': case 'S': case 's': - *which = 1; /* latitude */ + *which = 1; /*%< latitude */ break; case 'E': case 'e': case 'W': case 'w': - *which = 2; /* longitude */ + *which = 2; /*%< longitude */ break; default: - *which = 0; /* error */ + *which = 0; /*%< error */ break; } - cp++; /* skip the hemisphere */ - - while (!isspace((unsigned char)*cp)) /* if any trailing garbage */ + cp++; /*%< skip the hemisphere */ + while (!isspace((unsigned char)*cp)) /*%< if any trailing garbage */ cp++; - while (isspace((unsigned char)*cp)) /* move to next field */ + while (isspace((unsigned char)*cp)) /*%< move to next field */ cp++; *latlonstrptr = cp; @@ -891,7 +931,8 @@ latlon2ul(const char **latlonstrptr, int *which) { return (retval); } -/* converts a zone file representation in a string to an RDATA on-the-wire +/*% + * converts a zone file representation in a string to an RDATA on-the-wire * representation. */ int loc_aton(ascii, binary) @@ -904,9 +945,9 @@ loc_aton(ascii, binary) u_int32_t latit = 0, longit = 0, alt = 0; u_int32_t lltemp1 = 0, lltemp2 = 0; int altmeters = 0, altfrac = 0, altsign = 1; - u_int8_t hp = 0x16; /* default = 1e6 cm = 10000.00m = 10km */ - u_int8_t vp = 0x13; /* default = 1e3 cm = 10.00m */ - u_int8_t siz = 0x12; /* default = 1e2 cm = 1.00m */ + u_int8_t hp = 0x16; /*%< default = 1e6 cm = 10000.00m = 10km */ + u_int8_t vp = 0x13; /*%< default = 1e3 cm = 10.00m */ + u_int8_t siz = 0x12; /*%< default = 1e2 cm = 1.00m */ int which1 = 0, which2 = 0; cp = ascii; @@ -917,18 +958,18 @@ loc_aton(ascii, binary) lltemp2 = latlon2ul(&cp, &which2); switch (which1 + which2) { - case 3: /* 1 + 2, the only valid combination */ - if ((which1 == 1) && (which2 == 2)) { /* normal case */ + case 3: /*%< 1 + 2, the only valid combination */ + if ((which1 == 1) && (which2 == 2)) { /*%< normal case */ latit = lltemp1; longit = lltemp2; - } else if ((which1 == 2) && (which2 == 1)) { /* reversed */ + } else if ((which1 == 2) && (which2 == 1)) { /*%< reversed */ longit = lltemp1; latit = lltemp2; - } else { /* some kind of brokenness */ + } else { /*%< some kind of brokenness */ return (0); } break; - default: /* we didn't get one of each */ + default: /*%< we didn't get one of each */ return (0); } @@ -937,14 +978,14 @@ loc_aton(ascii, binary) altsign = -1; cp++; } - + if (*cp == '+') cp++; while (isdigit((unsigned char)*cp)) altmeters = altmeters * 10 + (*cp++ - '0'); - if (*cp == '.') { /* decimal meters */ + if (*cp == '.') { /*%< decimal meters */ cp++; if (isdigit((unsigned char)*cp)) { altfrac = (*cp++ - '0') * 10; @@ -956,7 +997,7 @@ loc_aton(ascii, binary) alt = (10000000 + (altsign * (altmeters * 100 + altfrac))); - while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */ + while (!isspace((unsigned char)*cp) && (cp < maxcp)) /*%< if trailing garbage or m */ cp++; while (isspace((unsigned char)*cp) && (cp < maxcp)) @@ -966,8 +1007,8 @@ loc_aton(ascii, binary) goto defaults; siz = precsize_aton(&cp); - - while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */ + + while (!isspace((unsigned char)*cp) && (cp < maxcp)) /*%< if trailing garbage or m */ cp++; while (isspace((unsigned char)*cp) && (cp < maxcp)) @@ -978,7 +1019,7 @@ loc_aton(ascii, binary) hp = precsize_aton(&cp); - while (!isspace((unsigned char)*cp) && (cp < maxcp)) /* if trailing garbage or m */ + while (!isspace((unsigned char)*cp) && (cp < maxcp)) /*%< if trailing garbage or m */ cp++; while (isspace((unsigned char)*cp) && (cp < maxcp)) @@ -992,30 +1033,26 @@ loc_aton(ascii, binary) defaults: bcp = binary; - *bcp++ = (u_int8_t) 0; /* version byte */ + *bcp++ = (u_int8_t) 0; /*%< version byte */ *bcp++ = siz; *bcp++ = hp; *bcp++ = vp; PUTLONG(latit,bcp); PUTLONG(longit,bcp); PUTLONG(alt,bcp); - - return (16); /* size of RR in octets */ + + return (16); /*%< size of RR in octets */ } -/* takes an on-the-wire LOC RR and formats it in a human readable format. */ +/*% takes an on-the-wire LOC RR and formats it in a human readable format. */ const char * loc_ntoa(binary, ascii) const u_char *binary; char *ascii; { static const char *error = "?"; -#ifdef SUNW_MT_RESOLVER - char *tmpbuf = loc_ntoa_tmpbuf; -#else static char tmpbuf[sizeof "1000 60 60.000 N 1000 60 60.000 W -12345678.00m 90000000.00m 90000000.00m 90000000.00m"]; -#endif /* SUNW_MT_RESOLVER */ const u_char *cp = binary; int latdeg, latmin, latsec, latsecfrac; @@ -1029,7 +1066,7 @@ loc_ntoa(binary, ascii) int32_t latval, longval, altval; u_int32_t templ; u_int8_t sizeval, hpval, vpval, versionval; - + char *sizestr, *hpstr, *vpstr; versionval = *cp++; @@ -1054,7 +1091,7 @@ loc_ntoa(binary, ascii) longval = (templ - ((unsigned)1<<31)); GETLONG(templ, cp); - if (templ < referencealt) { /* below WGS 84 spheroid */ + if (templ < referencealt) { /*%< below WGS 84 spheroid */ altval = referencealt - templ; altsign = "-"; } else { @@ -1117,7 +1154,7 @@ loc_ntoa(binary, ascii) } -/* Return the number of DNS hierarchy levels in the name. */ +/*% Return the number of DNS hierarchy levels in the name. */ int dn_count_labels(const char *name) { int i, len, count; @@ -1142,28 +1179,19 @@ dn_count_labels(const char *name) { return (count); } - -/* - * Make dates expressed in seconds-since-Jan-1-1970 easy to read. +/*% + * Make dates expressed in seconds-since-Jan-1-1970 easy to read. * SIG records are required to be printed like this, by the Secure DNS RFC. */ char * -#ifdef ORIGINAL_ISC_CODE p_secstodate (u_long secs) { -#else -p_secstodate (u_int secs) { -#endif -#ifdef SUNW_MT_RESOLVER - char *output = p_secstodate_output; -#else - /* XXX nonreentrant */ - static char output[15]; /* YYYYMMDDHHMMSS and null */ -#endif /* SUNW_MT_RESOLVER */ + char *output = p_secstodate_output; time_t clock = secs; struct tm *time; - #ifdef HAVE_TIME_R - gmtime_r(&clock, &time); + struct tm res; + + time = gmtime_r(&clock, &res); #else time = gmtime(&clock); #endif @@ -1190,7 +1218,7 @@ res_nametoclass(const char *buf, int *successp) { goto done; errno = 0; result = strtoul(buf + 5, &endptr, 10); - if (errno == 0 && *endptr == '\0' && result <= 0xffff) + if (errno == 0 && *endptr == '\0' && result <= 0xffffU) success = 1; done: if (successp) @@ -1213,10 +1241,12 @@ res_nametotype(const char *buf, int *successp) { goto done; errno = 0; result = strtoul(buf + 4, &endptr, 10); - if (errno == 0 && *endptr == '\0' && result <= 0xffff) + if (errno == 0 && *endptr == '\0' && result <= 0xffffU) success = 1; done: if (successp) *successp = success; return (result); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/resolv/res_debug.h b/usr/src/lib/libresolv2/common/resolv/res_debug.h index 1395d7a207..c28171d7c8 100644 --- a/usr/src/lib/libresolv2/common/resolv/res_debug.h +++ b/usr/src/lib/libresolv2/common/resolv/res_debug.h @@ -1,30 +1,23 @@ /* - * Copyright (c) 2001 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef _RES_DEBUG_H_ #define _RES_DEBUG_H_ -#pragma ident "%Z%%M% %I% %E% SMI" - #ifndef DEBUG # define Dprint(cond, args) /*empty*/ # define DprintQ(cond, args, query, size) /*empty*/ @@ -39,3 +32,4 @@ #endif #endif /* _RES_DEBUG_H_ */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/resolv/res_findzonecut.c b/usr/src/lib/libresolv2/common/resolv/res_findzonecut.c index 65be96235b..933169e3ab 100644 --- a/usr/src/lib/libresolv2/common/resolv/res_findzonecut.c +++ b/usr/src/lib/libresolv2/common/resolv/res_findzonecut.c @@ -1,29 +1,22 @@ -/* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: res_findzonecut.c,v 8.20 2003/05/27 23:36:53 marka Exp $"; +static const char rcsid[] = "$Id: res_findzonecut.c,v 1.10 2005/10/11 00:10:16 marka Exp $"; #endif /* not lint */ /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* Import. */ @@ -97,61 +90,62 @@ static void res_dprintf(const char *, ...) ISC_FORMAT_PRINTF(1, 2); #define DPRINTF(x) do {\ int save_errno = errno; \ - if ((statp->options & RES_DEBUG) != 0) res_dprintf x; \ + if ((statp->options & RES_DEBUG) != 0U) res_dprintf x; \ errno = save_errno; \ } while (0) /* Public. */ -/* - * int - * res_findzonecut(res, dname, class, zname, zsize, addrs, naddrs) +/*% * find enclosing zone for a <dname,class>, and some server addresses + * * parameters: - * res - resolver context to work within (is modified) - * dname - domain name whose enclosing zone is desired - * class - class of dname (and its enclosing zone) - * zname - found zone name - * zsize - allocated size of zname - * addrs - found server addresses - * naddrs - max number of addrs + *\li res - resolver context to work within (is modified) + *\li dname - domain name whose enclosing zone is desired + *\li class - class of dname (and its enclosing zone) + *\li zname - found zone name + *\li zsize - allocated size of zname + *\li addrs - found server addresses + *\li naddrs - max number of addrs + * * return values: - * < 0 - an error occurred (check errno) - * = 0 - zname is now valid, but addrs[] wasn't changed - * > 0 - zname is now valid, and return value is number of addrs[] found + *\li < 0 - an error occurred (check errno) + *\li = 0 - zname is now valid, but addrs[] wasn't changed + *\li > 0 - zname is now valid, and return value is number of addrs[] found + * * notes: - * this function calls res_nsend() which means it depends on correctly + *\li this function calls res_nsend() which means it depends on correctly * functioning recursive nameservers (usually defined in /etc/resolv.conf * or its local equivilent). * - * we start by asking for an SOA<dname,class>. if we get one as an + *\li we start by asking for an SOA<dname,class>. if we get one as an * answer, that just means <dname,class> is a zone top, which is fine. * more than likely we'll be told to go pound sand, in the form of a * negative answer. * - * note that we are not prepared to deal with referrals since that would + *\li note that we are not prepared to deal with referrals since that would * only come from authority servers and our correctly functioning local * recursive server would have followed the referral and got us something * more definite. * - * if the authority section contains an SOA, this SOA should also be the + *\li if the authority section contains an SOA, this SOA should also be the * closest enclosing zone, since any intermediary zone cuts would've been * returned as referrals and dealt with by our correctly functioning local * recursive name server. but an SOA in the authority section should NOT * match our dname (since that would have been returned in the answer * section). an authority section SOA has to be "above" our dname. * - * however, since authority section SOA's were once optional, it's + *\li however, since authority section SOA's were once optional, it's * possible that we'll have to go hunting for the enclosing SOA by * ripping labels off the front of our dname -- this is known as "doing * it the hard way." * - * ultimately we want some server addresses, which are ideally the ones + *\li ultimately we want some server addresses, which are ideally the ones * pertaining to the SOA.MNAME, but only if there is a matching NS RR. * so the second phase (after we find an SOA) is to go looking for the * NS RRset for that SOA's zone. * - * no answer section processed by this code is allowed to contain CNAME + *\li no answer section processed by this code is allowed to contain CNAME * or DNAME RR's. for the SOA query this means we strip a label and * keep going. for the NS and A queries this means we just give up. */ @@ -326,7 +320,6 @@ get_soa(res_state statp, const char *dname, ns_class class, int opts, for (i = 0; i < n; i++) { const char *t; const u_char *rdata; - int rdlen; ns_rr rr; if (ns_parserr(&msg, sect, i, &rr) < 0) { @@ -367,14 +360,14 @@ get_soa(res_state statp, const char *dname, ns_class class, int opts, abort(); } if (strlen(t) + 1 > zsize) { - DPRINTF(("get_soa: zname(%d) too small (%d)", - zsize, strlen(t) + 1)); + DPRINTF(("get_soa: zname(%lu) too small (%lu)", + (unsigned long)zsize, + (unsigned long)strlen(t) + 1)); errno = EMSGSIZE; goto cleanup; } strcpy(zname, t); rdata = ns_rr_rdata(rr); - rdlen = ns_rr_rdlen(rr); if (ns_name_uncompress(resp, ns_msg_end(msg), rdata, mname, msize) < 0) { DPRINTF(("get_soa: ns_name_uncompress failed") @@ -532,7 +525,6 @@ save_ns(res_state statp, ns_msg *msg, ns_sect sect, const u_char *rdata; rr_ns *nsrr; ns_rr rr; - int rdlen; if (ns_parserr(msg, sect, i, &rr) < 0) { DPRINTF(("save_ns: ns_parserr(%s, %d) failed", @@ -551,7 +543,6 @@ save_ns(res_state statp, ns_msg *msg, ns_sect sect, return (-1); } rdata = ns_rr_rdata(rr); - rdlen = ns_rr_rdlen(rr); if (ns_name_uncompress(ns_msg_base(*msg), ns_msg_end(*msg), rdata, tname, sizeof tname) < 0) { @@ -727,3 +718,5 @@ res_dprintf(const char *fmt, ...) { fputc('\n', stderr); va_end(ap); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/resolv/res_init.c b/usr/src/lib/libresolv2/common/resolv/res_init.c index 33ccc9ece7..e839323a79 100644 --- a/usr/src/lib/libresolv2/common/resolv/res_init.c +++ b/usr/src/lib/libresolv2/common/resolv/res_init.c @@ -1,8 +1,9 @@ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ + /* * Copyright (c) 1985, 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -57,27 +58,25 @@ */ /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Portions Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; -static const char rcsid[] = "$Id: res_init.c,v 8.32 2003/04/03 06:31:10 marka Exp $"; +static const char rcsid[] = "$Id: res_init.c,v 1.26 2008/12/11 09:59:00 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -98,14 +97,30 @@ static const char rcsid[] = "$Id: res_init.c,v 8.32 2003/04/03 06:31:10 marka Ex #include <unistd.h> #include <netdb.h> +#ifndef HAVE_MD5 +# include "../dst/md5.h" +#else +# ifdef SOLARIS2 +# include <sys/md5.h> +# endif +#endif +#ifndef _MD5_H_ +# define _MD5_H_ 1 /*%< make sure we do not include rsaref md5.h file */ +#endif + + #include "port_after.h" /* ensure that sockaddr_in6 and IN6ADDR_ANY_INIT are declared / defined */ #include <resolv.h> +/* ISC purposely put port_after.h before <resolv.h> to force in6 stuff + * (above) so we explicitly include port_resolv.h here */ +#include "port_resolv.h" + #include "res_private.h" -/* Options. Should all be left alone. */ +/*% Options. Should all be left alone. */ #define RESOLVSORT #define DEBUG @@ -116,15 +131,9 @@ static const char rcsid[] = "$Id: res_init.c,v 8.32 2003/04/03 06:31:10 marka Ex #define MAXIFS 8192 #endif /* SUNW_INITCHKIF */ -#ifdef SUNW_DOMAINFROMNIS +#ifdef SOLARIS2 #include <sys/systeminfo.h> -#include <string.h> -#endif /* SUNW_DOMAINFROMNIS */ - -#ifdef ORIGINAL_ISC_CODE -#else -#pragma weak __res_randomid = res_randomid -#endif /* ORIGINAL_ISC_CODE */ +#endif static void res_setoptions __P((res_state, const char *, const char *)); @@ -134,7 +143,7 @@ static const char sort_mask[] = "/&"; static u_int32_t net_mask __P((struct in_addr)); #endif -#if !defined(isascii) /* XXX - could be a function */ +#if !defined(isascii) /*%< XXX - could be a function */ # define isascii(c) (!(c & 0200)) #endif @@ -142,7 +151,7 @@ static u_int32_t net_mask __P((struct in_addr)); * Resolver state default settings. */ -/* +/*% * Set up default settings. If the configuration file exist, the values * there will have precedence. Otherwise, the server address is set to * INADDR_ANY and the default domain name comes from the gethostname(). @@ -166,18 +175,17 @@ static u_int32_t net_mask __P((struct in_addr)); int res_ninit(res_state statp) { extern int __res_vinit(res_state, int); - return (__res_vinit(statp, 0)); } -/* This function has to be reachable by res_data.c but not publically. */ +/*% This function has to be reachable by res_data.c but not publically. */ int __res_vinit(res_state statp, int preinit) { register FILE *fp; register char *cp, **pp; register int n; char buf[BUFSIZ]; - int nserv = 0; /* number of nameserver records read from file */ + int nserv = 0; /*%< number of nameserver records read from file */ int haveenv = 0; int havesearch = 0; #ifdef RESOLVSORT @@ -186,7 +194,9 @@ __res_vinit(res_state statp, int preinit) { #endif int dots; union res_sockaddr_union u[2]; + int maxns = MAXNS; + RES_SET_H_ERRNO(statp, 0); if (statp->_u._ext.ext != NULL) res_ndestroy(statp); @@ -194,7 +204,8 @@ __res_vinit(res_state statp, int preinit) { statp->retrans = RES_TIMEOUT; statp->retry = RES_DFLRETRY; statp->options = RES_DEFAULT; - statp->id = res_randomid(); + res_rndinit(statp); + statp->id = res_nrandomid(statp); } memset(u, 0, sizeof(u)); @@ -236,8 +247,22 @@ __res_vinit(res_state statp, int preinit) { statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr; strcpy(statp->_u._ext.ext->nsuffix, "ip6.arpa"); strcpy(statp->_u._ext.ext->nsuffix2, "ip6.int"); - } else - return (-1); + } else { + /* + * Historically res_init() rarely, if at all, failed. + * Examples and applications exist which do not check + * our return code. Furthermore several applications + * simply call us to get the systems domainname. So + * rather then immediately fail here we store the + * failure, which is returned later, in h_errno. And + * prevent the collection of 'nameserver' information + * by setting maxns to 0. Thus applications that fail + * to check our return code wont be able to make + * queries anyhow. + */ + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); + maxns = 0; + } #ifdef RESOLVSORT statp->nsort = 0; #endif @@ -328,25 +353,27 @@ __res_vinit(res_state statp, int preinit) { } #endif /* SUNW_INITCHKIF */ -#ifdef SUNW_DOMAINFROMNIS -/* - * The old (4.8.3) libresolv derived the default domainname from NIS/NIS+. - */ - { - char buf[sizeof(statp->defdname)], *cp; - int ret; - if ((ret = sysinfo(SI_SRPC_DOMAIN, buf, sizeof(buf))) > 0 && - ret <= sizeof(buf)) { - if (buf[0] == '+') - buf[0] = '.'; - cp = strchr(buf, '.'); - if (cp == 0) - strcpy(statp->defdname, buf); - else - strcpy(statp->defdname, cp+1); - } - } -#endif /* SUNW_DOMAINFROMNIS */ +#ifdef SOLARIS2 + /* + * The old libresolv derived the defaultdomain from NIS/NIS+. + * We want to keep this behaviour + */ + { + char buf[sizeof(statp->defdname)], *cp; + int ret; + + if ((ret = sysinfo(SI_SRPC_DOMAIN, buf, sizeof(buf))) > 0 && + (unsigned int)ret <= sizeof(buf)) { + if (buf[0] == '+') + buf[0] = '.'; + cp = strchr(buf, '.'); + cp = (cp == NULL) ? buf : (cp + 1); + strncpy(statp->defdname, cp, + sizeof(statp->defdname) - 1); + statp->defdname[sizeof(statp->defdname) - 1] = '\0'; + } + } +#endif /* SOLARIS2 */ /* Allow user to override the local domain definition */ if ((cp = getenv("LOCALDOMAIN")) != NULL) { @@ -365,7 +392,7 @@ __res_vinit(res_state statp, int preinit) { pp = statp->dnsrch; *pp++ = cp; for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) { - if (*cp == '\n') /* silly backwards compat */ + if (*cp == '\n') /*%< silly backwards compat */ break; else if (*cp == ' ' || *cp == '\t') { *cp = 0; @@ -389,12 +416,7 @@ __res_vinit(res_state statp, int preinit) { line[sizeof(name) - 1] == '\t')) nserv = 0; - -#ifdef SUNW_AVOIDSTDIO_FDLIMIT - if ((fp = fopen(_PATH_RESCONF, "rF")) != NULL) { -#else if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) { -#endif /* read the config file */ while (fgets(buf, sizeof(buf), fp) != NULL) { /* skip comments */ @@ -402,7 +424,7 @@ __res_vinit(res_state statp, int preinit) { continue; /* read default domain name */ if (MATCH(buf, "domain")) { - if (haveenv) /* skip if have from environ */ + if (haveenv) /*%< skip if have from environ */ continue; cp = buf + sizeof("domain") - 1; while (*cp == ' ' || *cp == '\t') @@ -418,7 +440,7 @@ __res_vinit(res_state statp, int preinit) { } /* set search list */ if (MATCH(buf, "search")) { - if (haveenv) /* skip if have from environ */ + if (haveenv) /*%< skip if have from environ */ continue; cp = buf + sizeof("search") - 1; while (*cp == ' ' || *cp == '\t') @@ -454,7 +476,7 @@ __res_vinit(res_state statp, int preinit) { continue; } /* read nameservers to query */ - if (MATCH(buf, "nameserver") && nserv < MAXNS) { + if (MATCH(buf, "nameserver") && nserv < maxns) { struct addrinfo hints, *ai; char sbuf[NI_MAXSERV]; const size_t minsiz = @@ -542,7 +564,7 @@ __res_vinit(res_state statp, int preinit) { #ifdef RESOLVSORT statp->nsort = nsort; #endif - (void) fclose(fp); + (void) fclose(fp); } /* * Last chance to get a nameserver. This should not normally @@ -572,7 +594,7 @@ __res_vinit(res_state statp, int preinit) { while (pp < statp->dnsrch + MAXDFLSRCH) { if (dots < LOCALDOMAINPARTS) break; - cp = strchr(cp, '.') + 1; /* we know there is one */ + cp = strchr(cp, '.') + 1; /*%< we know there is one */ *pp++ = cp; dots--; } @@ -590,7 +612,7 @@ __res_vinit(res_state statp, int preinit) { if ((cp = getenv("RES_OPTIONS")) != NULL) res_setoptions(statp, cp, "env"); statp->options |= RES_INIT; - return (0); + return (statp->res_h_errno); #ifdef SUNW_INITCHKIF freedata: if (statp->_u._ext.ext != NULL) { @@ -599,6 +621,7 @@ freedata: } return (-1); #endif /* SUNW_INITCHKIF */ + } static void @@ -634,20 +657,17 @@ res_setoptions(res_state statp, const char *options, const char *source) statp->retrans = i; else statp->retrans = RES_MAXRETRANS; - } else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){ - i = atoi(cp + sizeof("attempts:") - 1); - if (i <= RES_MAXRETRY) - statp->retry = i; - else - statp->retry = RES_MAXRETRY; -#ifdef ORIGINAL_ISC_CODE -#else +#ifdef DEBUG + if (statp->options & RES_DEBUG) + printf(";;\ttimeout=%d\n", statp->retrans); +#endif +#ifdef SOLARIS2 } else if (!strncmp(cp, "retrans:", sizeof("retrans:") - 1)) { /* - * For backward compatibility, 'retrans' is - * supported as an alias for 'timeout', though - * without an imposed maximum. - */ + * For backward compatibility, 'retrans' is + * supported as an alias for 'timeout', though + * without an imposed maximum. + */ statp->retrans = atoi(cp + sizeof("retrans:") - 1); } else if (!strncmp(cp, "retry:", sizeof("retry:") - 1)){ /* @@ -656,7 +676,17 @@ res_setoptions(res_state statp, const char *options, const char *source) * without an imposed maximum. */ statp->retry = atoi(cp + sizeof("retry:") - 1); -#endif /* ORIGINAL_ISC_CODE */ +#endif /* SOLARIS2 */ + } else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){ + i = atoi(cp + sizeof("attempts:") - 1); + if (i <= RES_MAXRETRY) + statp->retry = i; + else + statp->retry = RES_MAXRETRY; +#ifdef DEBUG + if (statp->options & RES_DEBUG) + printf(";;\tattempts=%d\n", statp->retry); +#endif } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) { #ifdef DEBUG if (!(statp->options & RES_DEBUG)) { @@ -726,7 +756,7 @@ res_setoptions(res_state statp, const char *options, const char *source) #ifdef RESOLVSORT /* XXX - should really support CIDR which means explicit masks always. */ static u_int32_t -net_mask(in) /* XXX - should really use system's version of this */ +net_mask(in) /*!< XXX - should really use system's version of this */ struct in_addr in; { register u_int32_t i = ntohl(in.s_addr); @@ -739,15 +769,49 @@ net_mask(in) /* XXX - should really use system's version of this */ } #endif +void +res_rndinit(res_state statp) +{ + struct timeval now; + u_int32_t u32; + u_int16_t u16; + + gettimeofday(&now, NULL); + u32 = now.tv_sec; + memcpy(statp->_u._ext._rnd, &u32, 4); + u32 = now.tv_usec; + memcpy(statp->_u._ext._rnd + 4, &u32, 4); + u32 += now.tv_sec; + memcpy(statp->_u._ext._rnd + 8, &u32, 4); + u16 = getpid(); + memcpy(statp->_u._ext._rnd + 12, &u16, 2); + +} + u_int -res_randomid(void) { +res_nrandomid(res_state statp) { struct timeval now; + u_int16_t u16; + MD5_CTX ctx; gettimeofday(&now, NULL); - return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid())); + u16 = (u_int16_t) (now.tv_sec ^ now.tv_usec); + + memcpy(statp->_u._ext._rnd + 14, &u16, 2); +#ifndef HAVE_MD5 + MD5_Init(&ctx); + MD5_Update(&ctx, statp->_u._ext._rnd, 16); + MD5_Final(statp->_u._ext._rnd, &ctx); +#else + MD5Init(&ctx); + MD5Update(&ctx, statp->_u._ext._rnd, 16); + MD5Final(statp->_u._ext._rnd, &ctx); +#endif + memcpy(&u16, statp->_u._ext._rnd + 14, 2); + return ((u_int) u16); } -/* +/*% * This routine is for closing the socket if a virtual circuit is used and * the program wants to close it. This provides support for endhostent() * which expects to close the socket. @@ -890,3 +954,5 @@ res_getservers(res_state statp, union res_sockaddr_union *set, int cnt) { } return (statp->nscount); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/resolv/res_mkquery.c b/usr/src/lib/libresolv2/common/resolv/res_mkquery.c index c81e9eba32..acc538a055 100644 --- a/usr/src/lib/libresolv2/common/resolv/res_mkquery.c +++ b/usr/src/lib/libresolv2/common/resolv/res_mkquery.c @@ -1,12 +1,30 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ + +/* + * Portions Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") + * Portions Copyright (C) 1996, 1997, 1988, 1999, 2001, 2003 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + /* * Copyright (c) 1985, 1993 * The Regents of the University of California. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -22,7 +40,7 @@ * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -38,14 +56,14 @@ /* * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * + * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies, and that * the name of Digital Equipment Corporation not be used in advertising or * publicity pertaining to distribution of the document or software without * specific, written prior permission. - * + * * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT @@ -56,28 +74,9 @@ * SOFTWARE. */ -/* - * Portions Copyright (c) 1996-1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: res_mkquery.c,v 8.16 2003/04/29 02:13:08 marka Exp $"; +static const char rcsid[] = "$Id: res_mkquery.c,v 1.10 2008/12/11 09:59:00 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -90,7 +89,8 @@ static const char rcsid[] = "$Id: res_mkquery.c,v 8.16 2003/04/29 02:13:08 marka #include <sys/socket.h> #include <errno.h> #include <sys/stat.h> -#endif +#endif /* SUNW_CONFCHECK */ + #include <netdb.h> #include <resolv.h> @@ -105,22 +105,23 @@ extern const char *_res_opcodes[]; #ifdef SUNW_CONFCHECK static int _confcheck(res_state statp); -#endif +#endif /* SUNW_CONFCHECK */ -/* + +/*% * Form all types of queries. * Returns the size of the result or -1. */ int res_nmkquery(res_state statp, - int op, /* opcode of query */ - const char *dname, /* domain name */ - int class, int type, /* class and type of query */ - const u_char *data, /* resource record data */ - int datalen, /* length of data */ - const u_char *newrr_in, /* new rr for modify or append */ - u_char *buf, /* buffer to put query */ - int buflen) /* size of buffer */ + int op, /*!< opcode of query */ + const char *dname, /*!< domain name */ + int class, int type, /*!< class and type of query */ + const u_char *data, /*!< resource record data */ + int datalen, /*!< length of data */ + const u_char *newrr_in, /*!< new rr for modify or append */ + u_char *buf, /*!< buffer to put query */ + int buflen) /*!< size of buffer */ { register HEADER *hp; register u_char *cp, *ep; @@ -144,8 +145,8 @@ res_nmkquery(res_state statp, RES_SET_H_ERRNO(statp, NO_RECOVERY); return(-1); } -#endif - +#endif /* SUNW_CONFCHECK */ + /* * Initialize header fields. */ @@ -153,9 +154,10 @@ res_nmkquery(res_state statp, return (-1); memset(buf, 0, HFIXEDSZ); hp = (HEADER *) buf; - hp->id = htons(++statp->id); + statp->id = res_nrandomid(statp); + hp->id = htons(statp->id); hp->opcode = op; - hp->rd = (statp->options & RES_RECURSE) != 0; + hp->rd = (statp->options & RES_RECURSE) != 0U; hp->rcode = NOERROR; cp = buf + HFIXEDSZ; ep = buf + buflen; @@ -209,7 +211,7 @@ res_nmkquery(res_state statp, */ if (ep - cp < 1 + RRFIXEDSZ + datalen) return (-1); - *cp++ = '\0'; /* no domain name */ + *cp++ = '\0'; /*%< no domain name */ ns_put16(type, cp); cp += INT16SZ; ns_put16(class, cp); @@ -233,27 +235,20 @@ res_nmkquery(res_state statp, #ifdef RES_USE_EDNS0 /* attach OPT pseudo-RR, as documented in RFC2671 (EDNS0). */ -#ifndef T_OPT -#define T_OPT 41 -#endif int res_nopt(res_state statp, - int n0, /* current offset in buffer */ -#ifdef ORIGINAL_ISC_CODE - u_char *buf, /* buffer to put query */ -#else - uchar_t *buf, /* buffer to put query */ -#endif - int buflen, /* size of buffer */ - int anslen) /* UDP answer buffer size */ + int n0, /*%< current offset in buffer */ + u_char *buf, /*%< buffer to put query */ + int buflen, /*%< size of buffer */ + int anslen) /*%< UDP answer buffer size */ { register HEADER *hp; register u_char *cp, *ep; u_int16_t flags = 0; #ifdef DEBUG - if ((statp->options & RES_DEBUG) != 0) + if ((statp->options & RES_DEBUG) != 0U) printf(";; res_nopt()\n"); #endif @@ -264,14 +259,14 @@ res_nopt(res_state statp, if ((ep - cp) < 1 + RRFIXEDSZ) return (-1); - *cp++ = 0; /* "." */ - - ns_put16(T_OPT, cp); /* TYPE */ + *cp++ = 0; /*%< "." */ + ns_put16(ns_t_opt, cp); /*%< TYPE */ cp += INT16SZ; - ns_put16(anslen & 0xffff, cp); /* CLASS = UDP payload size */ + ns_put16(anslen & 0xffff, cp); /*%< CLASS = UDP payload size */ cp += INT16SZ; - *cp++ = NOERROR; /* extended RCODE */ - *cp++ = 0; /* EDNS version */ + *cp++ = NOERROR; /*%< extended RCODE */ + *cp++ = 0; /*%< EDNS version */ + if (statp->options & RES_USE_DNSSEC) { #ifdef DEBUG if (statp->options & RES_DEBUG) @@ -281,44 +276,74 @@ res_nopt(res_state statp, } ns_put16(flags, cp); cp += INT16SZ; - ns_put16(0, cp); /* RDLEN */ + + ns_put16(0U, cp); /*%< RDLEN */ cp += INT16SZ; + hp->arcount = htons(ntohs(hp->arcount) + 1); return (cp - buf); } -#endif -#ifdef SUNW_CONFCHECK /* - * Kludge to time out quickly if there is no /etc/resolv.conf - * and a TCP connection to the local DNS server fails. - * - * Moved function from res_send.c to res_mkquery.c. This - * solves a long timeout problem with nslookup. - * - * __areweinnamed is needed because there is a possibility that the - * user might do bad things to resolv.conf and cause in.named to call - * _confcheck and deadlock the server. + * Construct variable data (RDATA) block for OPT psuedo-RR, append it + * to the buffer, then update the RDLEN field (previously set to zero by + * res_nopt()) with the new RDATA length. */ - -#ifdef SUNW_AREWEINNAMED -int __areweinnamed() +int +res_nopt_rdata(res_state statp, + int n0, /*%< current offset in buffer */ + u_char *buf, /*%< buffer to put query */ + int buflen, /*%< size of buffer */ + u_char *rdata, /*%< ptr to start of opt rdata */ + u_short code, /*%< OPTION-CODE */ + u_short len, /*%< OPTION-LENGTH */ + u_char *data) /*%< OPTION_DATA */ { - return (0); + register u_char *cp, *ep; + +#ifdef DEBUG + if ((statp->options & RES_DEBUG) != 0U) + printf(";; res_nopt_rdata()\n"); +#endif + + cp = buf + n0; + ep = buf + buflen; + + if ((ep - cp) < (4 + len)) + return (-1); + + if (rdata < (buf + 2) || rdata >= ep) + return (-1); + + ns_put16(code, cp); + cp += INT16SZ; + + ns_put16(len, cp); + cp += INT16SZ; + + memcpy(cp, data, len); + cp += len; + + len = cp - rdata; + ns_put16(len, rdata - 2); /* Update RDLEN field */ + + return (cp - buf); } -#endif /* SUNW_AREWEINNAMED */ +#endif +#ifdef SUNW_CONFCHECK + +/* + * Time out quickly if there is no /etc/resolv.conf and a TCP connection + * to the local DNS server fails. + */ static int _confcheck(res_state statp) { int ns; struct stat rc_stat; struct sockaddr_in ns_sin; - - if (__areweinnamed()) - return (0); - /* First, we check to see if /etc/resolv.conf exists. * If it doesn't, then it is likely that the localhost is * the nameserver. @@ -356,4 +381,6 @@ static int _confcheck(res_state statp) return (0); } -#endif +#endif /* SUNW_CONFCHECK */ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/resolv/res_mkupdate.c b/usr/src/lib/libresolv2/common/resolv/res_mkupdate.c index d66f0b91ed..2eb6757a0e 100644 --- a/usr/src/lib/libresolv2/common/resolv/res_mkupdate.c +++ b/usr/src/lib/libresolv2/common/resolv/res_mkupdate.c @@ -1,34 +1,28 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - -/* +/*! \file + * \brief * Based on the Dynamic DNS reference implementation by Viraj Bais - * <viraj_bais@ccm.fm.intel.com> + * <viraj_bais@ccm.fm.intel.com> */ #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: res_mkupdate.c,v 1.30 2003/08/14 07:54:50 marka Exp $"; +static const char rcsid[] = "$Id: res_mkupdate.c,v 1.10 2008/12/11 09:59:00 marka Exp $"; #endif /* not lint */ #include "port_before.h" @@ -69,23 +63,25 @@ static int getstr_str(char *, int, u_char **, u_char *); int res_protocolnumber(const char *); int res_servicenumber(const char *); -/* +/*% * Form update packets. * Returns the size of the resulting packet if no error + * * On error, - * returns -1 if error in reading a word/number in rdata + * returns + *\li -1 if error in reading a word/number in rdata * portion for update packets - * -2 if length of buffer passed is insufficient - * -3 if zone section is not the first section in + *\li -2 if length of buffer passed is insufficient + *\li -3 if zone section is not the first section in * the linked list, or section order has a problem - * -4 on a number overflow - * -5 unknown operation or no records + *\li -4 on a number overflow + *\li -5 unknown operation or no records */ int res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) { ns_updrec *rrecp_start = rrecp_in; HEADER *hp; - u_char *cp, *sp1, *sp2, *startp, *endp; + u_char *cp, *sp2, *startp, *endp; int n, i, soanum, multiline; ns_updrec *rrecp; struct in_addr ina; @@ -105,10 +101,10 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) { return (-1); memset(buf, 0, HFIXEDSZ); hp = (HEADER *) buf; - hp->id = htons(++statp->id); + statp->id = res_nrandomid(statp); + hp->id = htons(statp->id); hp->opcode = ns_o_update; hp->rcode = NOERROR; - sp1 = buf + 2*INT16SZ; /* save pointer to zocount */ cp = buf + HFIXEDSZ; buflen -= HFIXEDSZ; dpp = dnptrs; @@ -197,7 +193,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) { } ShrinkBuffer(INT32SZ + INT16SZ); PUTLONG(rttl, cp); - sp2 = cp; /* save pointer to length byte */ + sp2 = cp; /*%< save pointer to length byte */ cp += INT16SZ; if (rrecp->r_size == 0) { if (section == S_UPDATE && rclass != C_ANY) @@ -226,6 +222,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) { case T_MR: case T_NS: case T_PTR: + case ns_t_dname: if (!getword_str(buf2, sizeof buf2, &startp, endp)) return (-1); n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr); @@ -356,13 +353,13 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) { bm[i] = 0; while (getword_str(buf2, sizeof buf2, &startp, endp)) { - if ((n1 = res_servicenumber(buf2)) <= 0) + if ((n = res_servicenumber(buf2)) <= 0) return (-1); - if (n1 < MAXPORT) { - bm[n1/8] |= (0x80>>(n1%8)); - if (n1 > maxbm) - maxbm = n1; + if (n < MAXPORT) { + bm[n/8] |= (0x80>>(n%8)); + if ((unsigned)n > maxbm) + maxbm = n; } else return (-1); } @@ -386,7 +383,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) { } break; case T_TXT: - while (1) { + for (;;) { if ((n = getstr_str(buf2, sizeof buf2, &startp, endp)) < 0) { if (cp != (sp2 + INT16SZ)) @@ -402,7 +399,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) { } break; case T_X25: - /* RFC 1183 */ + /* RFC1183 */ if ((n = getstr_str(buf2, sizeof buf2, &startp, endp)) < 0) return (-1); @@ -414,7 +411,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) { cp += n; break; case T_ISDN: - /* RFC 1183 */ + /* RFC1183 */ if ((n = getstr_str(buf2, sizeof buf2, &startp, endp)) < 0) return (-1); @@ -588,7 +585,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) { ShrinkBuffer(n); maxtype = 0; memset(data, 0, sizeof data); - while (1) { + for (;;) { if (!getword_str(buf2, sizeof buf2, &startp, endp)) break; @@ -715,7 +712,7 @@ res_nmkupdate(res_state statp, ns_updrec *rrecp_in, u_char *buf, int buflen) { return (cp - buf); } -/* +/*% * Get a whitespace delimited word from a string (not file) * into buf. modify the start pointer to point after the * word in the string. @@ -728,9 +725,9 @@ getword_str(char *buf, int size, u_char **startpp, u_char *endp) { for (cp = buf; *startpp <= endp; ) { c = **startpp; if (isspace(c) || c == '\0') { - if (cp != buf) /* trailing whitespace */ + if (cp != buf) /*%< trailing whitespace */ break; - else { /* leading whitespace */ + else { /*%< leading whitespace */ (*startpp)++; continue; } @@ -744,9 +741,9 @@ getword_str(char *buf, int size, u_char **startpp, u_char *endp) { return (cp != buf); } -/* +/*% * get a white spae delimited string from memory. Process quoted strings - * and \DDD escapes. Return length or -1 on error. Returned string may + * and \\DDD escapes. Return length or -1 on error. Returned string may * contain nulls. */ static char digits[] = "0123456789"; @@ -823,7 +820,8 @@ getstr_str(char *buf, int size, u_char **startpp, u_char *endp) { *cp = '\0'; return ((cp == buf)? (seen_quote? 0: -1): (cp - buf)); } -/* + +/*% * Get a whitespace delimited base 16 number from a string (not file) into buf * update the start pointer to point after the number in the string. */ @@ -839,9 +837,9 @@ gethexnum_str(u_char **startpp, u_char *endp) { for (n = 0; *startpp <= endp; ) { c = **startpp; if (isspace(c) || c == '\0') { - if (seendigit) /* trailing whitespace */ + if (seendigit) /*%< trailing whitespace */ break; - else { /* leading whitespace */ + else { /*%< leading whitespace */ (*startpp)++; continue; } @@ -871,7 +869,7 @@ gethexnum_str(u_char **startpp, u_char *endp) { return (n + m); } -/* +/*% * Get a whitespace delimited base 10 number from a string (not file) into buf * update the start pointer to point after the number in the string. */ @@ -884,9 +882,9 @@ getnum_str(u_char **startpp, u_char *endp) { for (n = 0; *startpp <= endp; ) { c = **startpp; if (isspace(c) || c == '\0') { - if (seendigit) /* trailing whitespace */ + if (seendigit) /*%< trailing whitespace */ break; - else { /* leading whitespace */ + else { /*%< leading whitespace */ (*startpp)++; continue; } @@ -913,7 +911,7 @@ getnum_str(u_char **startpp, u_char *endp) { return (n + m); } -/* +/*% * Allocate a resource record buffer & save rr info. */ ns_updrec * @@ -928,14 +926,14 @@ res_mkupdrec(int section, const char *dname, } INIT_LINK(rrecp, r_link); INIT_LINK(rrecp, r_glink); - rrecp->r_class = class; - rrecp->r_type = type; + rrecp->r_class = (ns_class)class; + rrecp->r_type = (ns_type)type; rrecp->r_ttl = ttl; - rrecp->r_section = section; + rrecp->r_section = (ns_sect)section; return (rrecp); } -/* +/*% * Free a resource record buffer created by res_mkupdrec. */ void @@ -977,7 +975,7 @@ res_buildservicelist() { free(slp); break; } - slp->port = ntohs((u_int16_t)sp->s_port); /* host byt order */ + slp->port = ntohs((u_int16_t)sp->s_port); /*%< host byt order */ slp->next = servicelist; slp->prev = NULL; if (servicelist) @@ -1019,7 +1017,7 @@ res_buildprotolist(void) { free(slp); break; } - slp->port = pp->p_proto; /* host byte order */ + slp->port = pp->p_proto; /*%< host byte order */ slp->next = protolist; slp->prev = NULL; if (protolist) @@ -1056,14 +1054,14 @@ findservice(const char *s, struct valuelist **list) { lp->next = *list; *list = lp; } - return (lp->port); /* host byte order */ + return (lp->port); /*%< host byte order */ } if (sscanf(s, "%d", &n) != 1 || n <= 0) n = -1; return (n); } -/* +/*% * Convert service name or (ascii) number to int. */ int @@ -1073,7 +1071,7 @@ res_servicenumber(const char *p) { return (findservice(p, &servicelist)); } -/* +/*% * Convert protocol name or (ascii) number to int. */ int @@ -1084,14 +1082,14 @@ res_protocolnumber(const char *p) { } static struct servent * -cgetservbyport(u_int16_t port, const char *proto) { /* Host byte order. */ +cgetservbyport(u_int16_t port, const char *proto) { /*%< Host byte order. */ struct valuelist **list = &servicelist; struct valuelist *lp = *list; static struct servent serv; port = ntohs(port); for (; lp != NULL; lp = lp->next) { - if (port != (u_int16_t)lp->port) /* Host byte order. */ + if (port != (u_int16_t)lp->port) /*%< Host byte order. */ continue; if (strcasecmp(lp->proto, proto) == 0) { if (lp != *list) { @@ -1112,13 +1110,13 @@ cgetservbyport(u_int16_t port, const char *proto) { /* Host byte order. */ } static struct protoent * -cgetprotobynumber(int proto) { /* Host byte order. */ +cgetprotobynumber(int proto) { /*%< Host byte order. */ struct valuelist **list = &protolist; struct valuelist *lp = *list; static struct protoent prot; for (; lp != NULL; lp = lp->next) - if (lp->port == proto) { /* Host byte order. */ + if (lp->port == proto) { /*%< Host byte order. */ if (lp != *list) { lp->prev->next = lp->next; if (lp->next) @@ -1128,7 +1126,7 @@ cgetprotobynumber(int proto) { /* Host byte order. */ *list = lp; } prot.p_name = lp->name; - prot.p_proto = lp->port; /* Host byte order. */ + prot.p_proto = lp->port; /*%< Host byte order. */ return (&prot); } return (0); @@ -1150,7 +1148,7 @@ res_protocolname(int num) { } const char * -res_servicename(u_int16_t port, const char *proto) { /* Host byte order. */ +res_servicename(u_int16_t port, const char *proto) { /*%< Host byte order. */ static char number[8]; struct servent *ss; diff --git a/usr/src/lib/libresolv2/common/resolv/res_mkupdate.h b/usr/src/lib/libresolv2/common/resolv/res_mkupdate.h index 97a7518ee8..96c452d89e 100644 --- a/usr/src/lib/libresolv2/common/resolv/res_mkupdate.h +++ b/usr/src/lib/libresolv2/common/resolv/res_mkupdate.h @@ -1,31 +1,25 @@ /* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1998,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef _RES_MKUPDATE_H_ #define _RES_MKUPDATE_H_ -#pragma ident "%Z%%M% %I% %E% SMI" - __BEGIN_DECLS __END_DECLS #endif /* _RES_MKUPDATE_H_ */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/resolv/res_private.h b/usr/src/lib/libresolv2/common/resolv/res_private.h index 0ee5617541..4e98157ced 100644 --- a/usr/src/lib/libresolv2/common/resolv/res_private.h +++ b/usr/src/lib/libresolv2/common/resolv/res_private.h @@ -1,10 +1,3 @@ -/* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #ifndef res_private_h #define res_private_h @@ -25,3 +18,5 @@ extern int res_ourserver_p(const res_state statp, const struct sockaddr *sa); #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/resolv/res_query.c b/usr/src/lib/libresolv2/common/resolv/res_query.c index b592f4e72f..ab18548c92 100644 --- a/usr/src/lib/libresolv2/common/resolv/res_query.c +++ b/usr/src/lib/libresolv2/common/resolv/res_query.c @@ -1,12 +1,24 @@ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. + * Portions Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") + * Portions Copyright (C) 1996-2001, 2003 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ /* * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -22,7 +34,7 @@ * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -38,14 +50,14 @@ /* * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * + * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies, and that * the name of Digital Equipment Corporation not be used in advertising or * publicity pertaining to distribution of the document or software without * specific, written prior permission. - * + * * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT @@ -56,28 +68,9 @@ * SOFTWARE. */ -/* - * Portions Copyright (c) 1996-1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: res_query.c,v 8.24 2003/01/31 15:25:58 vixie Exp $"; +static const char rcsid[] = "$Id: res_query.c,v 1.11 2008/11/14 02:36:51 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include "port_before.h" @@ -104,7 +97,7 @@ static const char rcsid[] = "$Id: res_query.c,v 8.24 2003/01/31 15:25:58 vixie E #define MAXPACKET 1024 #endif -/* +/*% * Formulate a normal query, send, and await answer. * Returned answer is placed in supplied buffer "answer". * Perform preliminary check of answer, returning success only @@ -116,21 +109,21 @@ static const char rcsid[] = "$Id: res_query.c,v 8.24 2003/01/31 15:25:58 vixie E */ int res_nquery(res_state statp, - const char *name, /* domain name */ - int class, int type, /* class and type of query */ - u_char *answer, /* buffer to put answer */ - int anslen) /* size of answer buffer */ + const char *name, /*%< domain name */ + int class, int type, /*%< class and type of query */ + u_char *answer, /*%< buffer to put answer */ + int anslen) /*%< size of answer buffer */ { u_char buf[MAXPACKET]; HEADER *hp = (HEADER *) answer; - int n; u_int oflags; + u_char *rdata; + int n; oflags = statp->_flags; again: - hp->rcode = NOERROR; /* default */ - + hp->rcode = NOERROR; /*%< default */ #ifdef DEBUG if (statp->options & RES_DEBUG) printf(";; res_query(%s, %d, %d)\n", name, class, type); @@ -140,8 +133,14 @@ again: buf, sizeof(buf)); #ifdef RES_USE_EDNS0 if (n > 0 && (statp->_flags & RES_F_EDNS0ERR) == 0 && - (statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0) + (statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC|RES_NSID))) { n = res_nopt(statp, n, buf, sizeof(buf), anslen); + rdata = &buf[n]; + if (n > 0 && (statp->options & RES_NSID) != 0U) { + n = res_nopt_rdata(statp, n, buf, sizeof(buf), rdata, + NS_OPT_NSID, 0, NULL); + } + } #endif if (n <= 0) { #ifdef DEBUG @@ -151,11 +150,12 @@ again: RES_SET_H_ERRNO(statp, NO_RECOVERY); return (n); } + n = res_nsend(statp, buf, n, answer, anslen); if (n < 0) { #ifdef RES_USE_EDNS0 /* if the query choked with EDNS0, retry without EDNS0 */ - if ((statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0 && + if ((statp->options & (RES_USE_EDNS0|RES_USE_DNSSEC)) != 0U && ((oflags ^ statp->_flags) & RES_F_EDNS0ERR) != 0) { statp->_flags |= RES_F_EDNS0ERR; if (statp->options & RES_DEBUG) @@ -202,7 +202,7 @@ again: return (n); } -/* +/*% * Formulate a normal query, send, and retrieve answer in supplied buffer. * Return the size of the response on success, -1 on error. * If enabled, implement search rules until answer or unrecoverable failure @@ -210,10 +210,10 @@ again: */ int res_nsearch(res_state statp, - const char *name, /* domain name */ - int class, int type, /* class and type of query */ - u_char *answer, /* buffer to put answer */ - int anslen) /* size of answer */ + const char *name, /*%< domain name */ + int class, int type, /*%< class and type of query */ + u_char *answer, /*%< buffer to put answer */ + int anslen) /*%< size of answer */ { const char *cp, * const *domain; HEADER *hp = (HEADER *) answer; @@ -225,8 +225,7 @@ res_nsearch(res_state statp, int searched = 0; errno = 0; - RES_SET_H_ERRNO(statp, HOST_NOT_FOUND); /* True if we never query. */ - + RES_SET_H_ERRNO(statp, HOST_NOT_FOUND); /*%< True if we never query. */ dots = 0; for (cp = name; *cp != '\0'; cp++) dots += (*cp == '.'); @@ -259,8 +258,8 @@ res_nsearch(res_state statp, * - there is at least one dot, there is no trailing dot, * and RES_DNSRCH is set. */ - if ((!dots && (statp->options & RES_DEFNAMES) != 0) || - (dots && !trailing_dot && (statp->options & RES_DNSRCH) != 0)) { + if ((!dots && (statp->options & RES_DEFNAMES) != 0U) || + (dots && !trailing_dot && (statp->options & RES_DNSRCH) != 0U)) { int done = 0; for (domain = (const char * const *)statp->dnsrch; @@ -318,7 +317,7 @@ res_nsearch(res_state statp, /* if we got here for some reason other than DNSRCH, * we only wanted one iteration of the loop, so stop. */ - if ((statp->options & RES_DNSRCH) == 0) + if ((statp->options & RES_DNSRCH) == 0U) done++; } } @@ -327,7 +326,7 @@ res_nsearch(res_state statp, * If the query has not already been tried as is then try it * unless RES_NOTLDQUERY is set and there were no dots. */ - if ((dots || !searched || (statp->options & RES_NOTLDQUERY) == 0) && + if ((dots || !searched || (statp->options & RES_NOTLDQUERY) == 0U) && !(tried_as_is || root_on_list)) { ret = res_nquerydomain(statp, name, NULL, class, type, answer, anslen); @@ -351,7 +350,7 @@ res_nsearch(res_state statp, return (-1); } -/* +/*% * Perform a call on res_query on the concatenation of name and domain, * removing a trailing dot from name if domain is NULL. */ @@ -359,9 +358,9 @@ int res_nquerydomain(res_state statp, const char *name, const char *domain, - int class, int type, /* class and type of query */ - u_char *answer, /* buffer to put answer */ - int anslen) /* size of answer */ + int class, int type, /*%< class and type of query */ + u_char *answer, /*%< buffer to put answer */ + int anslen) /*%< size of answer */ { char nbuf[MAXDNAME]; const char *longname = nbuf; @@ -409,11 +408,7 @@ res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) { if (statp->options & RES_NOALIASES) return (NULL); file = getenv("HOSTALIASES"); -#ifdef SUNW_AVOIDSTDIO_FDLIMIT - if (file == NULL || (fp = fopen(file, "rF")) == NULL) -#else - if (file == NULL || (fp = fopen(file, "r")) == NULL) -#endif + if (file == NULL || (fp = fopen(file, "r")) == NULL) return (NULL); setbuf(fp, NULL); buf[sizeof(buf) - 1] = '\0'; @@ -441,3 +436,5 @@ res_hostalias(const res_state statp, const char *name, char *dst, size_t siz) { fclose(fp); return (NULL); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/resolv/res_send.c b/usr/src/lib/libresolv2/common/resolv/res_send.c index 5891e01e62..8e629a3d96 100644 --- a/usr/src/lib/libresolv2/common/resolv/res_send.c +++ b/usr/src/lib/libresolv2/common/resolv/res_send.c @@ -1,12 +1,30 @@ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ + +/* + * Portions Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC") + * Portions Copyright (C) 1996-2003 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + /* * Copyright (c) 1985, 1989, 1993 * The Regents of the University of California. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -22,7 +40,7 @@ * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -38,14 +56,14 @@ /* * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * + * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies, and that * the name of Digital Equipment Corporation not be used in advertising or * publicity pertaining to distribution of the document or software without * specific, written prior permission. - * + * * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT @@ -56,31 +74,13 @@ * SOFTWARE. */ -/* - * Portions Copyright (c) 1996-1999 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "$Id: res_send.c,v 8.52 2003/04/29 02:13:08 marka Exp $"; +static const char rcsid[] = "$Id: res_send.c,v 1.22 2009/01/22 23:49:23 tbox Exp $"; #endif /* LIBC_SCCS and not lint */ -/* +/*! \file + * \brief * Send query to name server and wait for reply. */ @@ -110,14 +110,12 @@ static const char rcsid[] = "$Id: res_send.c,v 8.52 2003/04/29 02:13:08 marka Ex #include "port_after.h" -#ifdef SUNW_POLL +#ifdef USE_POLL +#ifdef HAVE_STROPTS_H #include <stropts.h> -#include <poll.h> -#if defined(pselect) -#undef pselect #endif -#define pselect Pselect -#endif /* SUNW_POLL */ +#include <poll.h> +#endif /* USE_POLL */ /* Options. Leave them on. */ #define DEBUG @@ -126,7 +124,7 @@ static const char rcsid[] = "$Id: res_send.c,v 8.52 2003/04/29 02:13:08 marka Ex #define EXT(res) ((res)->_u._ext) -#ifdef ORIGINAL_ISC_CODE +#ifndef USE_POLL static const int highestFD = FD_SETSIZE - 1; #else static int highestFD = 0; @@ -139,21 +137,20 @@ static struct sockaddr * get_nsaddr __P((res_state, size_t)); static int send_vc(res_state, const u_char *, int, u_char *, int, int *, int); static int send_dg(res_state, const u_char *, int, - u_char *, int, int *, int, + u_char *, int, int *, int, int, int *, int *); static void Aerror(const res_state, FILE *, const char *, int, const struct sockaddr *, int); static void Perror(const res_state, FILE *, const char *, int); static int sock_eq(struct sockaddr *, struct sockaddr *); -#ifdef NEED_PSELECT +#if defined(NEED_PSELECT) && !defined(USE_POLL) static int pselect(int, void *, void *, void *, struct timespec *, const sigset_t *); #endif void res_pquery(const res_state, const u_char *, int, FILE *); -#ifdef ORIGINAL_ISC_CODE -#else +#ifndef ORIGINAL_ISC_CODE #pragma weak __res_nameinquery = res_nameinquery #pragma weak __res_queriesmatch = res_queriesmatch #pragma weak res_nisourserver = res_ourserver_p @@ -163,14 +160,15 @@ static const int niflags = NI_NUMERICHOST | NI_NUMERICSERV; /* Public. */ -/* int - * res_isourserver(ina) +/*% * looks up "ina" in _res.ns_addr_list[] + * * returns: - * 0 : not found - * >0 : found + *\li 0 : not found + *\li >0 : found + * * author: - * paul vixie, 29may94 + *\li paul vixie, 29may94 */ int res_ourserver_p(const res_state statp, const struct sockaddr *sa) { @@ -199,8 +197,8 @@ res_ourserver_p(const res_state statp, const struct sockaddr *sa) { if (srv6->sin6_family == in6p->sin6_family && srv6->sin6_port == in6p->sin6_port && #ifdef HAVE_SIN6_SCOPE_ID - (srv6->sin6_scope_id == 0 || - srv6->sin6_scope_id == in6p->sin6_scope_id) && + (srv6->sin6_scope_id == 0 || + srv6->sin6_scope_id == in6p->sin6_scope_id) && #endif (IN6_IS_ADDR_UNSPECIFIED(&srv6->sin6_addr) || IN6_ARE_ADDR_EQUAL(&srv6->sin6_addr, &in6p->sin6_addr))) @@ -213,17 +211,19 @@ res_ourserver_p(const res_state statp, const struct sockaddr *sa) { return (0); } -/* int - * res_nameinquery(name, type, class, buf, eom) +/*% * look for (name,type,class) in the query section of packet (buf,eom) + * * requires: - * buf + HFIXEDSZ <= eom + *\li buf + HFIXEDSZ <= eom + * * returns: - * -1 : format error - * 0 : not found - * >0 : found + *\li -1 : format error + *\li 0 : not found + *\li >0 : found + * * author: - * paul vixie, 29may94 + *\li paul vixie, 29may94 */ int res_nameinquery(const char *name, int type, int class, @@ -251,16 +251,17 @@ res_nameinquery(const char *name, int type, int class, return (0); } -/* int - * res_queriesmatch(buf1, eom1, buf2, eom2) +/*% * is there a 1:1 mapping of (name,type,class) * in (buf1,eom1) and (buf2,eom2)? + * * returns: - * -1 : format error - * 0 : not a 1:1 mapping - * >0 : is a 1:1 mapping + *\li -1 : format error + *\li 0 : not a 1:1 mapping + *\li >0 : is a 1:1 mapping + * * author: - * paul vixie, 29may94 + *\li paul vixie, 29may94 */ int res_queriesmatch(const u_char *buf1, const u_char *eom1, @@ -304,14 +305,14 @@ int res_nsend(res_state statp, const u_char *buf, int buflen, u_char *ans, int anssiz) { - int gotsomewhere, terrno, try, v_circuit, resplen, ns, n; + int gotsomewhere, terrno, tries, v_circuit, resplen, ns, n; char abuf[NI_MAXHOST]; -#ifdef SUNW_POLL +#ifdef USE_POLL highestFD = sysconf(_SC_OPEN_MAX) - 1; #endif - /* No name servers or previous res_ninit() failure */ + /* No name servers or res_init() failure */ if (statp->nscount == 0 || EXT(statp).ext == NULL) { errno = ESRCH; return (-1); @@ -349,7 +350,7 @@ res_nsend(res_state statp, if (EXT(statp).nssocks[ns] == -1) continue; peerlen = sizeof(peer); - if (getsockname(EXT(statp).nssocks[ns], + if (getpeername(EXT(statp).nssocks[ns], (struct sockaddr *)&peer, &peerlen) < 0) { needclose++; break; @@ -385,8 +386,8 @@ res_nsend(res_state statp, * Some resolvers want to even out the load on their nameservers. * Note that RES_BLAST overrides RES_ROTATE. */ - if ((statp->options & RES_ROTATE) != 0 && - (statp->options & RES_BLAST) == 0) { + if ((statp->options & RES_ROTATE) != 0U && + (statp->options & RES_BLAST) == 0U) { union res_sockaddr_union inu; struct sockaddr_in ina; int lastns = statp->nscount - 1; @@ -400,7 +401,7 @@ res_nsend(res_state statp, nstime = EXT(statp).nstimes[0]; for (ns = 0; ns < lastns; ns++) { if (EXT(statp).ext != NULL) - EXT(statp).ext->nsaddrs[ns] = + EXT(statp).ext->nsaddrs[ns] = EXT(statp).ext->nsaddrs[ns + 1]; statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1]; EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns + 1]; @@ -416,7 +417,7 @@ res_nsend(res_state statp, /* * Send request, RETRY times, or until successful. */ - for (try = 0; try < statp->retry; try++) { + for (tries = 0; tries < statp->retry; tries++) { for (ns = 0; ns < statp->nscount; ns++) { struct sockaddr *nsap; int nsaplen; @@ -464,7 +465,7 @@ res_nsend(res_state statp, if (v_circuit) { /* Use VC; at most one attempt per server. */ - try = statp->retry; + tries = statp->retry; n = send_vc(statp, buf, buflen, ans, anssiz, &terrno, ns); if (n < 0) @@ -475,7 +476,7 @@ res_nsend(res_state statp, } else { /* Use datagrams. */ n = send_dg(statp, buf, buflen, ans, anssiz, &terrno, - ns, &v_circuit, &gotsomewhere); + ns, tries, &v_circuit, &gotsomewhere); if (n < 0) goto fail; if (n == 0) @@ -500,8 +501,8 @@ res_nsend(res_state statp, * or if we haven't been asked to keep a socket open, * close the socket. */ - if ((v_circuit && (statp->options & RES_USEVC) == 0) || - (statp->options & RES_STAYOPEN) == 0) { + if ((v_circuit && (statp->options & RES_USEVC) == 0U) || + (statp->options & RES_STAYOPEN) == 0U) { res_nclose(statp); } if (statp->rhook) { @@ -540,9 +541,9 @@ res_nsend(res_state statp, res_nclose(statp); if (!v_circuit) { if (!gotsomewhere) - errno = ECONNREFUSED; /* no nameservers found */ + errno = ECONNREFUSED; /*%< no nameservers found */ else - errno = ETIMEDOUT; /* no answer obtained */ + errno = ETIMEDOUT; /*%< no answer obtained */ } else errno = terrno; return (-1); @@ -569,10 +570,10 @@ get_salen(sa) else if (sa->sa_family == AF_INET6) return (sizeof(struct sockaddr_in6)); else - return (0); /* unknown, die on connect */ + return (0); /*%< unknown, die on connect */ } -/* +/*% * pick appropriate nsaddr_list for use. see res_init() for initialization. */ static struct sockaddr * @@ -612,6 +613,9 @@ send_vc(res_state statp, u_short len; u_char *cp; void *tmp; +#ifdef SO_NOSIGPIPE + int on = 1; +#endif nsap = get_nsaddr(statp, ns); nsaplen = get_salen(nsap); @@ -643,10 +647,31 @@ send_vc(res_state statp, errno = ENOTSOCK; } if (statp->_vcsock < 0) { - *terrno = errno; - Perror(statp, stderr, "socket(vc)", errno); - return (-1); + switch (errno) { + case EPROTONOSUPPORT: +#ifdef EPFNOSUPPORT + case EPFNOSUPPORT: +#endif + case EAFNOSUPPORT: + Perror(statp, stderr, "socket(vc)", errno); + return (0); + default: + *terrno = errno; + Perror(statp, stderr, "socket(vc)", errno); + return (-1); + } } +#ifdef SO_NOSIGPIPE + /* + * Disable generation of SIGPIPE when writing to a closed + * socket. Write should return -1 and set errno to EPIPE + * instead. + * + * Push on even if setsockopt(SO_NOSIGPIPE) fails. + */ + (void)setsockopt(statp->_vcsock, SOL_SOCKET, SO_NOSIGPIPE, &on, + sizeof(on)); +#endif errno = 0; if (connect(statp->_vcsock, nsap, nsaplen) < 0) { *terrno = errno; @@ -679,7 +704,7 @@ send_vc(res_state statp, len = INT16SZ; while ((n = read(statp->_vcsock, (char *)cp, (int)len)) > 0) { cp += n; - if ((len -= n) <= 0) + if ((len -= n) == 0) break; } if (n <= 0) { @@ -739,14 +764,6 @@ send_vc(res_state statp, */ anhp->tc = 1; len = resplen - anssiz; - /* - * Reset the value of resplen to anssiz, - * this is done because the caller assumes - * resplen contains the size of message read - * into the "ans" buffer passed in. - */ - resplen = anssiz; - while (len != 0) { char junk[PACKETSZ]; @@ -781,22 +798,23 @@ send_vc(res_state statp, } static int -send_dg(res_state statp, - const u_char *buf, int buflen, u_char *ans, int anssiz, - int *terrno, int ns, int *v_circuit, int *gotsomewhere) +send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans, + int anssiz, int *terrno, int ns, int tries, int *v_circuit, + int *gotsomewhere) { const HEADER *hp = (const HEADER *) buf; HEADER *anhp = (HEADER *) ans; const struct sockaddr *nsap; int nsaplen; struct timespec now, timeout, finish; - fd_set dsmask; struct sockaddr_storage from; ISC_SOCKLEN_T fromlen; int resplen, seconds, n, s; -#ifdef SUNW_POLL - int polltimeout; +#ifdef USE_POLL + int polltimeout; struct pollfd pollfd; +#else + fd_set dsmask; #endif nsap = get_nsaddr(statp, ns); @@ -808,9 +826,19 @@ send_dg(res_state statp, errno = ENOTSOCK; } if (EXT(statp).nssocks[ns] < 0) { - *terrno = errno; - Perror(statp, stderr, "socket(dg)", errno); - return (-1); + switch (errno) { + case EPROTONOSUPPORT: +#ifdef EPFNOSUPPORT + case EPFNOSUPPORT: +#endif + case EAFNOSUPPORT: + Perror(statp, stderr, "socket(dg)", errno); + return (0); + default: + *terrno = errno; + Perror(statp, stderr, "socket(dg)", errno); + return (-1); + } } #ifndef CANNOT_CONNECT_DGRAM /* @@ -853,7 +881,7 @@ send_dg(res_state statp, /* * Wait for reply. */ - seconds = (statp->retrans << ns); + seconds = (statp->retrans << tries); if (ns > 0) seconds /= statp->nscount; if (seconds <= 0) @@ -865,7 +893,15 @@ send_dg(res_state statp, wait: now = evNowTime(); nonow: -#ifdef SUNW_POLL +#ifndef USE_POLL + FD_ZERO(&dsmask); + FD_SET(s, &dsmask); + if (evCmpTime(finish, now) > 0) + timeout = evSubTime(finish, now); + else + timeout = evConsTime(0, 0); + n = pselect(s + 1, &dsmask, NULL, NULL, &timeout, NULL); +#else timeout = evSubTime(finish, now); if (timeout.tv_sec < 0) timeout = evConsTime(0, 0); @@ -874,15 +910,8 @@ send_dg(res_state statp, pollfd.fd = s; pollfd.events = POLLRDNORM; n = poll(&pollfd, 1, polltimeout); -#else - FD_ZERO(&dsmask); - FD_SET(s, &dsmask); - if (evCmpTime(finish, now) > 0) - timeout = evSubTime(finish, now); - else - timeout = evConsTime(0, 0); - n = pselect(s + 1, &dsmask, NULL, NULL, &timeout, NULL); -#endif +#endif /* USE_POLL */ + if (n == 0) { Dprint(statp->options & RES_DEBUG, (stdout, ";; timeout\n")); *gotsomewhere = 1; @@ -891,11 +920,11 @@ send_dg(res_state statp, if (n < 0) { if (errno == EINTR) goto wait; -#ifdef SUNW_POLL - Perror(statp, stderr, "poll", errno); -#else +#ifndef USE_POLL Perror(statp, stderr, "select", errno); -#endif +#else + Perror(statp, stderr, "poll", errno); +#endif /* USE_POLL */ res_nclose(statp); return (0); } @@ -946,7 +975,7 @@ send_dg(res_state statp, goto wait; } #ifdef RES_USE_EDNS0 - if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0) { + if (anhp->rcode == FORMERR && (statp->options & RES_USE_EDNS0) != 0U) { /* * Do not retry if the server do not understand EDNS0. * The case has to be captured here, as FORMERR packet do not @@ -1014,7 +1043,7 @@ Aerror(const res_state statp, FILE *file, const char *string, int error, alen = alen; - if ((statp->options & RES_DEBUG) != 0) { + if ((statp->options & RES_DEBUG) != 0U) { if (getnameinfo(address, alen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), niflags)) { strncpy(hbuf, "?", sizeof(hbuf) - 1); @@ -1032,7 +1061,7 @@ static void Perror(const res_state statp, FILE *file, const char *string, int error) { int save = errno; - if ((statp->options & RES_DEBUG) != 0) + if ((statp->options & RES_DEBUG) != 0U) fprintf(file, "res_send: %s: %s\n", string, strerror(error)); errno = save; @@ -1064,7 +1093,7 @@ sock_eq(struct sockaddr *a, struct sockaddr *b) { } } -#ifdef NEED_PSELECT +#if defined(NEED_PSELECT) && !defined(USE_POLL) /* XXX needs to move to the porting library. */ static int pselect(int nfds, void *rfds, void *wfds, void *efds, diff --git a/usr/src/lib/libresolv2/common/resolv/res_sendsigned.c b/usr/src/lib/libresolv2/common/resolv/res_sendsigned.c index 63fe5cc2d9..63ae07ce3d 100644 --- a/usr/src/lib/libresolv2/common/resolv/res_sendsigned.c +++ b/usr/src/lib/libresolv2/common/resolv/res_sendsigned.c @@ -1,12 +1,3 @@ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - * No ISC copyright for this file. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "port_before.h" #include "fd_setsize.h" @@ -33,7 +24,7 @@ #include "res_debug.h" -/* res_nsendsigned */ +/*% res_nsendsigned */ int res_nsendsigned(res_state statp, const u_char *msg, int msglen, ns_tsig_key *key, u_char *answer, int anslen) @@ -47,6 +38,7 @@ res_nsendsigned(res_state statp, const u_char *msg, int msglen, HEADER *hp; time_t tsig_time; int ret; + int len; dst_init(); @@ -60,6 +52,7 @@ res_nsendsigned(res_state statp, const u_char *msg, int msglen, bufsize = msglen + 1024; newmsg = (u_char *) malloc(bufsize); if (newmsg == NULL) { + free(nstatp); errno = ENOMEM; return (-1); } @@ -95,34 +88,51 @@ res_nsendsigned(res_state statp, const u_char *msg, int msglen, return (ret); } - if (newmsglen > PACKETSZ || (nstatp->options & RES_IGNTC)) + if (newmsglen > PACKETSZ || nstatp->options & RES_USEVC) usingTCP = 1; if (usingTCP == 0) nstatp->options |= RES_IGNTC; else nstatp->options |= RES_USEVC; + /* + * Stop res_send printing the answer. + */ + nstatp->options &= ~RES_DEBUG; + nstatp->pfcode &= ~RES_PRF_REPLY; retry: - ret = res_nsend(nstatp, newmsg, newmsglen, answer, anslen); - if (ret < 0) { + len = res_nsend(nstatp, newmsg, newmsglen, answer, anslen); + if (len < 0) { free (nstatp); free (newmsg); dst_free_key(dstkey); - return (ret); + return (len); } - anslen = ret; - ret = ns_verify(answer, &anslen, dstkey, sig, siglen, + ret = ns_verify(answer, &len, dstkey, sig, siglen, NULL, NULL, &tsig_time, nstatp->options & RES_KEEPTSIG); if (ret != 0) { -#ifdef ORIGINAL_ISC_CODE - Dprint(nstatp->pfcode & RES_PRF_REPLY, - (stdout, ";; TSIG invalid (%s)\n", p_rcode(ret))); -#else - Dprint(nstatp->pfcode & RES_PRF_REPLY, - (stdout, ";; TSIG invalid (%s)\n", p_rcode(-ret))); -#endif + Dprint((statp->options & RES_DEBUG) || + ((statp->pfcode & RES_PRF_REPLY) && + (statp->pfcode & RES_PRF_HEAD1)), + (stdout, ";; got answer:\n")); + + DprintQ((statp->options & RES_DEBUG) || + (statp->pfcode & RES_PRF_REPLY), + (stdout, "%s", ""), + answer, (anslen > len) ? len : anslen); + + if (ret > 0) { + Dprint(statp->pfcode & RES_PRF_REPLY, + (stdout, ";; server rejected TSIG (%s)\n", + p_rcode(ret))); + } else { + Dprint(statp->pfcode & RES_PRF_REPLY, + (stdout, ";; TSIG invalid (%s)\n", + p_rcode(-ret))); + } + free (nstatp); free (newmsg); dst_free_key(dstkey); @@ -132,17 +142,29 @@ retry: errno = ENOTTY; return (-1); } - Dprint(nstatp->pfcode & RES_PRF_REPLY, (stdout, ";; TSIG ok\n")); hp = (HEADER *) answer; - if (hp->tc && usingTCP == 0) { + if (hp->tc && !usingTCP && (statp->options & RES_IGNTC) == 0U) { nstatp->options &= ~RES_IGNTC; usingTCP = 1; goto retry; } + Dprint((statp->options & RES_DEBUG) || + ((statp->pfcode & RES_PRF_REPLY) && + (statp->pfcode & RES_PRF_HEAD1)), + (stdout, ";; got answer:\n")); + + DprintQ((statp->options & RES_DEBUG) || + (statp->pfcode & RES_PRF_REPLY), + (stdout, "%s", ""), + answer, (anslen > len) ? len : anslen); + + Dprint(statp->pfcode & RES_PRF_REPLY, (stdout, ";; TSIG ok\n")); free (nstatp); free (newmsg); dst_free_key(dstkey); - return (anslen); + return (len); } + +/*! \file */ diff --git a/usr/src/lib/libresolv2/common/resolv/res_update.c b/usr/src/lib/libresolv2/common/resolv/res_update.c index 8983dee245..5b2ecb1a35 100644 --- a/usr/src/lib/libresolv2/common/resolv/res_update.c +++ b/usr/src/lib/libresolv2/common/resolv/res_update.c @@ -1,34 +1,28 @@ -/* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - #if !defined(lint) && !defined(SABER) -static const char rcsid[] = "$Id: res_update.c,v 1.38 2003/05/27 23:36:53 marka Exp $"; +static const char rcsid[] = "$Id: res_update.c,v 1.13 2005/04/27 04:56:43 sra Exp $"; #endif /* not lint */ /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - -/* +/*! \file + * \brief * Based on the Dynamic DNS reference implementation by Viraj Bais - * <viraj_bais@ccm.fm.intel.com> + * <viraj_bais@ccm.fm.intel.com> */ #include "port_before.h" @@ -56,7 +50,7 @@ static const char rcsid[] = "$Id: res_update.c,v 1.38 2003/05/27 23:36:53 marka #include "port_after.h" #include "res_private.h" -/* +/*% * Separate a linked list of records into groups so that all records * in a group will belong to a single zone on the nameserver. * Create a dynamic update packet for each zone and send it to the @@ -90,7 +84,7 @@ static void res_dprintf(const char *, ...) ISC_FORMAT_PRINTF(1, 2); #define DPRINTF(x) do {\ int save_errno = errno; \ - if ((statp->options & RES_DEBUG) != 0) res_dprintf x; \ + if ((statp->options & RES_DEBUG) != 0U) res_dprintf x; \ errno = save_errno; \ } while (0) diff --git a/usr/src/lib/libresolv2/common/sunw/sunw_dst_init.c b/usr/src/lib/libresolv2/common/sunw/sunw_dst_init.c deleted file mode 100644 index 9d299a6f90..0000000000 --- a/usr/src/lib/libresolv2/common/sunw/sunw_dst_init.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#define __SUNW_DST_INIT_NODEFINE - -#include <port_before.h> - -#include <dlfcn.h> - -#include <isc/dst.h> - -#include <port_after.h> - - -static int -genInit(char *library, char *symbol, int (**initFunc)(void)) { - - void *dlHandle; - - if (*initFunc == 0) { - if ((dlHandle = dlopen(library, RTLD_LAZY|RTLD_GLOBAL)) == 0) - return (0); - if ((*(initFunc) = (int (*)(void))dlsym(dlHandle, - symbol)) == 0) { - /* - * Can't close the library, since it may be in use - * as a result of a previous, successful, call to - * this function. - */ - return (0); - } - } - - return ((**initFunc)()); -} - - -int -sunw_dst_bsafe_init(void) { - - static int (*initFunc)(void); - - return (genInit("/usr/lib/dns/dnssafe.so.1", "dst_bsafe_init", - &initFunc) || - genInit("/usr/lib/dns/sparcv9/dnssafe.so.1", "dst_bsafe_init", - &initFunc)); -} - - -int -sunw_dst_eay_dss_init(void) { - - static int (*initFunc)(void); - - return (genInit("/usr/lib/dns/cylink.so.1", "dst_eay_dss_init", - &initFunc) || - genInit("/usr/lib/dns/sparcv9/cylink.so.1", "dst_eay_dss_init", - &initFunc)); -} - - -int -sunw_dst_cylink_init(void) { - - static int (*initFunc)(void); - - return (genInit("/usr/lib/dns/cylink.so.1", "dst_cylink_init", - &initFunc) || - genInit("/usr/lib/dns/sparcv9/cylink.so.1", "dst_cylink_init", - &initFunc)); -} - - -int -sunw_dst_hmac_md5_init(void) { - - static int (*initFunc)(void); - - return (genInit("/usr/lib/dns/dnssafe.so.1", "dst_md5_hmac_init", - &initFunc) || - genInit("/usr/lib/dns/sparcv9/dnssafe.so.1", - "dst_hmac_md5_init", - &initFunc)); -} - - -int -sunw_dst_rsaref_init(void) { - - static int (*initFunc)(void); - - return (genInit("/usr/lib/dns/dnssafe.so.1", "dst_rsaref_init", - &initFunc) || - genInit("/usr/lib/dns/sparcv9/dnssafe.so.1", "dst_rsaref_init", - &initFunc)); -} diff --git a/usr/src/lib/libresolv2/common/sunw/sunw_irs_init.c b/usr/src/lib/libresolv2/common/sunw/sunw_irs_init.c deleted file mode 100644 index 542172cf25..0000000000 --- a/usr/src/lib/libresolv2/common/sunw/sunw_irs_init.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#define __SUNW_IRS_INIT_NODEFINE - -#include <port_before.h> - -#include <dlfcn.h> - -#include <port_after.h> - - -static struct irs_acc * -genInit(char *library, char *symbol, - struct irs_acc *(**initFunc)(const char *), const char *options) { - - void *dlHandle; - - if (*initFunc == 0) { - if ((dlHandle = dlopen(library, RTLD_LAZY|RTLD_GLOBAL)) == 0) - return (0); - if ((*(initFunc) = - (struct irs_acc *(*)(const char *))dlsym(dlHandle, - symbol)) == 0) { - /* - * Can't close the library, since it may be in use - * as a result of a previous, successful, call to - * this function. - */ - return (0); - } - } - - return ((**initFunc)(options)); -} - - -#ifdef WANT_IRS_NIS -struct irs_acc * -sunw_irs_nis_acc(const char *options) { - - static struct irs_acc *(*initFunc)(const char *); - struct irs_acc *ret; - - ret = genInit("/usr/lib/dns/irs.so.1", "irs_nis_acc", &initFunc, - options); - if (ret == 0) - ret = genInit("/usr/lib/dns/sparcv9/irs.so.1", "irs_nis_acc", - &initFunc, options); - return (ret); -} -#else -struct irs_acc * -sunw_irs_nis_acc(const char *options) { - return (0); -} -#endif /* WANT_IRS_NIS */ - -struct irs_acc * -sunw_irs_irp_acc(const char *options) { - - static struct irs_acc *(*initFunc)(const char *); - struct irs_acc *ret; - - ret = genInit("/usr/lib/dns/irs.so.1", "irs_irp_acc", &initFunc, - options); - if (ret == 0) - ret = genInit("/usr/lib/dns/sparcv9/irs.so.1", "irs_irp_acc", - &initFunc, options); - return (ret); -} diff --git a/usr/src/lib/libresolv2/common/sunw/sunw_irs_nis_acc.c b/usr/src/lib/libresolv2/common/sunw/sunw_irs_nis_acc.c deleted file mode 100644 index 0b5422b991..0000000000 --- a/usr/src/lib/libresolv2/common/sunw/sunw_irs_nis_acc.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <port_before.h> - -#include <irs.h> - -#include <port_after.h> - -#ifdef WANT_IRS_NIS -static int __deliberately_empty; -#else -/* - * Never called; defined here so that the mapfile doesn't have to change - * depending on WANT_IRS_NIS. - */ -struct irs_acc * -irs_nis_acc(const char *options) { - return (0); -} -#endif /* WANT_IRS_NIS */ diff --git a/usr/src/lib/libresolv2/common/sunw/sunw_mtctxres.c b/usr/src/lib/libresolv2/common/sunw/sunw_mtctxres.c index c77e103e22..eec652bd67 100644 --- a/usr/src/lib/libresolv2/common/sunw/sunw_mtctxres.c +++ b/usr/src/lib/libresolv2/common/sunw/sunw_mtctxres.c @@ -1,9 +1,8 @@ /* - * Copyright (c) 1998-2000 by Sun Microsystems, Inc. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <port_before.h> #include <thread.h> #include <errno.h> @@ -14,106 +13,11 @@ #include <irs.h> #include <port_after.h> -static int thr_keycreate_ret = 0; - -static thread_key_t key; -static int mt_key_initialized = 0; - -static mtctxres_t sharedctx; - -static int __res_init_ctx(thread_key_t); -static void __res_destroy_ctx(void *); - -#pragma init (_mtctxres_init) - -/* - * Initialize the TSD key. By doing this at library load time, we're - * implicitly running without interference from other threads, so there's - * no need for locking. - */ -static void -_mtctxres_init(void) { - - if ((thr_keycreate_ret = thr_keycreate(&key, __res_destroy_ctx)) == 0) { - mt_key_initialized = 1; - } -} - - /* - * To support binaries that used the private MT-safe interface in - * on998 or on28, we still need to provide the __res_enable_mt() - * and __res_disable_mt() entry points. They're do-nothing routines. + * much of the original version of sunw_mtxtxres.c was incorporated into + * ISC libbind as resolv/mtctxres.c. The following bits have not yet made + * it into ISC libbind. */ -int -__res_enable_mt(void) { - return (-1); -} - -int -__res_disable_mt(void) { - return (0); -} - - -static int -__res_init_ctx(thread_key_t key) { - - mtctxres_t *mt; - int ret; - - - if (thr_getspecific(key, (void **)&mt) == 0 && mt != 0) { - /* Already exists */ - return (0); - } - - if ((mt = malloc(sizeof (mtctxres_t))) == 0) { - errno = ENOMEM; - return (-1); - } - - memset(mt, 0, sizeof (*mt)); - - if ((ret = thr_setspecific(key, mt)) != 0) { - errno = ret; - free(mt); - return (-1); - } - - return (0); - -} - - -static void -__res_destroy_ctx(void *value) { - - mtctxres_t *mt = (mtctxres_t *)value; - - if (mt != 0) { - free(mt); - } -} - - -mtctxres_t * -___mtctxres() { - - mtctxres_t *mt; - - - if (mt_key_initialized) { - if ((thr_getspecific(key, (void **)&mt) == 0 && mt != 0) || - (__res_init_ctx(key) == 0 && - thr_getspecific(key, (void **)&mt) == 0 && mt != 0)) { - return (mt); - } - } - - return (&sharedctx); -} - /* * There used to be a private, MT-safe resolver interface that used TSD diff --git a/usr/src/lib/libresolv2/common/sunw/sunw_updrec.c b/usr/src/lib/libresolv2/common/sunw/sunw_updrec.c index c9bc2b2038..3b0ffc49df 100644 --- a/usr/src/lib/libresolv2/common/sunw/sunw_updrec.c +++ b/usr/src/lib/libresolv2/common/sunw/sunw_updrec.c @@ -1,10 +1,8 @@ /* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* * As of BIND 8.2.2, ISC (a) removed res_mkupdate(), res_update(), and * res_mkupdrec() from what they consider the supported interface. The @@ -25,19 +23,25 @@ #include <sys/types.h> #include <netinet/in.h> +/* get the Solaris ns_updrec before any renaming happens */ +#include <arpa/nameser.h> + +/* get the __ISC_ns_updrec */ #include <res_update.h> + +#include <port_after.h> + +/* un-rename ns_updrec and res_* functions so we can wrap them */ #undef ns_updrec #undef res_mkupdate #undef res_update #undef res_mkupdrec #undef res_freeupdrec -#include <arpa/nameser.h> - -#include <port_after.h> +#undef res_nmkupdate +#undef res_nupdate void res_freeupdrec(ns_updrec *); - static int old2new(ns_updrec *old, __ISC_ns_updrec *new) { @@ -106,7 +110,7 @@ delete_list(__ISC_ns_updrec *list) { static __ISC_ns_updrec * -copy_list(ns_updrec *old) { +copy_list(ns_updrec *old, int do_glink) { __ISC_ns_updrec *list = 0, *r, *p; @@ -122,23 +126,34 @@ copy_list(ns_updrec *old) { } r->r_link.prev = p; r->r_link.next = 0; - if (p != 0) + /* res_update and res_nupdate want r_glink set up like this */ + if (do_glink) { + r->r_glink.prev = p; + r->r_glink.next = 0; + } else { + r->r_glink.prev = (void *)-1; + r->r_glink.next = (void *)-1; + } + if (p != 0) { p->r_link.next = r; - else + if (do_glink) { + p->r_glink.next = r; + } + } else { list = r; + } } - return (list); } int -res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int length) { +res_mkupdate(ns_updrec *rrecp_in, uchar_t *buf, int length) { __ISC_ns_updrec *r; int ret; - if ((r = copy_list(rrecp_in)) == 0) + if ((r = copy_list(rrecp_in, 1)) == 0) return (-1); ret = __ISC_res_mkupdate(r, buf, length); @@ -148,6 +163,22 @@ res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int length) { return (ret); } +int +res_nmkupdate(res_state statp, ns_updrec *rrecp_in, uchar_t *buf, int length) { + + __ISC_ns_updrec *r; + int ret; + + if ((r = copy_list(rrecp_in, 1)) == 0) + return (-1); + + ret = __ISC_res_nmkupdate(statp, r, buf, length); + + delete_list(r); + + return (ret); +} + int res_update(ns_updrec *rrecp_in) { @@ -155,7 +186,7 @@ res_update(ns_updrec *rrecp_in) { __ISC_ns_updrec *r; int ret; - if ((r = copy_list(rrecp_in)) == 0) + if ((r = copy_list(rrecp_in, 0)) == 0) return (-1); ret = __ISC_res_update(r); @@ -165,6 +196,22 @@ res_update(ns_updrec *rrecp_in) { return (ret); } +int +res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) { + + __ISC_ns_updrec *r; + int ret; + + if ((r = copy_list(rrecp_in, 0)) == 0) + return (-1); + + ret = __ISC_res_nupdate(statp, r, key); + + delete_list(r); + + return (ret); +} + ns_updrec * diff --git a/usr/src/lib/libresolv2/common/sunw/sunw_wrappers.c b/usr/src/lib/libresolv2/common/sunw/sunw_wrappers.c new file mode 100644 index 0000000000..c69d7c5917 --- /dev/null +++ b/usr/src/lib/libresolv2/common/sunw/sunw_wrappers.c @@ -0,0 +1,23 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include <port_before.h> +#include <resolv.h> +#include <arpa/inet.h> +#include <port_after.h> + +#undef p_option +/* extern const char * isc_p_option(); */ +const char *p_option(uint_t option) { + return (isc_p_option((ulong_t)option)); +} +#pragma weak __p_option = p_option + +#undef p_secstodate +/* extern char * isc_p_secstodate (); */ +char *p_secstodate(uint_t secs) { + return (isc_p_secstodate((ulong_t)secs)); +} +#pragma weak __p_secstodate = p_secstodate diff --git a/usr/src/lib/libresolv2/dnssafe/Makefile b/usr/src/lib/libresolv2/dnssafe/Makefile deleted file mode 100644 index 6fc0de71a4..0000000000 --- a/usr/src/lib/libresolv2/dnssafe/Makefile +++ /dev/null @@ -1,80 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2008 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# - -include ../../../Makefile.master -include ../../Makefile.lib - -SUBDIRS = $(MACH) -$(BUILD64)SUBDIRS += $(MACH64) - -all := TARGET= all -clean := TARGET= clean -clobber := TARGET= clobber -delete := TARGET= delete -install := TARGET= install -lint := TARGET= lint -_msg := TARGET= _msg -package := TARGET= package - -LIBRARY= dnssafe.a -TEXT_DOMAIN= SUNW_OST_OSLIB -XGETFLAGS= -a -POFILE= $(LIBRARY:.a=.po) -POFILES= generic.po - -SED= sed -GREP= grep - -.KEEP_STATE: - -all clean clobber delete install lint package: $(SUBDIRS) - -# install rule for install_h target -$(ROOTHDRDIR)/%: % - $(INS.file) - -install_h: $(ROOTHDRS) - -check: $(CHECKHDRS) - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -_msg: $(MSGDOMAIN) $(POFILE) - $(RM) $(MSGDOMAIN)/$(POFILE) - $(CP) $(POFILE) $(MSGDOMAIN) - -$(POFILE): $(POFILES) - $(RM) $@ - $(CAT) $(POFILES) > $@ - -$(POFILES): - $(RM) messages.po - $(XGETTEXT) $(XGETFLAGS) *.[ch]* */*.[ch]* - $(SED) -e '/^# msg/d' -e '/^domain/d' messages.po > $@ - $(RM) messages.po - -FRC: diff --git a/usr/src/lib/libresolv2/dnssafe/Makefile.com b/usr/src/lib/libresolv2/dnssafe/Makefile.com deleted file mode 100644 index 980ac7a77b..0000000000 --- a/usr/src/lib/libresolv2/dnssafe/Makefile.com +++ /dev/null @@ -1,104 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2007 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# - -LIBRARY= dnssafe.a -VERS= .1 - -DSTOBJS= bsafe_link.o hmac_link.o rsaref_link.o eay_dss_link.o - -DNSSAFEOBJS= ahcbcpad.o ahchdig.o ahchencr.o ahchgen.o \ - ahchrand.o ahdigest.o ahencryp.o ahgen.o \ - ahrandom.o ahrsaenc.o ahrsaepr.o ahrsaepu.o \ - aichdig.o aichenc8.o aichencn.o aichencr.o \ - aichgen.o aichrand.o aimd5.o aimd5ran.o \ - ainfotyp.o ainull.o airsaepr.o airsaepu.o \ - airsakgn.o airsaprv.o airsapub.o algchoic.o \ - algobj.o amcrte.o ammd5.o ammd5r.o \ - amrkg.o amrsae.o balg.o bgclrbit.o \ - bgmdmpyx.o bgmdsqx.o bgmodexp.o bgpegcd.o \ - big2exp.o bigabs.o bigacc.o bigarith.o \ - bigcmp.o bigconst.o biginv.o biglen.o \ - bigmodx.o bigmpy.o bigpdiv.o bigpmpy.o \ - bigpmpyh.o bigpmpyl.o bigpsq.o bigqrx.o \ - bigsmod.o bigtocan.o bigu.o bigunexp.o \ - binfocsh.o bkey.o bmempool.o cantobig.o \ - crt2.o digest.o digrand.o encrypt.o \ - generate.o intbits.o intitem.o keyobj.o \ - ki8byte.o kifulprv.o kiitem.o kinfotyp.o \ - kipkcrpr.o kirsacrt.o kirsapub.o \ - md5rand.o prime.o random.o rsa.o \ - rsakeygn.o seccbcd.o seccbce.o surrendr.o - -OBJECTS= $(DSTOBJS) $(DNSSAFEOBJS) - -include ../../../Makefile.lib - -LIBNAME= $(LIBRARY:%.a=%) -LIBS= $(DYNLIB) -LDLIBS += -lmd -lresolv -lc - -MAPFILES = ../mapfile-vers - -SRCDIR= ../../common/dnssafe -SRCS= $(DSTOBJS:%.o=../../common/dst/%.c) \ - $(DNSSAFEOBJS:%.o=$(SRCDIR)/%.c) - -ROOTLIBDIR= $(ROOT)/usr/lib/dns -ROOTLIBDIR64= $(ROOT)/usr/lib/dns/$(MACH64) - - -# Local Libresolv definitions -SOLCOMPAT = -Dgethostbyname=res_gethostbyname \ - -Dgethostbyaddr=res_gethostbyaddr -Dgetnetbyname=res_getnetbyname \ - -Dgethostbyname2=res_gethostbyname2\ - -Dgetnetbyaddr=res_getnetbyaddr -Dsethostent=res_sethostent \ - -Dendhostent=res_endhostent -Dgethostent=res_gethostent \ - -Dsetnetent=res_setnetent -Dendnetent=res_endnetent \ - -Dgetnetent=res_getnetent -Dsocket=_socket - -CRYPTINCL= -I../../common/cylink -I../../common/dnssafe -CRYPTFLAGS= -DCYLINK_DSS -DHMAC_MD5 -DUSE_MD5 -DDNSSAFE \ - -D__SUNW_DST_INIT_NODEFINE - -CPPFLAGS += $(CRYPTFLAGS) $(CRYPTINCL) -CPPFLAGS += -D_SYS_STREAM_H -D_REENTRANT -DSVR4 -DSUNW_OPTIONS \ - $(SOLCOMPAT) -I../../include -I../../../common/inc - -.KEEP_STATE: - -all: $(LIBS) - -lint: lintcheck - -$(ROOTLIBDIR) $(ROOTLIBDIR64): - $(INS.dir) - -include ../../../Makefile.targ - -pics/%.o: ../../common/dst/%.c - $(COMPILE.c) -o $@ $< - $(POST_PROCESS_O) diff --git a/usr/src/lib/libresolv2/dnssafe/amd64/Makefile b/usr/src/lib/libresolv2/dnssafe/amd64/Makefile deleted file mode 100644 index 8df6381cfa..0000000000 --- a/usr/src/lib/libresolv2/dnssafe/amd64/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# - -include ../Makefile.com -include ../../../Makefile.lib.64 - -all: $(LIBS) - -install: all $(ROOTLIBDIR64) .WAIT $(ROOTLIBS64) diff --git a/usr/src/lib/libresolv2/dnssafe/i386/Makefile b/usr/src/lib/libresolv2/dnssafe/i386/Makefile deleted file mode 100644 index 5377e53c07..0000000000 --- a/usr/src/lib/libresolv2/dnssafe/i386/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# -# lib/libresolv2/dnssafe/i386/Makefile -# - -include ../Makefile.com - -install: all $(ROOTLIBDIR) .WAIT $(ROOTLIBS) diff --git a/usr/src/lib/libresolv2/dnssafe/mapfile-vers b/usr/src/lib/libresolv2/dnssafe/mapfile-vers deleted file mode 100644 index edb9b13360..0000000000 --- a/usr/src/lib/libresolv2/dnssafe/mapfile-vers +++ /dev/null @@ -1,48 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -# -# MAPFILE HEADER START -# -# WARNING: STOP NOW. DO NOT MODIFY THIS FILE. -# Object versioning must comply with the rules detailed in -# -# usr/src/lib/README.mapfiles -# -# You should not be making modifications here until you've read the most current -# copy of that file. If you need help, contact a gatekeeper for guidance. -# -# MAPFILE HEADER END -# - -SUNWprivate_1.1 { - global: - dst_bsafe_init; - dst_eay_dss_init; - dst_md5_hmac_init; - dst_rsaref_init; - local: - *; -}; diff --git a/usr/src/lib/libresolv2/dnssafe/sparc/Makefile b/usr/src/lib/libresolv2/dnssafe/sparc/Makefile deleted file mode 100644 index f8244e9564..0000000000 --- a/usr/src/lib/libresolv2/dnssafe/sparc/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# -# lib/libresolv2/dnssafe/sparc/Makefile -# - -include ../Makefile.com - -install: all $(ROOTLIBDIR) .WAIT $(ROOTLIBS) diff --git a/usr/src/lib/libresolv2/dnssafe/sparcv9/Makefile b/usr/src/lib/libresolv2/dnssafe/sparcv9/Makefile deleted file mode 100644 index 2737e64129..0000000000 --- a/usr/src/lib/libresolv2/dnssafe/sparcv9/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# -# lib/libresolv2/dnssafe/sparcv9/Makefile -# - -include ../Makefile.com -include ../../../Makefile.lib.64 - -install: all $(ROOTLIBDIR64) .WAIT $(ROOTLIBS64) diff --git a/usr/src/lib/libresolv2/include/arpa/port_inet.h b/usr/src/lib/libresolv2/include/arpa/port_inet.h new file mode 100644 index 0000000000..5eb1787f56 --- /dev/null +++ b/usr/src/lib/libresolv2/include/arpa/port_inet.h @@ -0,0 +1,41 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * + * All rights reserved. + */ + +#ifndef _ARPA_PORT_INET_H +#define _ARPA_PORT_INET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * these are libresolv2 functions that were made local in previous versions + * we rename them res_* because they conflict with libnsl or libsocket + */ + +#define inet_lnaof res_inet_lnaof /* libsocket */ +ulong_t inet_lnaof(struct in_addr in); + +#define inet_makeaddr res_inet_makeaddr /* libsocket */ +struct in_addr inet_makeaddr(ulong_t net, ulong_t host); + +#define inet_netof res_inet_netof /* libnsl */ +ulong_t inet_netof(struct in_addr in); + +#define inet_network res_inet_network /* libsocket */ +ulong_t inet_network(register const char *cp); + +#ifdef __cplusplus +} +#endif + + + +#endif /* _ARPA_PORT_INET_H */ diff --git a/usr/src/lib/libresolv2/include/arpa/port_nameser.h b/usr/src/lib/libresolv2/include/arpa/port_nameser.h new file mode 100644 index 0000000000..b40ea0d163 --- /dev/null +++ b/usr/src/lib/libresolv2/include/arpa/port_nameser.h @@ -0,0 +1,40 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _ARPA_PORT_NAMESER_H +#define _ARPA_PORT_NAMESER_H + +/* + * ISC changed the ns_updrec structure. However, it's a public interface + * in Solaris, so we rename it here and wrap in sunw_updrec.c + */ +#define ns_updrec __ISC_ns_updrec + + +/* + * Due to the above, the following functions need to be renamed and + * wrapped in sunw_updrec.c. + * + * For BIND 8.2.2, ISC removed the dynamic update functions, and the + * definition of the ns_updrec structure, from the public include files + * (<resolv.h>, <arpa/nameser.h>. However, res_update(), res_mkupdate(), + * and res_mkupdrec() are in the public libresolv interface in Solaris, + * so we can't easily remove them. Thus, ISC's new versions of res_mkupdate() + * etc. can't be exposed under their original names. + * + * res_nmkupdate() and res_nupdate are new. We could either change them + * to accept the <arpa/nameser.h> ns_updrec, or leave them unchanged and + * undocumented. Since ISC may change ns_updrec again, we pick the latter + * solution for now. + */ +#define res_mkupdate __ISC_res_mkupdate +#define res_update __ISC_res_update +#define res_mkupdrec __ISC_res_mkupdrec +#define res_freeupdrec __ISC_res_freeupdrec +#define res_nmkupdate __ISC_res_nmkupdate +#define res_nupdate __ISC_res_nupdate + + +#endif /* _ARPA_PORT_NAMESER_H */ diff --git a/usr/src/lib/libresolv2/include/conf/sunoptions.h b/usr/src/lib/libresolv2/include/conf/sunoptions.h index afdf7e3f78..b75ff9d878 100644 --- a/usr/src/lib/libresolv2/include/conf/sunoptions.h +++ b/usr/src/lib/libresolv2/include/conf/sunoptions.h @@ -1,50 +1,23 @@ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _SUNOPTIONS_H #define _SUNOPTIONS_H -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * The following options are PP flags available in the reference implementation - * but do not get compiled due to the elimination of the options.h file - * This section selectively reintroduces them - */ - -#define HAVE_GETRUSAGE - -/* - * The following options are PP flags introduced as part of the Sun/Solaris - * port. - */ - -/* We may have to pull this out */ -#define SUNW_LIBNSL /* conflicts for inet_addr, inet_ntoa */ +#define USELOOPBACK /* Resolver library defaults to 127.0.0.1 */ /* Additions for Solaris 2 */ -#define SUNW_NSSEARCH /* fix nslookup domain search */ -#define SUNW_AVOIDOVERFLOW /* Avoid buffer overflows */ -#define SUNW_INITCHKIF /* Check if any non-loopback interface is up */ -#define SUNW_DOMAINFROMNIS /* Default domain name from NIS/NIS+ */ -#define USELOOPBACK /* Resolver library defaults to 127.0.0.1 */ -#define SUNW_CONFCHECK /* Abort quickly if no /etc/resolv.conf or local */ - /* named */ -#define SUNW_AREWEINNAMED /* Override _confcheck if proc is in.named */ -#define SUNW_OPENFDOFFSET /* Open non-stdio fd:s with offset */ -#define SUNW_POLL /* Use poll(2) instead of select(3) */ + +#define SUNW_INITCHKIF /* Check if any non-loopback interface is up */ +#define SUNW_CONFCHECK /* Abort quickly if no /etc/resolv.conf or */ + /* local named */ #define SUNW_HOSTS_FALLBACK /* Configurable /etc/hosts fallback */ -#define SUNW_LISTEN_BACKLOG /* Configurable listen(3N) backlog (named) */ -#define SUNW_REJECT_BOGUS_H_LENGTH /* (libresolv) */ #define SUNW_HNOK_UNDERSCORE /* Allow underscore in hostnames (libresolv) */ #define SUNW_MT_RESOLVER /* MT hot extensions (libresolv) */ -#define SUNW_QSTREAM_CLEANUP /* Avoid using free()d struct qstreams */ #define SUNW_SETHERRNO /* ISC does not set h_errno in gethostbyname */ #define SUNW_OVERRIDE_RETRY /* Allow NS switch to override res->retry */ -#define SUNW_CLOSEFROM /* closefrom(3C) per PSARC 2000/193 */ -#define SUNW_AVOIDSTDIO_FDLIMIT /* Avoid 256 file descriptor limit in stdio */ #define SUNW_LIBMD5 /* Use md5(3EXT) instead of internal implementation */ /* If compiling an MT warm libresolv, we also need reentrancy */ @@ -52,11 +25,6 @@ #define _REENTRANT #endif -/* SUNW_AREWEINNAMED and SUNW_CONFCHECCK are mutually inclusive */ -#if defined(SUNW_AREWEINNAMED) && !defined(SUNW_CONFCHECK) -#define SUNW_CONFCHECK -#endif - /* End additions for Solaris 2 */ #endif /* _SUNOPTIONS_H */ diff --git a/usr/src/lib/libresolv2/include/config.h b/usr/src/lib/libresolv2/include/config.h new file mode 100644 index 0000000000..35fb115a0f --- /dev/null +++ b/usr/src/lib/libresolv2/include/config.h @@ -0,0 +1,75 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +/* config.h. Generated from config.h.in by configure. */ +/* #undef _SOCKADDR_LEN */ +#define HAVE_FCNTL_H 1 +/* #undef HAVE_PATHS_H */ +#define HAVE_INTTYPES_H 1 +#define HAVE_STROPTS_H 1 +/* #undef HAVE_SYS_TIMERS_H */ +#define HAVE_SYS_SELECT_H 1 +#define HAVE_MEMORY_H 1 +/* #undef SYS_CDEFS_H */ +#define _POSIX_PTHREAD_SEMANTICS 1 +#define POSIX_GETPWUID_R 1 +#define POSIX_GETPWNAM_R 1 +#define POSIX_GETGRGID_R 1 +#define POSIX_GETGRNAM_R 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MEMCHR 1 +/* #undef SPRINTF_CHAR */ +/* #undef VSPRINTF_CHAR */ +#define USE_SYSERROR_LIST 1 +/* #undef NEED_STRTOUL */ +/* #undef NEED_SUN4PROTOS */ +/* #undef REENABLE_SEND */ + +#define NEED_SETGROUPENT 1 +#define NEED_GETGROUPLIST 1 + +/* define if prototype for getgrnam_r() is required */ +/* #undef NEED_GETGRNAM_R */ +/* #undef NEED_GETGRGID_R */ +/* #undef NEED_GETGRENT_R */ +#define NEED_SETGRENT_R 1 +#define NEED_ENDGRENT_R 1 + +#define NEED_INNETGR_R 1 +/* #undef NEED_SETNETGRENT_R */ +#define NEED_ENDNETGRENT_R 1 + +/* #undef NEED_GETPWNAM_R */ +/* #undef NEED_GETPWUID_R */ +#define NEED_SETPWENT_R 1 +#define NEED_SETPASSENT_R 1 +#define NEED_SETPWENT_R 1 +/* #undef NEED_GETPWENT_R */ +#define NEED_ENDPWENT_R 1 + +#define NEED_SETPASSENT 1 + +/* #undef HAS_PW_CLASS */ + +/* #undef ssize_t */ +/* #undef uintptr_t */ + +/* Shut up warnings about sputaux in stdio.h on BSD/OS pre-4.1 */ +/* #undef SHUTUP_SPUTAUX */ +#ifdef SHUTUP_SPUTAUX +struct __sFILE; +extern __inline int __sputaux(int _c, struct __sFILE *_p); +#endif +#define BROKEN_IN6ADDR_INIT_MACROS 1 +#define HAVE_STRLCAT 1 +/* Shut up warnings about missing braces */ +/* #undef SHUTUP_MUTEX_INITIALIZER */ +#ifdef SHUTUP_MUTEX_INITIALIZER +#define LIBBIND_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER } +#else +#define LIBBIND_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER +#endif + diff --git a/usr/src/lib/libresolv2/include/fd_setsize.h b/usr/src/lib/libresolv2/include/fd_setsize.h index f6af1b2488..0e21049742 100644 --- a/usr/src/lib/libresolv2/include/fd_setsize.h +++ b/usr/src/lib/libresolv2/include/fd_setsize.h @@ -1,18 +1,10 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - * - * No ISC copyright for this file. - */ - #ifndef _FD_SETSIZE_H #define _FD_SETSIZE_H -#pragma ident "%Z%%M% %I% %E% SMI" - -/* +/*% * If you need a bigger FD_SETSIZE, this is NOT the place to set it. * This file is a fallback for BIND ports which don't specify their own. */ #endif /* _FD_SETSIZE_H */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/hesiod.h b/usr/src/lib/libresolv2/include/hesiod.h index 5f113734c8..d64c0c5e80 100644 --- a/usr/src/lib/libresolv2/include/hesiod.h +++ b/usr/src/lib/libresolv2/include/hesiod.h @@ -1,47 +1,39 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - -/* +/*! \file + * \brief * This file is primarily maintained by <tytso@mit.edu> and <ghudson@mit.edu>. */ /* - * $Id: hesiod.h,v 1.7 1999/01/08 19:22:45 vixie Exp $ + * $Id: hesiod.h,v 1.4 2005/04/27 04:56:14 sra Exp $ */ #ifndef _HESIOD_H_INCLUDED #define _HESIOD_H_INCLUDED -int hesiod_init __P((void **context)); -void hesiod_end __P((void *context)); -char * hesiod_to_bind __P((void *context, const char *name, - const char *type)); -char ** hesiod_resolve __P((void *context, const char *name, - const char *type)); -void hesiod_free_list __P((void *context, char **list)); -struct __res_state * __hesiod_res_get __P((void *context)); -void __hesiod_res_set __P((void *context, struct __res_state *, +int hesiod_init __P((void **)); +void hesiod_end __P((void *)); +char * hesiod_to_bind __P((void *, const char *, const char *)); +char ** hesiod_resolve __P((void *, const char *, const char *)); +void hesiod_free_list __P((void *, char **)); +struct __res_state * __hesiod_res_get __P((void *)); +void __hesiod_res_set __P((void *, struct __res_state *, void (*)(void *))); #endif /*_HESIOD_H_INCLUDED*/ diff --git a/usr/src/lib/libresolv2/include/inet_private.h b/usr/src/lib/libresolv2/include/inet_private.h deleted file mode 100644 index c9c03ab478..0000000000 --- a/usr/src/lib/libresolv2/include/inet_private.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#ifndef _INET_PRIVATE_H -#define _INET_PRIVATE_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Functions defined by the ISC for BIND 8.2, but which do not appear - * in RFC 2553 (hence, aren't suitable for inclusion in <inet.h>). - */ - -#ifdef __STDC__ -#ifndef __P -#define __P(x) x -#endif -#else -#ifndef __P -#define __P(x) () -#endif -#endif /* __STDC__ */ - -char * inet_net_ntop __P((int, const void *, int, char *, size_t)); -int inet_net_pton __P((int, const char *, void *, size_t)); -u_int inet_nsap_addr __P((const char *, u_char *, int)); -char * inet_nsap_ntoa __P((int, const u_char *, char *)); - -#endif /* _INET_PRIVATE_H */ diff --git a/usr/src/lib/libresolv2/include/irp.h b/usr/src/lib/libresolv2/include/irp.h index 76b7b23441..1290bd068f 100644 --- a/usr/src/lib/libresolv2/include/irp.h +++ b/usr/src/lib/libresolv2/include/irp.h @@ -1,39 +1,33 @@ /* - * Copyright 2003 by Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* - * $Id: irp.h,v 8.4 2003/05/02 05:56:21 marka Exp $ + * $Id: irp.h,v 1.4 2005/04/27 04:56:15 sra Exp $ */ #ifndef _IRP_H_INCLUDED #define _IRP_H_INCLUDED -#pragma ident "%Z%%M% %I% %E% SMI" +/*! \file */ -#define IRPD_TIMEOUT 30 /* seconds */ -#define IRPD_MAXSESS 50 /* number of simultaneous sessions. */ -#define IRPD_PORT 6660 /* 10 times the number of the beast. */ -#define IRPD_PATH "/var/run/irpd" /* af_unix socket path */ +#define IRPD_TIMEOUT 30 /*%< seconds */ +#define IRPD_MAXSESS 50 /*%< number of simultaneous sessions. */ +#define IRPD_PORT 6660 /*%< 10 times the number of the beast. */ +#define IRPD_PATH "/var/run/irpd" /*%< af_unix socket path */ /* If sets the environment variable IRPDSERVER to an IP address (e.g. "192.5.5.1"), then that's the host the client expects irpd to be @@ -92,21 +86,22 @@ struct irp_p; -char *irs_irp_read_body(struct irp_p *pvt, size_t *size); -int irs_irp_read_response(struct irp_p *pvt, char *text, size_t len); -void irs_irp_disconnect(struct irp_p *pvt); -int irs_irp_connect(struct irp_p *pvt); -int irs_irp_is_connected(struct irp_p *pvt); -int irs_irp_connection_setup(struct irp_p *cxndata, int *warned); -#ifdef __GNUC__ +char *irs_irp_read_body(struct irp_p *, size_t *); +int irs_irp_read_response(struct irp_p *, char *, size_t); +void irs_irp_disconnect(struct irp_p *); +int irs_irp_connect(struct irp_p *); +int irs_irp_is_connected(struct irp_p *); +int irs_irp_connection_setup(struct irp_p *, int *); +#ifdef __GNUC__ int irs_irp_send_command(struct irp_p *, const char *, ...) - __attribute__((__format__(__printf__, 2, 3))); + __attribute__((__format__(__printf__, 2, 3))); #else -int irs_irp_send_command(struct irp_p *pvt, const char *fmt, ...); +int irs_irp_send_command(struct irp_p *, const char *, ...); #endif -int irs_irp_get_full_response(struct irp_p *pvt, int *code, char *text, - size_t textlen, char **body, - size_t *bodylen); -int irs_irp_read_line(struct irp_p *pvt, char *buffer, int len); +int irs_irp_get_full_response(struct irp_p *, int *, char *, size_t, + char **, size_t *); +int irs_irp_read_line(struct irp_p *, char *, int); #endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/irs.h b/usr/src/lib/libresolv2/include/irs.h index d676136ac9..42d4890dfd 100644 --- a/usr/src/lib/libresolv2/include/irs.h +++ b/usr/src/lib/libresolv2/include/irs.h @@ -1,34 +1,29 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* - * $Id: irs.h,v 8.9 2003/04/29 05:51:13 marka Exp $ + * $Id: irs.h,v 1.5 2005/04/27 04:56:15 sra Exp $ */ #ifndef _IRS_H_INCLUDED #define _IRS_H_INCLUDED +/*! \file */ + #include <sys/types.h> #include <arpa/nameser.h> @@ -38,7 +33,7 @@ #include <resolv.h> #include <pwd.h> -/* +/*% * This is the group map class. */ struct irs_gr { @@ -56,7 +51,7 @@ struct irs_gr { void (*)(void *))); }; -/* +/*% * This is the password map class. */ struct irs_pw { @@ -72,7 +67,7 @@ struct irs_pw { void (*)(void *))); }; -/* +/*% * This is the service map class. */ struct irs_sv { @@ -89,7 +84,7 @@ struct irs_sv { void (*)(void *))); }; -/* +/*% * This is the protocols map class. */ struct irs_pr { @@ -105,7 +100,7 @@ struct irs_pr { void (*)(void *))); }; -/* +/*% * This is the hosts map class. */ struct irs_ho { @@ -125,7 +120,7 @@ struct irs_ho { const struct addrinfo *)); }; -/* +/*% * This is the networks map class. */ struct irs_nw { @@ -141,7 +136,7 @@ struct irs_nw { void (*)(void *))); }; -/* +/*% * This is the netgroups map class. */ struct irs_ng { @@ -156,7 +151,7 @@ struct irs_ng { void (*minimize) __P((struct irs_ng *)); }; -/* +/*% * This is the generic map class, which copies the front of all others. */ struct irs_map { @@ -164,7 +159,7 @@ struct irs_map { void (*close) __P((void *)); }; -/* +/*% * This is the accessor class. It contains pointers to all of the * initializers for the map classes for a particular accessor. */ @@ -183,21 +178,21 @@ struct irs_acc { void (*)(void *))); }; -/* +/*% * This is because the official definition of "struct netent" has no * concept of CIDR even though it allows variant address families (on * output but not input). The compatibility stubs convert the structs * below into "struct netent"'s. */ struct nwent { - char *n_name; /* official name of net */ - char **n_aliases; /* alias list */ - int n_addrtype; /* net address type */ - void *n_addr; /* network address */ - int n_length; /* address length, in bits */ + char *n_name; /*%< official name of net */ + char **n_aliases; /*%< alias list */ + int n_addrtype; /*%< net address type */ + void *n_addr; /*%< network address */ + int n_length; /*%< address length, in bits */ }; -/* +/*% * Hide external function names from POSIX. */ #define irs_gen_acc __irs_gen_acc @@ -205,10 +200,7 @@ struct nwent { #define irs_dns_acc __irs_dns_acc #define irs_nis_acc __irs_nis_acc #define irs_irp_acc __irs_irp_acc -#ifdef ORIGINAL_ISC_CODE #define irs_destroy __irs_destroy -#else -#endif #define irs_dns_gr __irs_dns_gr #define irs_dns_ho __irs_dns_ho #define irs_dns_nw __irs_dns_nw @@ -248,24 +240,20 @@ struct nwent { #define irs_nis_sv __irs_nis_sv #define net_data_create __net_data_create #define net_data_destroy __net_data_destroy -#ifdef ORIGINAL_ISC_CODE #define net_data_minimize __net_data_minimize -#else -#endif -/* +/*% * Externs. */ -extern struct irs_acc * irs_gen_acc __P((const char *options, - const char *conf_file)); -extern struct irs_acc * irs_lcl_acc __P((const char *options)); -extern struct irs_acc * irs_dns_acc __P((const char *options)); -extern struct irs_acc * irs_nis_acc __P((const char *options)); -extern struct irs_acc * irs_irp_acc __P((const char *options)); +extern struct irs_acc * irs_gen_acc __P((const char *, const char *)); +extern struct irs_acc * irs_lcl_acc __P((const char *)); +extern struct irs_acc * irs_dns_acc __P((const char *)); +extern struct irs_acc * irs_nis_acc __P((const char *)); +extern struct irs_acc * irs_irp_acc __P((const char *)); -extern void irs_destroy(void); +extern void irs_destroy __P((void)); -/* +/*% * These forward declarations are for the semi-private functions in * the get*.c files. Each of these funcs implements the real get* * functionality and the standard versions are just wrappers that @@ -274,110 +262,87 @@ extern void irs_destroy(void); * the /usr/include replacements. */ -struct net_data; /* forward */ - +struct net_data; /*%< forward */ /* * net_data_create gets a singleton net_data object. net_data_init * creates as many net_data objects as times it is called. Clients using * the default interface will use net_data_create by default. Servers will * probably want net_data_init (one call per client) */ -struct net_data *net_data_create(const char *conf_file); -struct net_data *net_data_init(const char *conf_file); -void net_data_destroy(void *p); +struct net_data *net_data_create __P((const char *)); +struct net_data *net_data_init __P((const char *)); +void net_data_destroy __P((void *)); -extern struct group *getgrent_p __P((struct net_data *net_data)); -extern struct group *getgrnam_p __P((const char *name, - struct net_data *net_data)); -extern struct group *getgrgid_p __P((gid_t gid, - struct net_data *net_data)); -extern int setgroupent_p __P((int stayopen, - struct net_data *net_data)); -extern void endgrent_p __P((struct net_data *net_data)); -extern int getgrouplist_p __P((const char *name, - gid_t basegid, - gid_t *groups, - int *ngroups, - struct net_data *net_data)); +extern struct group *getgrent_p __P((struct net_data *)); +extern struct group *getgrnam_p __P((const char *, struct net_data *)); +extern struct group *getgrgid_p __P((gid_t, struct net_data *)); +extern int setgroupent_p __P((int, struct net_data *)); +extern void endgrent_p __P((struct net_data *)); +extern int getgrouplist_p __P((const char *, gid_t, gid_t *, int *, + struct net_data *)); #ifdef SETGRENT_VOID -extern void setgrent_p __P((struct net_data *net_data)); +extern void setgrent_p __P((struct net_data *)); #else -extern int setgrent_p __P((struct net_data *net_data)); +extern int setgrent_p __P((struct net_data *)); #endif -extern struct hostent *gethostbyname_p __P((const char *name, - struct net_data *net_data)); -extern struct hostent *gethostbyname2_p __P((const char *name, int af, - struct net_data *net_data)); -extern struct hostent *gethostbyaddr_p __P((const char *addr, int len, - int af, - struct net_data *net_data)); -extern struct hostent *gethostent_p __P((struct net_data *net_data)); -extern void sethostent_p __P((int stayopen, - struct net_data *net_data)); -extern void endhostent_p __P((struct net_data *net_data)); -extern struct hostent *getipnodebyname_p __P((const char *name, int af, - int flags, int *errp, - struct net_data *net_data)); -extern struct hostent *getipnodebyaddr_p __P((const void *addr, size_t len, - int af, int *errp, - struct net_data *net_data)); - -extern struct netent *getnetent_p __P((struct net_data *net_data)); -extern struct netent *getnetbyname_p __P((const char *name, - struct net_data *net_data)); -extern struct netent *getnetbyaddr_p __P((unsigned long net, int type, - struct net_data *net_data)); -extern void setnetent_p __P((int stayopen, - struct net_data *net_data)); -extern void endnetent_p __P((struct net_data *net_data)); - -extern void setnetgrent_p __P((const char *netgroup, - struct net_data *net_data)); -extern void endnetgrent_p __P((struct net_data *net_data)); -extern int innetgr_p __P((const char *netgroup, - const char *host, - const char *user, - const char *domain, - struct net_data *net_data)); -extern int getnetgrent_p __P((const char **host, const char **user, - const char **domain, - struct net_data *net_data)); - -extern struct protoent *getprotoent_p __P((struct net_data *net_data)); -extern struct protoent *getprotobyname_p __P((const char *name, - struct net_data *net_data)); -extern struct protoent *getprotobynumber_p __P((int proto, - struct net_data *net_data)); -extern void setprotoent_p __P((int stayopen, - struct net_data *net_data)); -extern void endprotoent_p __P((struct net_data *net_data)); - - -extern struct passwd *getpwent_p __P((struct net_data *net_data)); -extern struct passwd *getpwnam_p __P((const char *name, - struct net_data *net_data)); -extern struct passwd *getpwuid_p __P((uid_t uid, - struct net_data *net_data)); -extern int setpassent_p __P((int stayopen, - struct net_data *net_data)); -extern void endpwent_p __P((struct net_data *net_data)); +extern struct hostent *gethostbyname_p __P((const char *, + struct net_data *)); +extern struct hostent *gethostbyname2_p __P((const char *, int, + struct net_data *)); +extern struct hostent *gethostbyaddr_p __P((const char *, int, int, + struct net_data *)); +extern struct hostent *gethostent_p __P((struct net_data *)); +extern void sethostent_p __P((int, struct net_data *)); +extern void endhostent_p __P((struct net_data *)); +extern struct hostent *getipnodebyname_p __P((const char *, int, int, int *, + struct net_data *)); +extern struct hostent *getipnodebyaddr_p __P((const void *, size_t, + int, int *, struct net_data *)); + +extern struct netent *getnetent_p __P((struct net_data *)); +extern struct netent *getnetbyname_p __P((const char *, struct net_data *)); +extern struct netent *getnetbyaddr_p __P((unsigned long, int, + struct net_data *)); +extern void setnetent_p __P((int, struct net_data *)); +extern void endnetent_p __P((struct net_data *)); + +extern void setnetgrent_p __P((const char *, struct net_data *)); +extern void endnetgrent_p __P((struct net_data *)); +extern int innetgr_p __P((const char *, const char *, const char *, + const char *, struct net_data *)); +extern int getnetgrent_p __P((const char **, const char **, + const char **, struct net_data *)); + +extern struct protoent *getprotoent_p __P((struct net_data *)); +extern struct protoent *getprotobyname_p __P((const char *, + struct net_data *)); +extern struct protoent *getprotobynumber_p __P((int, struct net_data *)); +extern void setprotoent_p __P((int, struct net_data *)); +extern void endprotoent_p __P((struct net_data *)); + + +extern struct passwd *getpwent_p __P((struct net_data *)); +extern struct passwd *getpwnam_p __P((const char *, struct net_data *)); +extern struct passwd *getpwuid_p __P((uid_t, struct net_data *)); +extern int setpassent_p __P((int, struct net_data *)); +extern void endpwent_p __P((struct net_data *)); #ifdef SETPWENT_VOID -extern void setpwent_p __P((struct net_data *net_data)); +extern void setpwent_p __P((struct net_data *)); #else -extern int setpwent_p __P((struct net_data *net_data)); +extern int setpwent_p __P((struct net_data *)); #endif -extern struct servent *getservent_p __P((struct net_data *net_data)); -extern struct servent *getservbyname_p __P((const char *name, - const char *proto, - struct net_data *net_data)); -extern struct servent *getservbyport_p __P((int port, const char *proto, - struct net_data *net_data)); -extern void setservent_p __P((int stayopen, - struct net_data *net_data)); -extern void endservent_p __P((struct net_data *net_data)); +extern struct servent *getservent_p __P((struct net_data *)); +extern struct servent *getservbyname_p __P((const char *, const char *, + struct net_data *)); +extern struct servent *getservbyport_p __P((int, const char *, + struct net_data *)); +extern void setservent_p __P((int, struct net_data *)); +extern void endservent_p __P((struct net_data *)); #endif /*_IRS_H_INCLUDED*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/isc/assertions.h b/usr/src/lib/libresolv2/include/isc/assertions.h index 1f02d666ce..68925e73b3 100644 --- a/usr/src/lib/libresolv2/include/isc/assertions.h +++ b/usr/src/lib/libresolv2/include/isc/assertions.h @@ -1,29 +1,22 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Copyright (c) 1997-1999 by Internet Software Consortium. + * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1997-2001 Internet Software Consortium. * - * Permission to use, copy, modify, and distribute this software for any + * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* - * $Id: assertions.h,v 8.4 2001/05/29 05:47:07 marka Exp $ + * $Id: assertions.h,v 1.5 2008/11/14 02:36:51 marka Exp $ */ #ifndef ASSERTIONS_H @@ -36,18 +29,19 @@ typedef enum { typedef void (*assertion_failure_callback)(const char *, int, assertion_type, const char *, int); +/* coverity[+kill] */ extern assertion_failure_callback __assertion_failed; void set_assertion_failure_callback(assertion_failure_callback f); const char *assertion_type_to_text(assertion_type type); -#ifdef CHECK_ALL +#if defined(CHECK_ALL) || defined(__COVERITY__) #define CHECK_REQUIRE 1 #define CHECK_ENSURE 1 #define CHECK_INSIST 1 #define CHECK_INVARIANT 1 #endif -#ifdef CHECK_NONE +#if defined(CHECK_NONE) && !defined(__COVERITY__) #define CHECK_REQUIRE 0 #define CHECK_ENSURE 0 #define CHECK_INSIST 0 @@ -125,5 +119,5 @@ const char *assertion_type_to_text(assertion_type type); #define INVARIANT(cond) ((void) (cond)) #define INVARIANT_ERR(cond) ((void) (cond)) #endif /* CHECK_INVARIANT */ - #endif /* ASSERTIONS_H */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/isc/ctl.h b/usr/src/lib/libresolv2/include/isc/ctl.h index 6b178c446a..e2ba20201d 100644 --- a/usr/src/lib/libresolv2/include/isc/ctl.h +++ b/usr/src/lib/libresolv2/include/isc/ctl.h @@ -1,34 +1,29 @@ -/* - * Copyright 2000-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - #ifndef ISC_CTL_H #define ISC_CTL_H -#pragma ident "%Z%%M% %I% %E% SMI" - /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1998,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* - * $Id: ctl.h,v 8.11 2001/08/10 02:40:49 marka Exp $ + * $Id: ctl.h,v 1.5 2005/04/27 04:56:17 sra Exp $ */ +/*! \file */ + #include <sys/types.h> #include <sys/socket.h> @@ -36,10 +31,9 @@ /* Macros. */ -#define CTL_MORE 0x0001 /* More will be / should be sent. */ -#define CTL_EXIT 0x0002 /* Close connection after this. */ -#define CTL_DATA 0x0004 /* Go into / this is DATA mode. */ - +#define CTL_MORE 0x0001 /*%< More will be / should be sent. */ +#define CTL_EXIT 0x0002 /*%< Close connection after this. */ +#define CTL_DATA 0x0004 /*%< Go into / this is DATA mode. */ /* Types. */ struct ctl_cctx; @@ -49,11 +43,11 @@ struct ctl_verb; enum ctl_severity { ctl_debug, ctl_warning, ctl_error }; -typedef void (*ctl_logfunc)(enum ctl_severity, const char *fmt, ...); +typedef void (*ctl_logfunc)(enum ctl_severity, const char *, ...); typedef void (*ctl_verbfunc)(struct ctl_sctx *, struct ctl_sess *, - const struct ctl_verb *, const char *rest, - u_int respflags, const void *respctx, void *uctx); + const struct ctl_verb *, const char *, + u_int, const void *, void *); typedef void (*ctl_srvrdone)(struct ctl_sctx *, struct ctl_sess *, void *); @@ -114,3 +108,5 @@ void * ctl_getcsctx(struct ctl_sess *); void * ctl_setcsctx(struct ctl_sess *, void *); #endif /*ISC_CTL_H*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/isc/dst.h b/usr/src/lib/libresolv2/include/isc/dst.h index 4460cf63ae..90a9e67468 100644 --- a/usr/src/lib/libresolv2/include/isc/dst.h +++ b/usr/src/lib/libresolv2/include/isc/dst.h @@ -1,25 +1,16 @@ -/* - * Copyright 2003 by Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - #ifndef DST_H #define DST_H -#pragma ident "%Z%%M% %I% %E% SMI" - #ifndef HAS_DST_KEY typedef struct dst_key { - char *dk_key_name; /* name of the key */ - int dk_key_size; /* this is the size of the key in bits */ - int dk_proto; /* what protocols this key can be used for */ - int dk_alg; /* algorithm number from key record */ - u_int32_t dk_flags; /* and the flags of the public key */ - u_int16_t dk_id; /* identifier of the key */ + char *dk_key_name; /*%< name of the key */ + int dk_key_size; /*%< this is the size of the key in bits */ + int dk_proto; /*%< what protocols this key can be used for */ + int dk_alg; /*%< algorithm number from key record */ + u_int32_t dk_flags; /*%< and the flags of the public key */ + u_int16_t dk_id; /*%< identifier of the key */ } DST_KEY; #endif /* HAS_DST_KEY */ - -#ifdef ORIGINAL_ISC_CODE /* * do not taint namespace */ @@ -36,7 +27,6 @@ typedef struct dst_key { #define dst_init __dst_init #define dst_key_to_buffer __dst_key_to_buffer #define dst_key_to_dnskey __dst_key_to_dnskey -#define dst_random __dst_random #define dst_read_key __dst_read_key #define dst_rsaref_init __dst_rsaref_init #define dst_s_build_filename __dst_s_build_filename @@ -61,8 +51,6 @@ typedef struct dst_key { #define dst_sign_data __dst_sign_data #define dst_verify_data __dst_verify_data #define dst_write_key __dst_write_key -#else -#endif /* * DST Crypto API defintions @@ -70,78 +58,64 @@ typedef struct dst_key { void dst_init(void); int dst_check_algorithm(const int); -int dst_sign_data(const int mode, /* specifies INIT/UPDATE/FINAL/ALL */ - DST_KEY *in_key, /* the key to use */ - void **context, /* pointer to state structure */ - const u_char *data, /* data to be signed */ - const int len, /* length of input data */ - u_char *signature, /* buffer to write signature to */ - const int sig_len); /* size of output buffer */ - -int dst_verify_data(const int mode, /* specifies INIT/UPDATE/FINAL/ALL */ - DST_KEY *in_key, /* the key to use */ - void **context, /* pointer to state structure */ - const u_char *data, /* data to be verified */ - const int len, /* length of input data */ - const u_char *signature,/* buffer containing signature */ - const int sig_len); /* length of signature */ - - -DST_KEY *dst_read_key(const char *in_name, /* name of key */ - const u_int16_t in_id, /* key tag identifier */ - const int in_alg, /* key algorithm */ - const int key_type); /* Private/PublicKey wanted*/ - -int dst_write_key(const DST_KEY *key, /* key to write out */ - const int key_type); /* Public/Private */ - -DST_KEY *dst_dnskey_to_key(const char *in_name, /* KEY record name */ - const u_char *key, /* KEY RDATA */ - const int len); /* size of input buffer*/ - -int dst_key_to_dnskey(const DST_KEY *key, /* key to translate */ - u_char *out_storage, /* output buffer */ - const int out_len); /* size of out_storage*/ - - -DST_KEY *dst_buffer_to_key(const char *key_name, /* name of the key */ - const int alg, /* algorithm */ - const int flags, /* dns flags */ - const int protocol, /* dns protocol */ - const u_char *key_buf, /* key in dns wire fmt */ - const int key_len); /* size of key */ - - -int dst_key_to_buffer(DST_KEY *key, u_char *out_buff, int buf_len); - -DST_KEY *dst_generate_key(const char *name, /* name of new key */ - const int alg, /* key algorithm to generate */ - const int bits, /* size of new key */ - const int exp, /* alg dependent parameter*/ - const int flags, /* key DNS flags */ - const int protocol); /* key DNS protocol */ - -DST_KEY *dst_free_key(DST_KEY *f_key); -int dst_compare_keys(const DST_KEY *key1, const DST_KEY *key2); - -int dst_sig_size(DST_KEY *key); - -int dst_random(const int mode, int wanted, u_char *outran); +int dst_sign_data(const int, /*!< specifies INIT/UPDATE/FINAL/ALL */ + DST_KEY *, /*!< the key to use */ + void **, /*!< pointer to state structure */ + const u_char *, /*!< data to be signed */ + const int, /*!< length of input data */ + u_char *, /*!< buffer to write signature to */ + const int); /*!< size of output buffer */ +int dst_verify_data(const int, /*!< specifies INIT/UPDATE/FINAL/ALL */ + DST_KEY *, /*!< the key to use */ + void **, /*!< pointer to state structure */ + const u_char *, /*!< data to be verified */ + const int, /*!< length of input data */ + const u_char *, /*!< buffer containing signature */ + const int); /*!< length of signature */ +DST_KEY *dst_read_key(const char *, /*!< name of key */ + const u_int16_t, /*!< key tag identifier */ + const int, /*!< key algorithm */ + const int); /*!< Private/PublicKey wanted */ +int dst_write_key(const DST_KEY *, /*!< key to write out */ + const int); /*!< Public/Private */ +DST_KEY *dst_dnskey_to_key(const char *, /*!< KEY record name */ + const u_char *, /*!< KEY RDATA */ + const int); /*!< size of input buffer */ +int dst_key_to_dnskey(const DST_KEY *, /*!< key to translate */ + u_char *, /*!< output buffer */ + const int); /*!< size of out_storage */ +DST_KEY *dst_buffer_to_key(const char *, /*!< name of the key */ + const int, /*!< algorithm */ + const int, /*!< dns flags */ + const int, /*!< dns protocol */ + const u_char *, /*!< key in dns wire fmt */ + const int); /*!< size of key */ +int dst_key_to_buffer(DST_KEY *, u_char *, int); + +DST_KEY *dst_generate_key(const char *, /*!< name of new key */ + const int, /*!< key algorithm to generate */ + const int, /*!< size of new key */ + const int, /*!< alg dependent parameter */ + const int, /*!< key DNS flags */ + const int); /*!< key DNS protocol */ +DST_KEY *dst_free_key(DST_KEY *); +int dst_compare_keys(const DST_KEY *, const DST_KEY *); + +int dst_sig_size(DST_KEY *); /* support for dns key tags/ids */ -u_int16_t dst_s_dns_key_id(const u_char *dns_key_rdata, const int rdata_len); -u_int16_t dst_s_id_calc(const u_char *key_data, const int key_len); +u_int16_t dst_s_dns_key_id(const u_char *, const int); +u_int16_t dst_s_id_calc(const u_char *, const int); /* Used by callers as well as by the library. */ -#define RAW_KEY_SIZE 8192 /* large enough to store any key */ - +#define RAW_KEY_SIZE 8192 /*%< large enough to store any key */ /* DST_API control flags */ /* These are used used in functions dst_sign_data and dst_verify_data */ -#define SIG_MODE_INIT 1 /* initialize digest */ -#define SIG_MODE_UPDATE 2 /* add data to digest */ -#define SIG_MODE_FINAL 4 /* generate/verify signature */ +#define SIG_MODE_INIT 1 /*%< initialize digest */ +#define SIG_MODE_UPDATE 2 /*%< add data to digest */ +#define SIG_MODE_FINAL 4 /*%< generate/verify signature */ #define SIG_MODE_ALL (SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL) /* Flags for dst_read_private_key() */ @@ -191,3 +165,4 @@ u_int16_t dst_s_id_calc(const u_char *key_data, const int key_len); #define UNSUPPORTED_KEYALG (-31) #endif /* DST_H */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/isc/eventlib.h b/usr/src/lib/libresolv2/include/isc/eventlib.h index 92988f63ca..a4cfdf9092 100644 --- a/usr/src/lib/libresolv2/include/isc/eventlib.h +++ b/usr/src/lib/libresolv2/include/isc/eventlib.h @@ -1,33 +1,26 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Copyright (c) 1995-1999 by Internet Software Consortium + * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1995-1999, 2001, 2003 Internet Software Consortium. * - * Permission to use, copy, modify, and distribute this software for any + * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ /* eventlib.h - exported interfaces for eventlib * vix 09sep95 [initial] * - * $Id: eventlib.h,v 1.23 2001/05/29 05:47:09 marka Exp $ + * $Id: eventlib.h,v 1.7 2008/11/14 02:36:51 marka Exp $ */ -#pragma ident "%Z%%M% %I% %E% SMI" - #ifndef _EVENTLIB_H #define _EVENTLIB_H @@ -36,6 +29,8 @@ #include <sys/time.h> #include <stdio.h> +#include <isc/platform.h> + #ifndef __P # define __EVENTLIB_P_DEFINED # ifdef __STDC__ @@ -57,14 +52,13 @@ typedef struct { void *opaque; } evEvent; #define evInitID(id) ((id)->opaque = NULL) #define evTestID(id) ((id).opaque != NULL) -typedef void (*evConnFunc)__P((evContext ctx, void *uap, int fd, - const void *la, int lalen, - const void *ra, int ralen)); -typedef void (*evFileFunc)__P((evContext ctx, void *uap, int fd, int evmask)); -typedef void (*evStreamFunc)__P((evContext ctx, void *uap, int fd, int bytes)); -typedef void (*evTimerFunc)__P((evContext ctx, void *uap, - struct timespec due, struct timespec inter)); -typedef void (*evWaitFunc)__P((evContext ctx, void *uap, const void *tag)); +typedef void (*evConnFunc)__P((evContext, void *, int, const void *, int, + const void *, int)); +typedef void (*evFileFunc)__P((evContext, void *, int, int)); +typedef void (*evStreamFunc)__P((evContext, void *, int, int)); +typedef void (*evTimerFunc)__P((evContext, void *, + struct timespec, struct timespec)); +typedef void (*evWaitFunc)__P((evContext, void *, const void *)); typedef struct { unsigned char mask[256/8]; } evByteMask; #define EV_BYTEMASK_BYTE(b) ((b) / 8) @@ -84,6 +78,8 @@ typedef struct { unsigned char mask[256/8]; } evByteMask; #define EV_WRITE 2 #define EV_EXCEPT 4 +#define EV_WASNONBLOCKING 8 /* Internal library use. */ + /* eventlib.c */ #define evCreate __evCreate #define evSetDebug __evSetDebug @@ -93,21 +89,19 @@ typedef struct { unsigned char mask[256/8]; } evByteMask; #define evDrop __evDrop #define evMainLoop __evMainLoop #define evHighestFD __evHighestFD - -int evCreate __P((evContext *ctx)); -void evSetDebug __P((evContext ctx, int lev, FILE *out)); -int evDestroy __P((evContext ctx)); -int evGetNext __P((evContext ctx, evEvent *ev, int options)); -int evDispatch __P((evContext ctx, evEvent ev)); -void evDrop __P((evContext ctx, evEvent ev)); -int evMainLoop __P((evContext ctx)); -int evHighestFD __P((evContext ctx)); - -#ifdef SUNW_POLL -extern void evPollfdAdd(evContext ctx, int pollfd_chunk_size, int fd, - short events); -extern void evPollfdDel(evContext ctx, int fd); -#endif /* SUNW_POLL */ +#define evGetOption __evGetOption +#define evSetOption __evSetOption + +int evCreate __P((evContext *)); +void evSetDebug __P((evContext, int, FILE *)); +int evDestroy __P((evContext)); +int evGetNext __P((evContext, evEvent *, int)); +int evDispatch __P((evContext, evEvent)); +void evDrop __P((evContext, evEvent)); +int evMainLoop __P((evContext)); +int evHighestFD __P((evContext)); +int evGetOption __P((evContext *, const char *, int *)); +int evSetOption __P((evContext *, const char *, int)); /* ev_connects.c */ #define evListen __evListen @@ -117,11 +111,10 @@ extern void evPollfdDel(evContext ctx, int fd); #define evUnhold __evUnhold #define evTryAccept __evTryAccept -int evListen __P((evContext ctx, int fd, int maxconn, - evConnFunc func, void *uap, evConnID *id)); -int evConnect __P((evContext ctx, int fd, const void *ra, int ralen, - evConnFunc func, void *uap, evConnID *id)); -int evCancelConn __P((evContext ctx, evConnID id)); +int evListen __P((evContext, int, int, evConnFunc, void *, evConnID *)); +int evConnect __P((evContext, int, const void *, int, + evConnFunc, void *, evConnID *)); +int evCancelConn __P((evContext, evConnID)); int evHold __P((evContext, evConnID)); int evUnhold __P((evContext, evConnID)); int evTryAccept __P((evContext, evConnID, int *)); @@ -130,9 +123,8 @@ int evTryAccept __P((evContext, evConnID, int *)); #define evSelectFD __evSelectFD #define evDeselectFD __evDeselectFD -int evSelectFD __P((evContext ctx, int fd, int eventmask, - evFileFunc func, void *uap, evFileID *id)); -int evDeselectFD __P((evContext ctx, evFileID id)); +int evSelectFD __P((evContext, int, int, evFileFunc, void *, evFileID *)); +int evDeselectFD __P((evContext, evFileID)); /* ev_streams.c */ #define evConsIovec __evConsIovec @@ -142,14 +134,14 @@ int evDeselectFD __P((evContext ctx, evFileID id)); #define evUntimeRW __evUntimeRW #define evCancelRW __evCancelRW -struct iovec evConsIovec __P((void *buf, size_t cnt)); -int evWrite __P((evContext ctx, int fd, const struct iovec *iov, int cnt, - evStreamFunc func, void *uap, evStreamID *id)); -int evRead __P((evContext ctx, int fd, const struct iovec *iov, int cnt, - evStreamFunc func, void *uap, evStreamID *id)); -int evTimeRW __P((evContext ctx, evStreamID id, evTimerID timer)); -int evUntimeRW __P((evContext ctx, evStreamID id)); -int evCancelRW __P((evContext ctx, evStreamID id)); +struct iovec evConsIovec __P((void *, size_t)); +int evWrite __P((evContext, int, const struct iovec *, int, + evStreamFunc func, void *, evStreamID *)); +int evRead __P((evContext, int, const struct iovec *, int, + evStreamFunc func, void *, evStreamID *)); +int evTimeRW __P((evContext, evStreamID, evTimerID timer)); +int evUntimeRW __P((evContext, evStreamID)); +int evCancelRW __P((evContext, evStreamID)); /* ev_timers.c */ #define evConsTime __evConsTime @@ -160,9 +152,11 @@ int evCancelRW __P((evContext ctx, evStreamID id)); #define evTimeVal __evTimeVal #define evNowTime __evNowTime +#define evUTCTime __evUTCTime #define evLastEventTime __evLastEventTime #define evSetTimer __evSetTimer #define evClearTimer __evClearTimer +#define evConfigTimer __evConfigTimer #define evResetTimer __evResetTimer #define evSetIdleTimer __evSetIdleTimer #define evClearIdleTimer __evClearIdleTimer @@ -170,17 +164,19 @@ int evCancelRW __P((evContext ctx, evStreamID id)); #define evTouchIdleTimer __evTouchIdleTimer struct timespec evConsTime __P((time_t sec, long nsec)); -struct timespec evAddTime __P((struct timespec add1, struct timespec add2)); -struct timespec evSubTime __P((struct timespec minu, struct timespec subtra)); +struct timespec evAddTime __P((struct timespec, struct timespec)); +struct timespec evSubTime __P((struct timespec, struct timespec)); struct timespec evNowTime __P((void)); +struct timespec evUTCTime __P((void)); struct timespec evLastEventTime __P((evContext)); struct timespec evTimeSpec __P((struct timeval)); struct timeval evTimeVal __P((struct timespec)); -int evCmpTime __P((struct timespec a, struct timespec b)); -int evSetTimer __P((evContext ctx, evTimerFunc func, void *uap, - struct timespec due, struct timespec inter, - evTimerID *id)); -int evClearTimer __P((evContext ctx, evTimerID id)); +int evCmpTime __P((struct timespec, struct timespec)); +int evSetTimer __P((evContext, evTimerFunc, void *, struct timespec, + struct timespec, evTimerID *)); +int evClearTimer __P((evContext, evTimerID)); +int evConfigTimer __P((evContext, evTimerID, const char *param, + int value)); int evResetTimer __P((evContext, evTimerID, evTimerFunc, void *, struct timespec, struct timespec)); int evSetIdleTimer __P((evContext, evTimerFunc, void *, struct timespec, @@ -196,10 +192,9 @@ int evTouchIdleTimer __P((evContext, evTimerID)); #define evUnwait __evUnwait #define evDefer __evDefer -int evWaitFor __P((evContext ctx, const void *tag, evWaitFunc func, void *uap, - evWaitID *id)); -int evDo __P((evContext ctx, const void *tag)); -int evUnwait __P((evContext ctx, evWaitID id)); +int evWaitFor __P((evContext, const void *, evWaitFunc, void *, evWaitID *)); +int evDo __P((evContext, const void *)); +int evUnwait __P((evContext, evWaitID)); int evDefer __P((evContext, evWaitFunc, void *)); #ifdef __EVENTLIB_P_DEFINED @@ -207,3 +202,5 @@ int evDefer __P((evContext, evWaitFunc, void *)); #endif #endif /*_EVENTLIB_H*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/isc/heap.h b/usr/src/lib/libresolv2/include/isc/heap.h index 46093f506d..384d507cf5 100644 --- a/usr/src/lib/libresolv2/include/isc/heap.h +++ b/usr/src/lib/libresolv2/include/isc/heap.h @@ -1,26 +1,19 @@ - /* - * Copyright (c) 1997, by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Copyright (c) 1997 by Internet Software Consortium. + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") + * Copyright (c) 1997,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" typedef int (*heap_higher_priority_func)(void *, void *); typedef void (*heap_index_func)(void *, int); @@ -52,3 +45,5 @@ int heap_increased(heap_context, int); int heap_decreased(heap_context, int); void * heap_element(heap_context, int); int heap_for_each(heap_context, heap_for_each_func, void *); + +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/isc/irpmarshall.h b/usr/src/lib/libresolv2/include/isc/irpmarshall.h index 9ef0f2e4e4..244b3e3460 100644 --- a/usr/src/lib/libresolv2/include/isc/irpmarshall.h +++ b/usr/src/lib/libresolv2/include/isc/irpmarshall.h @@ -1,34 +1,27 @@ /* - * Copyright 2000-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* - * $Id: irpmarshall.h,v 8.2 2001/05/29 05:47:10 marka Exp $ + * $Id: irpmarshall.h,v 1.4 2005/04/27 04:56:17 sra Exp $ */ #ifndef _IRPMARSHALL_H_INCLUDED #define _IRPMARSHALL_H_INCLUDED -#pragma ident "%Z%%M% %I% %E% SMI" - /* Hide function names */ #define irp_marshall_gr __irp_marshall_gr #define irp_marshall_ho __irp_marshall_ho @@ -52,26 +45,26 @@ (x == AF_INET6 ? "AF_INET6" : "UNKNOWN")) /* See comment below on usage */ -int irp_marshall_pw(const struct passwd *pw, char **buffer, size_t *len); -int irp_unmarshall_pw(struct passwd *pw, char *buffer); -int irp_marshall_gr(const struct group *gr, char **buffer, size_t *len); -int irp_unmarshall_gr(struct group *gr, char *buffer); -int irp_marshall_sv(const struct servent *sv, char **buffer, size_t *len); -int irp_unmarshall_sv(struct servent *sv, char *buffer); -int irp_marshall_pr(struct protoent *pr, char **buffer, size_t *len); -int irp_unmarshall_pr(struct protoent *pr, char *buffer); -int irp_marshall_ho(struct hostent *ho, char **buffer, size_t *len); -int irp_unmarshall_ho(struct hostent *ho, char *buffer); -int irp_marshall_ng(const char *host, const char *user, const char *domain, - char **buffer, size_t *len); -int irp_unmarshall_ng(const char **host, const char **user, - const char **domain, char *buffer); -int irp_marshall_nw(struct nwent *ne, char **buffer, size_t *len); -int irp_unmarshall_nw(struct nwent *ne, char *buffer); -int irp_marshall_ne(struct netent *ne, char **buffer, size_t *len); -int irp_unmarshall_ne(struct netent *ne, char *buffer); +int irp_marshall_pw(const struct passwd *, char **, size_t *); +int irp_unmarshall_pw(struct passwd *, char *); +int irp_marshall_gr(const struct group *, char **, size_t *); +int irp_unmarshall_gr(struct group *, char *); +int irp_marshall_sv(const struct servent *, char **, size_t *); +int irp_unmarshall_sv(struct servent *, char *); +int irp_marshall_pr(struct protoent *, char **, size_t *); +int irp_unmarshall_pr(struct protoent *, char *); +int irp_marshall_ho(struct hostent *, char **, size_t *); +int irp_unmarshall_ho(struct hostent *, char *); +int irp_marshall_ng(const char *, const char *, const char *, + char **, size_t *); +int irp_unmarshall_ng(const char **, const char **, const char **, char *); +int irp_marshall_nw(struct nwent *, char **, size_t *); +int irp_unmarshall_nw(struct nwent *, char *); +int irp_marshall_ne(struct netent *, char **, size_t *); +int irp_unmarshall_ne(struct netent *, char *); -/* +/*! \file + * \brief * Functions to marshall and unmarshall various system data structures. We * use a printable ascii format that is as close to various system config * files as reasonable (e.g. /etc/passwd format). @@ -87,9 +80,7 @@ int irp_unmarshall_ne(struct netent *ne, char *buffer); * * The following description is true for all the marshalling functions: * - */ - -/* int irp_marshall_XX(struct yyyy *XX, char **buffer, size_t *len); + * int irp_marshall_XX(struct yyyy *XX, char **buffer, size_t *len); * * The argument XX (of type struct passwd for example) is marshalled in the * buffer pointed at by *BUFFER, which is of length *LEN. Returns 0 @@ -109,9 +100,7 @@ int irp_unmarshall_ne(struct netent *ne, char *buffer); * to separate fields). Fields that have multiple subfields (like the * gr_mem field in struct group) have their subparts separated by * commas. - */ - -/* + * * int irp_unmarshall_XX(struct YYYYY *XX, char *buffer); * * The unmashalling functions break apart the buffer and store the diff --git a/usr/src/lib/libresolv2/include/isc/list.h b/usr/src/lib/libresolv2/include/isc/list.h index dba0aad62d..5fe9031141 100644 --- a/usr/src/lib/libresolv2/include/isc/list.h +++ b/usr/src/lib/libresolv2/include/isc/list.h @@ -1,27 +1,20 @@ /* - * Copyright (c) 1998-2001 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1997,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #ifndef LIST_H #define LIST_H 1 #include <isc/assertions.h> @@ -38,7 +31,8 @@ } while (0) #define INIT_LINK(elt, link) \ INIT_LINK_TYPE(elt, link, void) -#define LINKED(elt, link) ((void *)((elt)->link.prev) != (void *)(-1)) +#define LINKED(elt, link) ((void *)((elt)->link.prev) != (void *)(-1) && \ + (void *)((elt)->link.next) != (void *)(-1)) #define HEAD(list) ((list).head) #define TAIL(list) ((list).tail) @@ -73,12 +67,16 @@ INSIST(LINKED(elt, link));\ if ((elt)->link.next != NULL) \ (elt)->link.next->link.prev = (elt)->link.prev; \ - else \ + else { \ + INSIST((list).tail == (elt)); \ (list).tail = (elt)->link.prev; \ + } \ if ((elt)->link.prev != NULL) \ (elt)->link.prev->link.next = (elt)->link.next; \ - else \ + else { \ + INSIST((list).head == (elt)); \ (list).head = (elt)->link.next; \ + } \ INIT_LINK_TYPE(elt, link, type); \ } while (0) #define UNLINK(list, elt, link) \ @@ -117,3 +115,4 @@ #define DEQUEUE(list, elt, link) UNLINK(list, elt, link) #endif /* LIST_H */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/isc/logging.h b/usr/src/lib/libresolv2/include/isc/logging.h index 99f0e40fea..c539443ff8 100644 --- a/usr/src/lib/libresolv2/include/isc/logging.h +++ b/usr/src/lib/libresolv2/include/isc/logging.h @@ -1,25 +1,19 @@ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" #ifndef LOGGING_H #define LOGGING_H @@ -116,3 +110,4 @@ int log_free_channel(log_channel); void log_close_debug_channels(log_context); #endif /* !LOGGING_H */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/isc/memcluster.h b/usr/src/lib/libresolv2/include/isc/memcluster.h index 28e7c444a8..0923deb5e7 100644 --- a/usr/src/lib/libresolv2/include/isc/memcluster.h +++ b/usr/src/lib/libresolv2/include/isc/memcluster.h @@ -1,27 +1,20 @@ /* - * Copyright 1998-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1997,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #ifndef MEMCLUSTER_H #define MEMCLUSTER_H @@ -54,3 +47,4 @@ void memstats(FILE *); int memactive(void); #endif /* MEMCLUSTER_H */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/isc/misc.h b/usr/src/lib/libresolv2/include/isc/misc.h index 89afbc6c51..b54f4ee6ed 100644 --- a/usr/src/lib/libresolv2/include/isc/misc.h +++ b/usr/src/lib/libresolv2/include/isc/misc.h @@ -1,39 +1,37 @@ /* - * Copyright 1997-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Copyright (c) 1995-1999 by Internet Software Consortium + * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1995-2001, 2003 Internet Software Consortium. * - * Permission to use, copy, modify, and distribute this software for any + * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ /* - * $Id: misc.h,v 8.5 2001/06/18 06:40:43 marka Exp $ + * $Id: misc.h,v 1.7 2008/11/14 02:36:51 marka Exp $ */ -#pragma ident "%Z%%M% %I% %E% SMI" - #ifndef _ISC_MISC_H #define _ISC_MISC_H +/*! \file */ + #include <stdio.h> +#include <sys/types.h> #define bitncmp __bitncmp +/*#define isc_movefile __isc_movefile */ -extern int bitncmp(const void *l, const void *r, int n); +extern int bitncmp(const void *, const void *, int); +extern int isc_movefile(const char *, const char *); extern int isc_gethexstring(unsigned char *, size_t, int, FILE *, int *); @@ -42,3 +40,5 @@ extern void isc_puthexstring(FILE *, const unsigned char *, size_t, extern void isc_tohex(const unsigned char *, size_t, char *); #endif /*_ISC_MISC_H*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/isc/platform.h b/usr/src/lib/libresolv2/include/isc/platform.h new file mode 100644 index 0000000000..2fc59b61a8 --- /dev/null +++ b/usr/src/lib/libresolv2/include/isc/platform.h @@ -0,0 +1,42 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +/* + * Copyright (C) 2008 Internet Systems Consortium, Inc. ("ISC") + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: platform.h.in,v 1.3 2008/01/23 02:15:56 tbox Exp $ */ + +/*! \file */ + +#ifndef ISC_PLATFORM_H +#define ISC_PLATFORM_H + +/* + * Define if the OS does not define struct timespec. + */ +#undef ISC_PLATFORM_NEEDTIMESPEC +#ifdef ISC_PLATFORM_NEEDTIMESPEC +#include <time.h> /* For time_t */ +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* nanoseconds */ +}; +#endif + +#endif diff --git a/usr/src/lib/libresolv2/include/isc/tree.h b/usr/src/lib/libresolv2/include/isc/tree.h index 384832830c..96feaca68d 100644 --- a/usr/src/lib/libresolv2/include/isc/tree.h +++ b/usr/src/lib/libresolv2/include/isc/tree.h @@ -1,17 +1,11 @@ -/* - * Copyright 2003 by Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - /* tree.h - declare structures used by tree library * * vix 22jan93 [revisited; uses RCS, ANSI, POSIX; has bug fixes] * vix 27jun86 [broken out of tree.c] * - * $Id: tree.h,v 8.3 2002/12/03 05:26:48 marka Exp $ + * $Id: tree.h,v 1.3 2005/04/27 04:56:18 sra Exp $ */ -#pragma ident "%Z%%M% %I% %E% SMI" #ifndef _TREE_H_INCLUDED #define _TREE_H_INCLUDED @@ -25,7 +19,7 @@ # endif #endif -/* +/*% * tree_t is our package-specific anonymous pointer. */ #if defined(__STDC__) || defined(__GNUC__) @@ -34,8 +28,7 @@ typedef void *tree_t; typedef char *tree_t; #endif -#ifdef ORIGINAL_ISC_CODE -/* +/*% * Do not taint namespace */ #define tree_add __tree_add @@ -44,8 +37,7 @@ typedef char *tree_t; #define tree_mung __tree_mung #define tree_srch __tree_srch #define tree_trav __tree_trav -#else -#endif + typedef struct tree_s { tree_t data; @@ -64,3 +56,4 @@ void tree_mung __P((tree **, void (*)())); #endif /* _TREE_H_INCLUDED */ +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/netdb_private.h b/usr/src/lib/libresolv2/include/netdb_private.h deleted file mode 100644 index 58a6c5905f..0000000000 --- a/usr/src/lib/libresolv2/include/netdb_private.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 1999-2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#ifndef _NETDB_PRIVATE_H -#define _NETDB_PRIVATE_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Constants defined by the ISC for BIND 8.2, but which do not appear - * in RFC 2553 (hence, aren't suitable for inclusion in <netdb.h>). - */ - -/* - * Error return codes from getaddrinfo() - */ - -#define EAI_BADHINTS 12 -#define EAI_PROTOCOL 13 -#define EAI_MAX 14 - -/* - * Flag values for getaddrinfo() - */ - -#define AI_MASK 0x00000007 - -/* - * Scope delimit character - */ -#define SCOPE_DELIMITER '%' - -/* - * XXX - * Various data types (hostent_data, netent_data, protoent_data, servent_data) - * only defined for __osf__ or __hpux => we don't need them ?? - */ - -#endif /* _NETDB_PRIVATE_H */ diff --git a/usr/src/lib/libresolv2/include/netgroup.h b/usr/src/lib/libresolv2/include/netgroup.h index 36cc9a742f..e4be459fdf 100644 --- a/usr/src/lib/libresolv2/include/netgroup.h +++ b/usr/src/lib/libresolv2/include/netgroup.h @@ -1,26 +1,26 @@ -/* - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef ORIGINAL_ISC_CODE #ifndef netgroup_h #define netgroup_h +#ifndef __GLIBC__ -int getnetgrent(const char **machinep, const char **userp, - const char **domainp); - -int getnetgrent_r(char **machinep, char **userp, char **domainp, - char *buffer, int buflen); - -void setnetgrent(const char *netgroup); +/* + * The standard is crazy. These values "belong" to getnetgrent() and + * shouldn't be altered by the caller. + */ +int getnetgrent __P((/* const */ char **, /* const */ char **, + /* const */ char **)); -void endnetgrent(void); +int getnetgrent_r __P((char **, char **, char **, char *, int)); -int innetgr(const char *netgroup, const char *machine, - const char *user, const char *domain); +void endnetgrent __P((void)); +#ifdef __osf__ +int innetgr __P((char *, char *, char *, char *)); +void setnetgrent __P((char *)); +#else +void setnetgrent __P((const char *)); +int innetgr __P((const char *, const char *, const char *, const char *)); +#endif #endif -#endif /* ORIGINAL_ISC_CODE */ +#endif + +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/paths.h b/usr/src/lib/libresolv2/include/paths.h index 648c624e02..7ec03327e1 100644 --- a/usr/src/lib/libresolv2/include/paths.h +++ b/usr/src/lib/libresolv2/include/paths.h @@ -1,9 +1,2 @@ -/* - * Copyright (c) 1997, by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #define _PATH_DEVNULL "/dev/null" diff --git a/usr/src/lib/libresolv2/include/port_after.h b/usr/src/lib/libresolv2/include/port_after.h index 45b94dbd05..4b1b4a1f69 100644 --- a/usr/src/lib/libresolv2/include/port_after.h +++ b/usr/src/lib/libresolv2/include/port_after.h @@ -1,55 +1,82 @@ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" -#ifndef PORT_AFTER_H -#define PORT_AFTER_H -#include "os_version.h" +/* + * Copyright (C) 2004-2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2001-2003 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ -#undef HAVE_SA_LEN -#define USE_POSIX -#define POSIX_SIGNALS -#define NETREAD_BROKEN -#define USE_WAITPID -#define HAVE_FCHMOD -#define NEED_PSELECT -#define SETGRENT_VOID -#define SETPWENT_VOID -#define SIOCGIFCONF_ADDR -#define IP_OPT_BUF_SIZE 40 -#define HAVE_CHROOT -#define CAN_CHANGE_ID -#define POSIX_GETPWNAM_R -#define POSIX_GETPWUID_R -#define POSIX_GETGRGID_R -#define POSIX_GETGRNAM_R -#define NEED_SECURE_DIRECTORY -#define HAVE_DEV_RANDOM -#define NO_MSG_CONTROL - -#define PORT_NONBLOCK O_NONBLOCK -#define PORT_WOULDBLK EWOULDBLOCK -#define WAIT_T int -#ifndef SUNW_LIBNSL -#define INADDR_NONE 0xffffffff -#endif +/* $Id: port_after.h.in,v 1.60 2008/02/28 05:34:17 marka Exp $ */ + +#ifndef port_after_h +#define port_after_h +#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/param.h> +#include <sys/time.h> #if (!defined(BSD)) || (BSD < 199306) #include <sys/bitypes.h> #endif -#include <sys/time.h> +#ifdef HAVE_INTTYPES_H +#include <inttypes.h> +#endif +#ifdef HAVE_SYS_SELECT_H +#include <sys/select.h> +#endif /* HAVE_SYS_SELECT_H */ -#ifndef MIN -#define MIN(x, y) ((x > y) ?y :x) +#ifdef REENABLE_SEND +#undef send #endif -#ifndef MAX -#define MAX(x, y) ((x > y) ?x :y) + +#undef NEED_PSELECT +#undef HAVE_SA_LEN +#undef HAVE_MINIMUM_IFREQ +#define NEED_DAEMON 1 +#undef NEED_STRSEP +#undef NEED_STRERROR +#ifdef NEED_STRERROR +const char *isc_strerror(int); +#define strerror isc_strerror +#endif +/* HAS_INET6_STRUCTS and HAVE_SIN6_SCOPE_ID are defined by port_ipv6.h + * #define HAS_INET6_STRUCTS 1 + * #define HAVE_SIN6_SCOPE_ID 1 + */ +#include <port_ipv6.h> + +#undef NEED_IN6ADDR_ANY +#undef HAS_IN_ADDR6 +#define HAVE_SOCKADDR_STORAGE 1 +#undef NEED_GETTIMEOFDAY +#undef HAVE_STRNDUP +#undef USE_FIONBIO_IOCTL +#undef INNETGR_ARGS + +#undef USE_IFNAMELINKID +#define PORT_NONBLOCK O_NONBLOCK + +#ifndef _POSIX_PATH_MAX +#define _POSIX_PATH_MAX 255 +#endif +#ifndef PATH_MAX +#define PATH_MAX _POSIX_PATH_MAX #endif /* @@ -61,243 +88,454 @@ * derived systems for which AF_INET6 is defined. */ #ifndef AF_INET6 -#define AF_INET6 24 +#define AF_INET6 24 #endif -#ifndef PF_INET6 -#define PF_INET6 AF_INET6 +#ifndef PF_INET6 +#define PF_INET6 AF_INET6 +#endif + +#ifdef HAS_IN_ADDR6 +/* Map to pre-RFC structure. */ +#define in6_addr in_addr6 #endif -#include <port_ipv6.h> #ifndef HAS_INET6_STRUCTS /* Replace with structure from later rev of O/S if known. */ struct in6_addr { - u_int8_t s6_addr[16]; + u_int8_t s6_addr[16]; }; +#define IN6ADDR_ANY_INIT \ + {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }} + +#define IN6ADDR_LOOPBACK_INIT \ + {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }} + /* Replace with structure from later rev of O/S if known. */ struct sockaddr_in6 { -#ifdef HAVE_SA_LEN - u_int8_t sin6_len; /* length of this struct */ - u_int8_t sin6_family; /* AF_INET6 */ +#ifdef HAVE_SA_LEN + u_int8_t sin6_len; /* length of this struct */ + u_int8_t sin6_family; /* AF_INET6 */ #else - u_int16_t sin6_family; /* AF_INET6 */ + u_int16_t sin6_family; /* AF_INET6 */ #endif - u_int16_t sin6_port; /* transport layer port # */ - u_int32_t sin6_flowinfo; /* IPv6 flow information */ - struct in6_addr sin6_addr; /* IPv6 address */ - u_int32_t sin6_scope_id; /* set of interfaces for a scope */ + u_int16_t sin6_port; /* transport layer port # */ + u_int32_t sin6_flowinfo; /* IPv6 flow information */ + struct in6_addr sin6_addr; /* IPv6 address */ + u_int32_t sin6_scope_id; /* set of interfaces for a scope */ }; +#endif /* HAS_INET6_STRUCTS */ + +#ifdef BROKEN_IN6ADDR_INIT_MACROS +#undef IN6ADDR_ANY_INIT +#undef IN6ADDR_LOOPBACK_INIT +#endif +#ifdef _AIX #ifndef IN6ADDR_ANY_INIT -#define IN6ADDR_ANY_INIT {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} +#define IN6ADDR_ANY_INIT {{{ 0, 0, 0, 0 }}} #endif #ifndef IN6ADDR_LOOPBACK_INIT -#define IN6ADDR_LOOPBACK_INIT {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}} +#if BYTE_ORDER == BIG_ENDIAN +#define IN6ADDR_LOOPBACK_INIT {{{ 0, 0, 0, 1 }}} +#else +#define IN6ADDR_LOOPBACK_INIT {{{0, 0, 0, 0x01000000}}} +#endif +#endif #endif -#endif /* HAS_INET6_STRUCTS */ -#if defined(NEED_SOCKADDR_STORAGE) || !defined(HAS_INET6_STRUCTS) -#define __SS_MAXSIZE 128 -#define __SS_ALLIGSIZE (sizeof (long)) +#ifndef IN6ADDR_ANY_INIT +#ifdef s6_addr +#define IN6ADDR_ANY_INIT \ + {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} +#else +#define IN6ADDR_ANY_INIT \ + {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }} +#endif + +#endif +#ifndef IN6ADDR_LOOPBACK_INIT +#ifdef s6_addr +#define IN6ADDR_LOOPBACK_INIT \ + {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} +#else +#define IN6ADDR_LOOPBACK_INIT \ + {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }} +#endif +#endif + +#ifndef HAVE_SOCKADDR_STORAGE +#define __SS_MAXSIZE 128 +#define __SS_ALLIGSIZE (sizeof (long)) struct sockaddr_storage { #ifdef HAVE_SA_LEN - u_int8_t ss_len; /* address length */ - u_int8_t ss_family; /* address family */ - char __ss_pad1[__SS_ALLIGSIZE - 2 * sizeof (u_int8_t)]; - long __ss_align; - char __ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE]; + u_int8_t ss_len; /* address length */ + u_int8_t ss_family; /* address family */ + char __ss_pad1[__SS_ALLIGSIZE - 2 * sizeof(u_int8_t)]; + long __ss_align; + char __ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE]; #else - u_int16_t ss_family; /* address family */ - char __ss_pad1[__SS_ALLIGSIZE - sizeof (u_int16_t)]; - long __ss_align; - char __ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE]; + u_int16_t ss_family; /* address family */ + char __ss_pad1[__SS_ALLIGSIZE - sizeof(u_int16_t)]; + long __ss_align; + char __ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE]; #endif }; #endif #if !defined(HAS_INET6_STRUCTS) || defined(NEED_IN6ADDR_ANY) -#define in6addr_any isc_in6addr_any +#define in6addr_any isc_in6addr_any extern const struct in6_addr in6addr_any; #endif +/* + * IN6_ARE_ADDR_EQUAL, IN6_IS_ADDR_UNSPECIFIED, IN6_IS_ADDR_V4COMPAT and + * IN6_IS_ADDR_V4MAPPED are broken in glibc 2.1. + */ +#ifdef __GLIBC__ +#if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 2) +#undef IN6_ARE_ADDR_EQUAL +#undef IN6_IS_ADDR_UNSPECIFIED +#undef IN6_IS_ADDR_V4COMPAT +#undef IN6_IS_ADDR_V4MAPPED +#endif +#endif + #ifndef IN6_ARE_ADDR_EQUAL -#define IN6_ARE_ADDR_EQUAL(a, b) \ - (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof (struct in6_addr)) == 0) +#define IN6_ARE_ADDR_EQUAL(a,b) \ + (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) #endif #ifndef IN6_IS_ADDR_UNSPECIFIED -#define IN6_IS_ADDR_UNSPECIFIED(a) \ +#define IN6_IS_ADDR_UNSPECIFIED(a) \ IN6_ARE_ADDR_EQUAL(a, &in6addr_any) #endif #ifndef IN6_IS_ADDR_LOOPBACK extern const struct in6_addr isc_in6addr_loopback; -#define IN6_IS_ADDR_LOOPBACK(a) \ +#define IN6_IS_ADDR_LOOPBACK(a) \ IN6_ARE_ADDR_EQUAL(a, &isc_in6addr_loopback) #endif -#ifndef IN6_IS_ADDR_V4COMPAT -#define IN6_IS_ADDR_V4COMPAT(a) \ - ((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 && \ - (a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 && \ - (a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 && \ - (a)->s6_addr[6] == 0x00 && (a)->s6_addr[7] == 0x00 && \ - (a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 && \ - (a)->s6_addr[10] == 0x00 && (a)->s6_addr[11] == 0x00 && \ - ((a)->s6_addr[12] != 0x00 || (a)->s6_addr[13] != 0x00 || \ - (a)->s6_addr[14] != 0x00 || \ - ((a)->s6_addr[15] != 0x00 && (a)->s6_addr[15] != 1))) -#endif - #ifndef IN6_IS_ADDR_V4MAPPED -#define IN6_IS_ADDR_V4MAPPED(a) \ +#define IN6_IS_ADDR_V4MAPPED(a) \ ((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 && \ (a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 && \ (a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 && \ - (a)->s6_addr[6] == 0x00 && (a)->s6_addr[7] == 0x00 && \ + (a)->s6_addr[6] == 0x00 && (a)->s6_addr[9] == 0x00 && \ (a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 && \ (a)->s6_addr[10] == 0xff && (a)->s6_addr[11] == 0xff) #endif #ifndef IN6_IS_ADDR_SITELOCAL -#define IN6_IS_ADDR_SITELOCAL(a) \ +#define IN6_IS_ADDR_SITELOCAL(a) \ (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) #endif #ifndef IN6_IS_ADDR_LINKLOCAL -#define IN6_IS_ADDR_LINKLOCAL(a) \ +#define IN6_IS_ADDR_LINKLOCAL(a) \ (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) #endif #ifndef IN6_IS_ADDR_MULTICAST -#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) +#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) #endif #ifndef __IPV6_ADDR_MC_SCOPE -#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) +#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) #endif #ifndef __IPV6_ADDR_SCOPE_SITELOCAL -#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05 +#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05 #endif - #ifndef __IPV6_ADDR_SCOPE_ORGLOCAL -#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 +#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 #endif #ifndef IN6_IS_ADDR_MC_SITELOCAL -#define IN6_IS_ADDR_MC_SITELOCAL(a) \ +#define IN6_IS_ADDR_MC_SITELOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) && \ - (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL)) + (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL)) #endif #ifndef IN6_IS_ADDR_MC_ORGLOCAL -#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ +#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) && \ - (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL)) + (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL)) #endif -#ifndef INET6_ADDRSTRLEN -#define INET6_ADDRSTRLEN 46 +#ifndef INADDR_NONE +#define INADDR_NONE 0xffffffff #endif -/* - * Prior to 2.6, Solaris needs a prototype for gethostname(). - */ -#if (OS_MAJOR == 5 && OS_MINOR < 6) -extern int gethostname(char *, size_t); +#ifndef MAXHOSTNAMELEN +#define MAXHOSTNAMELEN 256 #endif -/* - * gethostid() was not available until 2.5 - * setsockopt(SO_REUSEADDR) fails on unix domain sockets before 2.5 - * use ioctl(FIONBIO) rather than fcntl() calls to set/clear non-blocking i/o. - */ -#if (OS_MAJOR == 5 && OS_MINOR < 5) -#define GET_HOST_ID_MISSING -#define NO_UNIX_REUSEADDR -#define USE_FIONBIO_IOCTL + +#ifndef INET6_ADDRSTRLEN +/* sizeof("aaaa:bbbb:cccc:dddd:eeee:ffff:123.123.123.123") */ +#define INET6_ADDRSTRLEN 46 +#endif + +#ifndef MIN +#define MIN(x,y) (((x) <= (y)) ? (x) : (y)) #endif -#define NEED_STRSEP -extern char *strsep(char **, const char *); +#ifndef MAX +#define MAX(x,y) (((x) >= (y)) ? (x) : (y)) +#endif -#define NEED_DAEMON +#ifdef NEED_DAEMON int daemon(int nochdir, int noclose); +#endif -/* - * Solaris defines this in <netdb.h> instead of in <sys/param.h>. We don't - * define it in our <netdb.h>, so we define it here. - */ -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 256 +#ifdef NEED_STRSEP +char * strsep(char **stringp, const char *delim); #endif -/* - * Solaris 2.5 and later have getrlimit(), setrlimit() and getrusage(). - */ -#if (OS_MAJOR > 5 || (OS_MAJOR == 5 && OS_MINOR >= 5)) -#include <sys/resource.h> -#define HAVE_GETRUSAGE -#define RLIMIT_TYPE rlim_t -#define RLIMIT_FILE_INFINITY +#ifndef ALIGN +#define ALIGN(p) (((uintptr_t)(p) + (sizeof(long) - 1)) & ~(sizeof(long) - 1)) #endif -#include <resolv_mt.h> -#include <netdb_private.h> -#include <inet_private.h> -#include <ctype.h> -#include <sunw_dst_init.h> -#include <sunw_irs_init.h> +#ifdef NEED_SETGROUPENT +int setgroupent(int stayopen); +#endif -#ifdef ORIGINAL_ISC_CODE -const char *isc_strerror(int errnum); -#define strerror isc_strerror +#ifdef NEED_GETGROUPLIST +int getgrouplist(GETGROUPLIST_ARGS); #endif -#ifndef ISC_FACILITY -#define ISC_FACILITY LOG_DAEMON +#ifdef POSIX_GETGRNAM_R +int +__posix_getgrnam_r(const char *, struct group *, char *, int, struct group **); #endif -/* res_mkquery.c refers explicitly to __putlong and __putshort */ -#define __putlong putlong -#define __putshort putshort +#ifdef NEED_GETGRNAM_R +int +getgrnam_r(const char *, struct group *, char *, size_t, struct group **); +#endif -/* - * If one wanted to use isc__gettimeofday for Solaris, they would - * need to define NEED_GETTIMEOFDAY (common/bsd/gettimeofday.c), - * which is not defined for Solaris. Hence there is no reason to - * change the current definition of gettimeofday which currently - * comes from libc and we comment the following out. - */ -#ifdef ORIGINAL_ISC_CODE -int isc__gettimeofday(struct timeval *, struct timezone *); -#define gettimeofday isc__gettimeofday +#ifdef POSIX_GETGRGID_R +int +__posix_getgrgid_r(gid_t, struct group *, char *, int, struct group **) ; #endif -/* - * Solaris 8 has if_nametoindex(). - */ -#if (OS_MAJOR > 5 || (OS_MAJOR == 5 && OS_MINOR >= 8)) -#define USE_IFNAMELINKID -#endif - -#define UNUSED(x) (x) = (x) -#define DE_CONST(konst, var) \ - do { \ - union { const void *k; void *v; } _u; \ - _u.k = konst; \ - var = _u.v; \ - } while (0) +#ifdef NEED_GETGRGID_R +int +getgrgid_r(gid_t, struct group *, char *, size_t, struct group **); +#endif -#ifndef ALIGN -#if (OS_MAJOR == 5 && OS_MINOR > 8) -#define ALIGN(x) (((uintptr_t)(x) + (sizeof(char*) - 1UL)) & ~(sizeof(char*) - 1UL)) +#ifdef NEED_GETGRENT_R +GROUP_R_RETURN getgrent_r(struct group *gptr, GROUP_R_ARGS); +#endif + +#ifdef NEED_SETGRENT_R +GROUP_R_SET_RETURN setgrent_r(GROUP_R_ENT_ARGS); +#endif + +#ifdef NEED_ENDGRENT_R +GROUP_R_END_RETURN endgrent_r(GROUP_R_ENT_ARGS); +#endif + +#if defined(NEED_INNETGR_R) && defined(NGR_R_RETURN) +NGR_R_RETURN +innetgr_r(const char *, const char *, const char *, const char *); +#endif + +#ifdef NEED_SETNETGRENT_R +#ifdef NGR_R_SET_ARGS +NGR_R_SET_RETURN setnetgrent_r(NGR_R_SET_CONST char *netgroup, NGR_R_SET_ARGS); +#else +NGR_R_SET_RETURN setnetgrent_r(NGR_R_SET_CONST char *netgroup); +#endif +#endif + +#ifdef NEED_ENDNETGRENT_R +#ifdef NGR_R_END_ARGS +NGR_R_END_RETURN endnetgrent_r(NGR_R_END_ARGS); #else -#define ALIGN(x) (((unsigned long)(x) + (sizeof(char*) - 1UL)) & ~(sizeof(char*) - 1UL)) +NGR_R_END_RETURN endnetgrent_r(void); #endif #endif -#endif /* ! PORT_AFTER_H */ +#ifdef POSIX_GETPWNAM_R +int +__posix_getpwnam_r(const char *login, struct passwd *pwptr, + char *buf, size_t buflen, struct passwd **result); +#endif + +#ifdef NEED_GETPWNAM_R +int +getpwnam_r(const char *login, struct passwd *pwptr, + char *buf, size_t buflen, struct passwd **result); +#endif + +#ifdef POSIX_GETPWUID_R +int +__posix_getpwuid_r(uid_t uid, struct passwd *pwptr, + char *buf, int buflen, struct passwd **result); +#endif + +#ifdef NEED_GETPWUID_R +int +getpwuid_r(uid_t uid, struct passwd *pwptr, + char *buf, size_t buflen, struct passwd **result); +#endif + +#ifdef NEED_SETPWENT_R +#ifdef PASS_R_ENT_ARGS +PASS_R_SET_RETURN setpwent_r(PASS_R_ENT_ARGS); +#else +PASS_R_SET_RETURN setpwent_r(void); +#endif + +#endif + +#ifdef NEED_SETPASSENT_R +#ifdef PASS_R_ENT_ARGS +PASS_R_SET_RETURN setpassent_r(int stayopen, PASS_R_ENT_ARGS); +#else +PASS_R_SET_RETURN setpassent_r(int stayopen); +#endif +#endif + +#ifdef NEED_GETPWENT_R +PASS_R_RETURN getpwent_r(struct passwd *pwptr, PASS_R_ARGS); +#endif + +#ifdef NEED_ENDPWENT_R +void endpwent_r(void); +#endif + +#ifdef NEED_SETPASSENT +int setpassent(int stayopen); +#endif + +#define gettimeofday isc__gettimeofday +#ifdef NEED_GETTIMEOFDAY +int isc__gettimeofday(struct timeval *tvp, struct _TIMEZONE *tzp); +#else +int isc__gettimeofday(struct timeval *tp, struct timezone *tzp); +#endif + +int getnetgrent(NGR_R_CONST char **machinep, NGR_R_CONST char **userp, + NGR_R_CONST char **domainp); + +#ifdef NGR_R_ARGS +int getnetgrent_r(NGR_R_CONST char **machinep, NGR_R_CONST char **userp, + NGR_R_CONST char **domainp, NGR_R_ARGS); +#endif + +/* setnetgrent and endnetgrent are defined in sunw_port_after.h +#ifdef SETNETGRENT_ARGS +void setnetgrent(SETNETGRENT_ARGS); +#else +void setnetgrent(const char *netgroup); +#endif + +void endnetgrent(void); +*/ + +#ifdef INNETGR_ARGS +int innetgr(INNETGR_ARGS); +#else +int innetgr(const char *netgroup, const char *machine, + const char *user, const char *domain); +#endif + +#ifdef NGR_R_SET_ARGS +NGR_R_SET_RETURN +setnetgrent_r(NGR_R_SET_CONST char *netgroup, NGR_R_SET_ARGS); +#else +NGR_R_SET_RETURN +setnetgrent_r(NGR_R_SET_CONST char *netgroup); +#endif + +#ifdef NEED_STRTOUL +unsigned long strtoul(const char *, char **, int); +#endif + +#ifdef NEED_SUN4PROTOS +#include <stdarg.h> +#ifndef __SIZE_TYPE__ +#define __SIZE_TYPE__ int +#endif +struct sockaddr; +struct iovec; +struct timeval; +struct timezone; +int fprintf(FILE *, const char *, ...); +int getsockname(int, struct sockaddr *, int *); +int getpeername(int, struct sockaddr *, int *); +int socket(int, int, int); +int connect(int, const struct sockaddr *, int); +int writev(int, struct iovec *, int); +int readv(int, struct iovec *, int); +int send(int, const char *, int, int); +void bzero(char *, int); +int recvfrom(int, char *, int, int, struct sockaddr *, int *); +int syslog(int, const char *, ... ); +int printf(const char *, ...); +__SIZE_TYPE__ fread(void *, __SIZE_TYPE__, __SIZE_TYPE__, FILE *); +__SIZE_TYPE__ fwrite(const void *, __SIZE_TYPE__, __SIZE_TYPE__, FILE *); +int fclose(FILE *); +int ungetc(int, FILE *); +int scanf(const char *, ...); +int sscanf(const char *, const char *, ... ); +int tolower(int); +int toupper(int); +int strcasecmp(const char *, const char *); +int strncasecmp(const char *, const char *, int); +int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); +#ifdef gettimeofday +#undef gettimeofday +int gettimeofday(struct timeval *, struct timezone *); +#define gettimeofday isc__gettimeofday +#else +int gettimeofday(struct timeval *, struct timezone *); +#endif +long strtol(const char*, char **, int); +int fseek(FILE *, long, int); +int setsockopt(int, int, int, const char *, int); +int bind(int, const struct sockaddr *, int); +void bcopy(char *, char *, int); +int fputc(char, FILE *); +int listen(int, int); +int accept(int, struct sockaddr *, int *); +int getsockopt(int, int, int, char *, int *); +int vfprintf(FILE *, const char *, va_list); +int fflush(FILE *); +int fgetc(FILE *); +int fputs(const char *, FILE *); +int fchown(int, int, int); +void setbuf(FILE *, char *); +int gethostname(char *, int); +int rename(const char *, const char *); +time_t time(time_t *); +int fscanf(FILE *, const char *, ...); +int sscanf(const char *, const char *, ...); +int ioctl(int, int, caddr_t); +void perror(const char *); + +#if !defined(__USE_FIXED_PROTOTYPES__) && !defined(__cplusplus) && !defined(__STRICT_ANSI__) +/* + * 'gcc -ansi' changes the prototype for vsprintf(). + * Use this prototype when 'gcc -ansi' is not in effect. + */ +char *vsprintf(char *, const char *, va_list); +#endif +#endif + +/* Solaris-specific changes */ +#include "sunw_port_after.h" + +#endif diff --git a/usr/src/lib/libresolv2/include/port_before.h b/usr/src/lib/libresolv2/include/port_before.h index 6cb7b14588..2801139223 100644 --- a/usr/src/lib/libresolv2/include/port_before.h +++ b/usr/src/lib/libresolv2/include/port_before.h @@ -1,127 +1,188 @@ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" -#ifdef SUNW_OPTIONS -#include "conf/sunoptions.h" +/* + * Copyright (C) 2005-2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: port_before.h.in,v 1.31 2008/02/28 05:36:10 marka Exp $ */ + +#ifndef port_before_h +#define port_before_h +/* Solaris-specific changes */ +#include "sunw_port_before.h" +#include <config.h> + +#ifdef NEED_SUN4PROTOS +#define _PARAMS(x) x #endif -#define __EXTENSIONS__ -/* #define SVR4 */ -#ifdef WANT_IRS_NIS -#undef WANT_IRS_NIS +struct group; /* silence warning */ +struct passwd; /* silence warning */ +struct timeval; /* silence warning */ +struct timezone; /* silence warning */ + +#ifdef HAVE_SYS_TIMERS_H +#include <sys/timers.h> #endif -#undef WANT_IRS_PW -#undef WANT_IRS_GR -#define SIG_FN void -#define ISC_SOCKLEN_T int -#include "os_version.h" -#if (OS_MAJOR == 5 && OS_MINOR < 5) -#undef HAS_PTHREADS -#else -#define HAS_PTHREADS +#include <limits.h> + +#ifdef ISC_PLATFORM_NEEDTIMESPEC +#include <time.h> /* For time_t */ +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* nanoseconds */ +}; #endif - -#if defined(HAS_PTHREADS) && defined(_REENTRANT) -#define DO_PTHREADS +#ifndef HAVE_MEMMOVE +#define memmove(a,b,c) bcopy(b,a,c) #endif +#undef WANT_IRS_GR +#undef WANT_IRS_NIS +#undef WANT_IRS_PW + +#define BSD_COMP 1 +#define USE_POLL 1 +#define HAVE_MD5 1 +#define SOLARIS2 1 + +/* DO_PTHREADS is conditionally defined in sunw_port_before.h + * #define DO_PTHREADS 1 */ +#define GETGROUPLIST_ARGS const char *name, gid_t basegid, gid_t *groups, int *ngroups +#define GETNETBYADDR_ADDR_T long +#define SETPWENT_VOID 1 +#define SETGRENT_VOID 1 + +#define NET_R_ARGS char *buf, int buflen +#define NET_R_BAD NULL +#define NET_R_COPY buf, buflen +#define NET_R_COPY_ARGS NET_R_ARGS +#define NET_R_END_RESULT(x) /*empty*/ +#define NET_R_END_RETURN void +#undef NET_R_ENT_ARGS /*empty*/ +#define NET_R_OK nptr +#define NET_R_RETURN struct netent * +#undef NET_R_SET_RESULT /*empty*/ +#undef NET_R_SETANSWER +#define NET_R_SET_RETURN void +#undef NETENT_DATA + #define GROUP_R_RETURN struct group * #define GROUP_R_SET_RETURN void #undef GROUP_R_SET_RESULT /*empty*/ #define GROUP_R_END_RETURN void -#undef GROUP_R_END_RESULT /*empty*/ +#define GROUP_R_END_RESULT(x) /*empty*/ #define GROUP_R_ARGS char *buf, int buflen -#undef GROUP_R_ENT_ARGS /*empty*/ +#define GROUP_R_ENT_ARGS void #define GROUP_R_OK gptr #define GROUP_R_BAD NULL -#define GETGROUPLIST_ARGS const char *name, gid_t basegid, gid_t *groups, \ - int *ngroups -#define HOST_R_RETURN struct hostent * -#define HOST_R_SET_RETURN void -#undef HOST_R_SET_RESULT /*empty*/ -#define HOST_R_END_RETURN void -#define HOST_R_END_RESULT(x) /*empty*/ #define HOST_R_ARGS char *buf, int buflen, int *h_errnop -#undef HOST_R_ENT_ARGS /*empty*/ +#define HOST_R_BAD NULL #define HOST_R_COPY buf, buflen #define HOST_R_COPY_ARGS char *buf, int buflen +#define HOST_R_END_RESULT(x) /*empty*/ +#define HOST_R_END_RETURN void +#undef HOST_R_ENT_ARGS /*empty*/ #define HOST_R_ERRNO *h_errnop = h_errno #define HOST_R_OK hptr -#define HOST_R_BAD NULL - -#define NET_R_RETURN struct netent * -#define NET_R_SET_RETURN void -#undef NET_R_SET_RESULT /*empty*/ -#define NET_R_END_RETURN void -#define NET_R_END_RESULT(x) /*empty*/ -#define NET_R_ARGS char *buf, int buflen -#undef NET_R_ENT_ARGS /*empty*/ -#define NET_R_COPY buf, buflen -#define NET_R_COPY_ARGS NET_R_ARGS -#define NET_R_OK nptr -#define NET_R_BAD NULL +#define HOST_R_RETURN struct hostent * +#undef HOST_R_SETANSWER +#undef HOST_R_SET_RESULT +#define HOST_R_SET_RETURN void +#undef HOSTENT_DATA -#define NGR_R_RETURN int -#define NGR_R_SET_RETURN void -#undef NGR_R_SET_RESULT /*empty*/ -#define NGR_R_END_RETURN void -#ifdef ORIGINAL_ISC_CODE -#undef NGR_R_END_RESULT /*empty*/ -#else -#define NGR_R_END_RESULT(x) /*empty*/ -#endif #define NGR_R_ARGS char *buf, int buflen -#undef NGR_R_ENT_ARGS /*empty*/ +#define NGR_R_BAD (0) #define NGR_R_COPY buf, buflen #define NGR_R_COPY_ARGS NGR_R_ARGS +#define NGR_R_CONST +#define NGR_R_END_RESULT(x) /*empty*/ +#define NGR_R_END_RETURN void +#undef NGR_R_END_ARGS /*empty*/ #define NGR_R_OK 1 -#define NGR_R_BAD (0) +#define NGR_R_RETURN int +#define NGR_R_SET_CONST const +#undef NGR_R_SET_RESULT /*empty*/ +#define NGR_R_SET_RETURN void +#undef NGR_R_SET_ARGS + + +#if !defined(NGR_R_SET_ARGS) && defined(NGR_R_END_ARGS) +#define NGR_R_SET_ARGS NGR_R_END_ARGS +#endif -#define PROTO_R_RETURN struct protoent * -#define PROTO_R_SET_RETURN void -#undef PROTO_R_SET_RESULT /*empty*/ -#define PROTO_R_END_RETURN void -#define PROTO_R_END_RESULT(x) /*empty*/ #define PROTO_R_ARGS char *buf, int buflen -#undef PROTO_R_ENT_ARGS /*empty*/ +#define PROTO_R_BAD NULL #define PROTO_R_COPY buf, buflen #define PROTO_R_COPY_ARGS PROTO_R_ARGS +#define PROTO_R_END_RESULT(x) /*empty*/ +#define PROTO_R_END_RETURN void +#undef PROTO_R_ENT_ARGS /*empty*/ +#undef PROTO_R_ENT_UNUSED #define PROTO_R_OK pptr -#define PROTO_R_BAD NULL +#undef PROTO_R_SETANSWER +#define PROTO_R_RETURN struct protoent * +#undef PROTO_R_SET_RESULT +#define PROTO_R_SET_RETURN void +#undef PROTOENT_DATA -#define PASS_R_RETURN struct passwd * -#define PASS_R_SET_RETURN void -#undef PASS_R_SET_RESULT /*empty*/ -#define PASS_R_END_RETURN void -#undef PASS_R_END_RESULT /*empty*/ #define PASS_R_ARGS char *buf, int buflen -#undef PASS_R_ENT_ARGS /*empty*/ +#define PASS_R_BAD NULL #define PASS_R_COPY buf, buflen #define PASS_R_COPY_ARGS PASS_R_ARGS +#define PASS_R_END_RESULT(x) /*empty*/ +#define PASS_R_END_RETURN void +#undef PASS_R_ENT_ARGS #define PASS_R_OK pwptr -#define PASS_R_BAD NULL +#define PASS_R_RETURN struct passwd * +#undef PASS_R_SET_RESULT /*empty*/ +#define PASS_R_SET_RETURN void -#define SERV_R_RETURN struct servent * -#define SERV_R_SET_RETURN void -#undef SERV_R_SET_RESULT /*empty*/ -#define SERV_R_END_RETURN void -#define SERV_R_END_RESULT(x) /*empty*/ #define SERV_R_ARGS char *buf, int buflen -#undef SERV_R_ENT_ARGS /*empty*/ +#define SERV_R_BAD NULL #define SERV_R_COPY buf, buflen #define SERV_R_COPY_ARGS SERV_R_ARGS +#define SERV_R_END_RESULT(x) /*empty*/ +#define SERV_R_END_RETURN void +#undef SERV_R_ENT_ARGS /*empty*/ +#undef SERV_R_ENT_UNUSED /*empty*/ #define SERV_R_OK sptr -#define SERV_R_BAD NULL +#undef SERV_R_SETANSWER +#define SERV_R_RETURN struct servent * +#undef SERV_R_SET_RESULT +#define SERV_R_SET_RETURN void + + -/* make #include <sys/ioctl.h> also #include <sys/sockio.h> */ -#define BSD_COMP +#define DE_CONST(konst, var) \ + do { \ + union { const void *k; void *v; } _u; \ + _u.k = konst; \ + var = _u.v; \ + } while (0) -#include <limits.h> /* _POSIX_PATH_MAX */ +#define UNUSED(x) (x) = (x) + +#undef NEED_SOLARIS_BITTYPES +#define ISC_SOCKLEN_T int #ifdef __GNUC__ #define ISC_FORMAT_PRINTF(fmt, args) \ @@ -130,17 +191,11 @@ #define ISC_FORMAT_PRINTF(fmt, args) #endif -/* - * Remove compiler warnings without modifying ISC source by including - * various headers here, mostly to get function prototypes. - */ -#include <string.h> -#include <strings.h> -#include <unistd.h> +/* Pull in host order macros when _XOPEN_SOURCE_EXTENDED is defined. */ +#if defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED) +#include <sys/byteorder.h> +#endif -#include <sys/types.h> -#include "sys/bitypes.h" -#include "sys/cdefs.h" +#endif -#define HAS_INET6_STRUCTS -#define H_ERRNO_IS_FUNCTION +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/port_netdb.h b/usr/src/lib/libresolv2/include/port_netdb.h new file mode 100644 index 0000000000..a5c70e823f --- /dev/null +++ b/usr/src/lib/libresolv2/include/port_netdb.h @@ -0,0 +1,188 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +#ifndef _PORT_NETDB_H +#define _PORT_NETDB_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* AI_NUMERICSERV is not a valid flag for getaddrinfo */ +#define AI_MASK 0x0038 /* mask of valid flags */ + +/* EAI_OVERFLOW was removed from ISC */ +#define EAI_BADHINTS 12 + +/* + * these are libresolv2 functions that were renamed in previous versions to + * res_* because they conflict with libnsl or libsocket + */ + +#define endhostent res_endhostent /* libnsl */ +void endhostent __P((void)); +#define endnetent res_endnetent /* libsocket */ +void endnetent __P((void)); +#define freeaddrinfo res_freeaddrinfo /* libsocket */ +void freeaddrinfo __P((struct addrinfo *)); +#define freehostent res_freehostent /* libsocket and libnsl */ +void freehostent __P((struct hostent *)); +#define getaddrinfo res_getaddrinfo /* libsocket */ +int getaddrinfo __P((const char *, const char *, + const struct addrinfo *, struct addrinfo **)); +#define gethostbyaddr res_gethostbyaddr /* libnsl */ +struct hostent *gethostbyaddr __P((const char *, int, int)); +#define gethostbyname res_gethostbyname /* libnsl */ +struct hostent *gethostbyname __P((const char *)); +#define gethostbyname2 res_gethostbyname2 /* lib/nsswitch/dns */ +struct hostent *gethostbyname2 __P((const char *, int)); +#define gethostent res_gethostent /* libnsl */ +struct hostent *gethostent __P((void)); +#define getipnodebyaddr res_getipnodebyaddr /* libnsl and libsocket */ +struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *)); +#define getipnodebyname res_getipnodebyname /* libnsl and libsocket */ +struct hostent *getipnodebyname __P((const char *, int, int, int *)); + +#define getnetbyaddr res_getnetbyaddr /* libsocket */ +struct netent *getnetbyaddr __P((unsigned long, int)); +#define getnetbyname res_getnetbyname /* libsocket */ +struct netent *getnetbyname __P((const char *)); +#define getnetent res_getnetent /* libsocket */ +struct netent *getnetent __P((void)); +#define sethostent res_sethostent /* libnsl */ +void sethostent __P((int)); +#define setnetent res_setnetent /* libsocket */ +void setnetent __P((int)); + +/* + * these are other irs functions now included in libresolv.so.2. We rename the + * ones that overlap with libsocket or libnsl + */ + +/* endprotoent is in libsocket.so.1 */ +#define endprotoent res_endprotoent +void endprotoent __P((void)); + +/* endservent is in libsocket.so.1 */ +#define endservent res_endservent +void endservent __P((void)); + +/* note: the next two symbols are variables, not functions */ + +/* gai_errlist is in libsocket.so.1 */ +#define gai_errlist res_gai_errlist + +/* gai_nerr is in libsocket.so.1 */ +#define gai_nerr res_gai_nerr + +/* gai_strerror is in libsocket.so.1 */ +#define gai_strerror res_gai_strerror +const char *gai_strerror __P((int ecode)); + +/* gethostbyaddr_r is in libnsl.so.1 */ +#define gethostbyaddr_r res_gethostbyaddr_r +struct hostent *gethostbyaddr_r __P((const char *addr, int len, int type, + struct hostent *hptr, char *buf, + int buflen, int *h_errnop)); + +/* gethostbyname_r is in libnsl.so.1 */ +#define gethostbyname_r res_gethostbyname_r +struct hostent *gethostbyname_r __P((const char *name, struct hostent *hptr, + char *buf, int buflen, int *h_errnop)); + +/* gethostent_r is in libnsl.so.1 */ +#define gethostent_r res_gethostent_r +struct hostent *gethostent_r __P((struct hostent *hptr, char *buf, int buflen, + int *h_errnop)); + +/* getnameinfo is in libsocket.so.1 */ +#define getnameinfo res_getnameinfo +int getnameinfo __P((const struct sockaddr *, size_t, char *, + size_t, char *, size_t, int)); + +/* getnetbyaddr_r is in libsocket.so.1 */ +#define getnetbyaddr_r res_getnetbyaddr_r +struct netent *getnetbyaddr_r __P((long, int, struct netent *, char *, int)); + +/* getnetbyname_r is in libsocket.so.1 */ +#define getnetbyname_r res_getnetbyname_r +struct netent *getnetbyname_r __P((const char *, struct netent *, char *, int)); + +/* getnetent_r is in libsocket.so.1 */ +#define getnetent_r res_getnetent_r +struct netent *getnetent_r __P((struct netent *, char *, int)); + +/* getprotobyname is in libsocket.so.1 */ +#define getprotobyname res_getprotobyname +struct protoent *getprotobyname __P((const char *)); + +/* getprotobyname_r is in libsocket.so.1 */ +#define getprotobyname_r res_getprotobyname_r +struct protoent *getprotobyname_r __P((const char *, struct protoent *, + char *, int)); + +/* getprotobynumber is in libsocket.so.1 */ +#define getprotobynumber res_getprotobynumber +struct protoent *getprotobynumber __P((int)); + +/* getprotobynumber_r is in libsocket.so.1 */ +#define getprotobynumber_r res_getprotobynumber_r +struct protoent *getprotobynumber_r __P((int, + struct protoent *, char *, int)); + +/* getprotoent is in libsocket.so.1 */ +#define getprotoent res_getprotoent +struct protoent *getprotoent __P((void)); + +/* getprotoent_r is in libsocket.so.1 */ +#define getprotoent_r res_getprotoent_r +struct protoent *getprotoent_r __P((struct protoent *, char *, int)); + +/* getservbyname is in libsocket.so.1 and libnsl.so.1 */ +#define getservbyname res_getservbyname +struct servent *getservbyname __P((const char *, const char *)); + +/* getservbyname_r is in libsocket.so.1 and libnsl.so.1 */ +#define getservbyname_r res_getservbyname_r +struct servent *getservbyname_r __P((const char *name, const char *, + struct servent *, char *, int)); + +/* getservbyport is in libsocket.so.1 and libnsl.so.1 */ +#define getservbyport res_getservbyport +struct servent *getservbyport __P((int, const char *)); + +/* getservbyport_r is in libsocket.so.1 and libnsl.so.1 */ +#define getservbyport_r res_getservbyport_r +struct servent *getservbyport_r __P((int port, const char *, + struct servent *, char *, int)); + +/* getservent is in libsocket.so.1 */ +#define getservent res_getservent +struct servent *getservent __P((void)); + +/* getservent_r is in libsocket.so.1 */ +#define getservent_r res_getservent_r +struct servent *getservent_r __P((struct servent *, char *, int)); + +/* innetgr is in libsocket.so.1 */ +#define innetgr res_innetgr +int innetgr __P((const char *, const char *, const char *, const char *)); + +/* setprotoent is in libsocket.so.1 */ +#define setprotoent res_setprotoent +void setprotoent __P((int)); + +/* setservent is in libsocket.so.1 */ +#define setservent res_setservent +void setservent __P((int)); + + + +#ifdef __cplusplus +} +#endif + +#endif /* _PORT_NETDB_H */ diff --git a/usr/src/lib/libresolv2/include/port_resolv.h b/usr/src/lib/libresolv2/include/port_resolv.h new file mode 100644 index 0000000000..cd1a97d40c --- /dev/null +++ b/usr/src/lib/libresolv2/include/port_resolv.h @@ -0,0 +1,42 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _PORT_RESOLV_H +#define _PORT_RESOLV_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* RES_NSID has the same value as RES_NO_NIBBLE, which has been deleted */ +#define RES_NSID 0x00040000 /* request name server ID */ + +/* RES_DEFAULT has a new value in libbind-6.0 */ +#undef RES_DEFAULT +#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | \ + RES_DNSRCH | RES_NO_NIBBLE2) + +#ifndef __ultrix__ +u_int16_t _getshort __P((const uchar_t *)); +u_int32_t _getlong __P((const uchar_t *)); +#endif + +/* rename functions so they can be wrapped (see sunw/sunw_wrappers.c */ +#define p_option isc_p_option +const char *p_option(ulong_t option); +#define p_secstodate isc_p_secstodate +char *p_secstodate(ulong_t secs); + +/* prevent namespace pollution */ +#define res_protocolnumber __res_protocolnumber +#define res_servicenumber __res_servicenumber + + + +#ifdef __cplusplus +} +#endif + +#endif /* _PORT_RESOLV_H */ diff --git a/usr/src/lib/libresolv2/include/prand_conf.h b/usr/src/lib/libresolv2/include/prand_conf.h deleted file mode 100644 index 89aa78295c..0000000000 --- a/usr/src/lib/libresolv2/include/prand_conf.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2001 by Sun Microsystems, Inc. - * All rights reserved. - * - * No ISC copyright for this file. - */ - -#ifndef _PRAND_CMD_H_ -#define _PRAND_CMD_H_ - -#pragma ident "%Z%%M% %I% %E% SMI" - -static const char *cmds[] = { - "/bin/ps -ef 2>&1", - "/usr/ucb/netstat -an 2>&1", - "/bin/df 2>&1", - "/usr/bin/dig com. soa +ti=1 +retry=0 2>&1", - "/usr/ucb/uptime 2>&1", - "/usr/ucb/netstat -an 2>&1", - "/bin/iostat 2>&1", - NULL -}; - -static const char *dirs[] = { - "/tmp", - "/var/tmp", - ".", - "/", - "/var/spool", - "/var/adm", - "/dev", - "/var/mail", - "/home", - NULL -}; - -static const char *files[] = { - "/proc/self/status", - "/var/adm/messages", - "/var/adm/wtmp", - "/var/adm/lastlog", - NULL -}; - -#endif /* _PRAND_CMD_H_ */ diff --git a/usr/src/lib/libresolv2/include/res_update.h b/usr/src/lib/libresolv2/include/res_update.h index e2eb9c651f..419dfc43d5 100644 --- a/usr/src/lib/libresolv2/include/res_update.h +++ b/usr/src/lib/libresolv2/include/res_update.h @@ -1,68 +1,67 @@ /* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" /* + * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1999 by Internet Software Consortium, Inc. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* - * $Id: res_update.h,v 8.1 1999/10/07 08:24:13 vixie Exp $ + * $Id: res_update.h,v 1.3 2005/04/27 04:56:15 sra Exp $ */ #ifndef __RES_UPDATE_H #define __RES_UPDATE_H +/*! \file */ + #include <sys/types.h> -#include <sys/bitypes.h> #include <arpa/nameser.h> #include <isc/list.h> #include <resolv.h> -#ifdef ORIGINAL_ISC_CODE -#else -/* - * ISC changed the ns_updrec structure. However, it's a public interface - * in Solaris, so it's time to break out that old #define magic. - */ -#define ns_updrec __ISC_ns_updrec +#ifndef ORIGINAL_ISC_CODE +/* definition of u_int32_t needed on Solaris */ +#include <sys/bitypes.h> +/* need to rename ns_updrec before we define it here */ +#include "arpa/port_nameser.h" #endif /* ORIGINAL_ISC_CODE */ -/* + + +/*% * This RR-like structure is particular to UPDATE. */ struct ns_updrec { LINK(struct ns_updrec) r_link, r_glink; - ns_sect r_section; /* ZONE/PREREQUISITE/UPDATE */ - char * r_dname; /* owner of the RR */ - ns_class r_class; /* class number */ - ns_type r_type; /* type number */ - u_int32_t r_ttl; /* time to live */ - u_char * r_data; /* rdata fields as text string */ - u_int r_size; /* size of r_data field */ - int r_opcode; /* type of operation */ + ns_sect r_section; /*%< ZONE/PREREQUISITE/UPDATE */ + char * r_dname; /*%< owner of the RR */ + ns_class r_class; /*%< class number */ + ns_type r_type; /*%< type number */ + u_int32_t r_ttl; /*%< time to live */ + u_char * r_data; /*%< rdata fields as text string */ + u_int r_size; /*%< size of r_data field */ + int r_opcode; /*%< type of operation */ /* following fields for private use by the resolver/server routines */ - struct databuf *r_dp; /* databuf to process */ - struct databuf *r_deldp; /* databuf's deleted/overwritten */ - u_int r_zone; /* zone number on server */ + struct databuf *r_dp; /*%< databuf to process */ + struct databuf *r_deldp; /*%< databuf's deleted/overwritten */ + u_int r_zone; /*%< zone number on server */ }; typedef struct ns_updrec ns_updrec; - typedef LIST(ns_updrec) ns_updque; #ifdef ORIGINAL_ISC_CODE @@ -73,27 +72,10 @@ typedef LIST(ns_updrec) ns_updque; #define res_nmkupdate __res_nmkupdate #define res_nupdate __res_nupdate #else -/* - * For BIND 8.2.2, ISC removed the dynamic update functions, and the - * definition of the ns_updrec structure, from the public include files - * (<resolv.h>, <arpa/nameser.h>. However, res_update(), res_mkupdate(), - * and res_mkupdrec() are in the public libresolv interface in Solaris, - * so we can't easily remove them. Thus, ISC's new versions of res_mkupdate() - * etc. can't be exposed under their original names. - * - * res_nmkupdate() and res_nupdate are new. We could either change them - * to accept the <arpa/nameser.h> ns_updrec, or leave them unchanged and - * undocumented. Since ISC may change ns_updrec again, we pick the latter - * solution for now. - */ -#define res_mkupdate __ISC_res_mkupdate -#define res_update __ISC_res_update -#define res_mkupdrec __ISC_res_mkupdrec -#define res_freeupdrec __ISC_res_freeupdrec -#define res_nmkupdate __ISC_res_nmkupdate -#define res_nupdate __ISC_res_nupdate +/* these are renamed in "port_nameser.h" */ #endif /* ORIGINAL_ISC_CODE */ + int res_mkupdate __P((ns_updrec *, u_char *, int)); int res_update __P((ns_updrec *)); ns_updrec * res_mkupdrec __P((int, const char *, u_int, u_int, u_long)); @@ -102,3 +84,5 @@ int res_nmkupdate __P((res_state, ns_updrec *, u_char *, int)); int res_nupdate __P((res_state, ns_updrec *, ns_tsig_key *)); #endif /*__RES_UPDATE_H*/ + +/*! \file */ diff --git a/usr/src/lib/libresolv2/include/resolv_mt.h b/usr/src/lib/libresolv2/include/resolv_mt.h index e26fd18f02..27963a1207 100644 --- a/usr/src/lib/libresolv2/include/resolv_mt.h +++ b/usr/src/lib/libresolv2/include/resolv_mt.h @@ -1,17 +1,5 @@ -/* - * Copyright (c) 1998-1999 by Sun Microsystems, Inc. - */ - -#ifndef _RESOLV_MT_H -#define _RESOLV_MT_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef SUNW_MT_RESOLVER +#ifndef _RESOLV_MT_H +#define _RESOLV_MT_H #include <sys/types.h> #include <netinet/in.h> @@ -20,50 +8,40 @@ extern "C" { /* Access functions for the libresolv private interface */ -int __res_enable_mt(void); -int __res_disable_mt(void); +int __res_enable_mt(void); +int __res_disable_mt(void); /* Per-thread context */ typedef struct { -#ifdef SUNW_HOSTS_FALLBACK - int no_hosts_fallback_private; -#endif /* SUNW_HOSTS_FALLBACK */ -#ifdef SUNW_OVERRIDE_RETRY - int retry_save; - int retry_private; -#endif /* SUNW_OVERRIDE_RETRY */ - char inet_nsap_ntoa_tmpbuf[255*3]; - char sym_ntos_unname[20]; - char sym_ntop_unname[20]; - char p_option_nbuf[40]; - char p_time_nbuf[40]; - char precsize_ntoa_retbuf[sizeof "90000000.00"]; - char loc_ntoa_tmpbuf[sizeof +int no_hosts_fallback_private; +int retry_save; +int retry_private; +char inet_nsap_ntoa_tmpbuf[255*3]; +char sym_ntos_unname[20]; +char sym_ntop_unname[20]; +char p_option_nbuf[40]; +char p_time_nbuf[40]; +char precsize_ntoa_retbuf[sizeof "90000000.00"]; +char loc_ntoa_tmpbuf[sizeof "1000 60 60.000 N 1000 60 60.000 W -12345678.00m 90000000.00m 90000000.00m 90000000.00m"]; - char p_secstodate_output[15]; +char p_secstodate_output[15]; } mtctxres_t; /* Thread-specific data (TSD) */ -extern mtctxres_t *___mtctxres(); -#define mtctxres (___mtctxres()) +mtctxres_t *___mtctxres(void); +#define mtctxres (___mtctxres()) /* Various static data that should be TSD */ -#define sym_ntos_unname (mtctxres->sym_ntos_unname) -#define sym_ntop_unname (mtctxres->sym_ntop_unname) -#define inet_nsap_ntoa_tmpbuf (mtctxres->inet_nsap_ntoa_tmpbuf) -#define p_option_nbuf (mtctxres->p_option_nbuf) -#define p_time_nbuf (mtctxres->p_time_nbuf) -#define precsize_ntoa_retbuf (mtctxres->precsize_ntoa_retbuf) -#define loc_ntoa_tmpbuf (mtctxres->loc_ntoa_tmpbuf) -#define p_secstodate_output (mtctxres->p_secstodate_output) - -#endif /* SUNW_MT_RESOLVER */ - -#ifdef __cplusplus -} -#endif +#define sym_ntos_unname (mtctxres->sym_ntos_unname) +#define sym_ntop_unname (mtctxres->sym_ntop_unname) +#define inet_nsap_ntoa_tmpbuf (mtctxres->inet_nsap_ntoa_tmpbuf) +#define p_option_nbuf (mtctxres->p_option_nbuf) +#define p_time_nbuf (mtctxres->p_time_nbuf) +#define precsize_ntoa_retbuf (mtctxres->precsize_ntoa_retbuf) +#define loc_ntoa_tmpbuf (mtctxres->loc_ntoa_tmpbuf) +#define p_secstodate_output (mtctxres->p_secstodate_output) #endif /* _RESOLV_MT_H */ diff --git a/usr/src/lib/libresolv2/include/sunw_dst_init.h b/usr/src/lib/libresolv2/include/sunw_dst_init.h deleted file mode 100644 index 72a93e3d70..0000000000 --- a/usr/src/lib/libresolv2/include/sunw_dst_init.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifndef _SUNW_DST_INIT_H -#define _SUNW_DST_INIT_H - -extern int sunw_dst_bsafe_init(void); -extern int sunw_dst_rsaref_init(void); -extern int sunw_dst_hmac_md5_init(void); -extern int sunw_dst_eay_dss_init(void); -extern int sunw_dst_cylink_init(void); - -#ifndef __SUNW_DST_INIT_NODEFINE - -#define dst_bsafe_init sunw_dst_bsafe_init -#define dst_rsaref_init sunw_dst_rsaref_init -#define dst_hmac_md5_init sunw_dst_hmac_md5_init -#define dst_eay_dss_init sunw_dst_eay_dss_init -#define dst_cylink_init sunw_dst_cylink_init - -#endif /* __SUNW_DST_INIT_NODEFINE */ - -#endif /* _SUNW_DST_INIT_H */ diff --git a/usr/src/lib/libresolv2/include/sunw_irs_init.h b/usr/src/lib/libresolv2/include/sunw_irs_init.h deleted file mode 100644 index d249a0f7e6..0000000000 --- a/usr/src/lib/libresolv2/include/sunw_irs_init.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 1999 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#ifndef _SUNW_IRS_INIT_H -#define _SUNW_IRS_INIT_H - -extern struct irs_acc *sunw_irs_nis_acc(const char *); -extern struct irs_acc *sunw_irs_irp_acc(const char *); - -#ifndef __SUNW_IRS_INIT_NODEFINE - -#define __irs_nis_acc sunw_irs_nis_acc -#define __irs_irp_acc sunw_irs_irp_acc - -#endif /* __SUNW_IRS_INIT_NODEFINE */ - -#endif /* _SUNW_IRS_INIT_H */ diff --git a/usr/src/lib/libresolv2/include/sunw_port_after.h b/usr/src/lib/libresolv2/include/sunw_port_after.h new file mode 100644 index 0000000000..fce7445189 --- /dev/null +++ b/usr/src/lib/libresolv2/include/sunw_port_after.h @@ -0,0 +1,123 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _SUNW_PORT_AFTER_H +#define _SUNW_PORT_AFTER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * rename setnetgrent and endnetgrent which were formerly in a separate irs + * shared library. These functions should come from libc.so + */ +#define setnetgrent res_setnetgrent +#ifdef SETNETGRENT_ARGS +void setnetgrent(SETNETGRENT_ARGS); +#else +void setnetgrent(const char *netgroup); +#endif + +#define endnetgrent res_endnetgrent +void endnetgrent(void); + + +/* + * include ports for the public header files. ISC's versions are quite different + * from those currently in OpenSolaris. + */ + +#ifdef _RESOLV_H_ +#include <port_resolv.h> +#endif /* _RESOLV_H_ */ + +#ifdef _NETDB_H +#include <port_netdb.h> +#endif /* _NETDB_H */ + +#ifdef _ARPA_INET_H +#include <arpa/port_inet.h> +#endif /* _ARPA_INET_H */ + +#ifdef _ARPA_NAMESER_H +#include <arpa/port_nameser.h> +#endif /* _ARPA_NAMESER_H */ + + +#ifdef _ARPA_NAMESER_COMPAT_H +/* no changes */ +#endif /* _ARPA_NAMESER_COMPAT_H */ + +/* version-specific defines */ +#include <os_version.h> + +/* + * Prior to 2.6, Solaris needs a prototype for gethostname(). + */ +#if (OS_MAJOR == 5 && OS_MINOR < 6) +extern int gethostname(char *, size_t); +#endif +/* + * gethostid() was not available until 2.5 + * setsockopt(SO_REUSEADDR) fails on unix domain sockets before 2.5 + * use ioctl(FIONBIO) rather than fcntl() calls to set/clear non-blocking i/o. + */ +#if (OS_MAJOR == 5 && OS_MINOR < 5) +#define GET_HOST_ID_MISSING +#define NO_UNIX_REUSEADDR +#define USE_FIONBIO_IOCTL +#endif + +#if (OS_MAJOR == 5 && OS_MINOR < 11) +#define NEED_STRSEP +extern char *strsep(char **, const char *); +#endif + + +/* + * Solaris 2.5 and later have getrlimit(), setrlimit() and getrusage(). + */ +#if (OS_MAJOR > 5 || (OS_MAJOR == 5 && OS_MINOR >= 5)) +#include <sys/resource.h> +#define HAVE_GETRUSAGE +#define RLIMIT_TYPE rlim_t +#define RLIMIT_FILE_INFINITY +#endif + +/* the default syslog facility of named/lwresd. */ +#ifndef ISC_FACILITY +#define ISC_FACILITY LOG_DAEMON +#endif + + +/* + * Solaris 8 has if_nametoindex(). + */ +#if (OS_MAJOR > 5 || (OS_MAJOR == 5 && OS_MINOR >= 8)) +#define USE_IFNAMELINKID +#endif + +#undef ALIGN +#if (OS_MAJOR == 5 && OS_MINOR > 8) +#define ALIGN(x) (((uintptr_t)(x) + (sizeof (char *) - 1UL)) & \ + ~(sizeof (char *) - 1UL)) +#else +#define ALIGN(x) (((unsigned long)(x) + (sizeof (char *) - 1UL)) & \ + ~(sizeof (char *) - 1UL)) +#endif + +#if (OS_MAJOR == 5 && OS_MINOR < 5) +#ifndef USE_FIONBIO_IOCTL +#define USE_FIONBIO_IOCTL 1 +#endif +#endif + + +#ifdef __cplusplus +} +#endif + +#endif /* _SUNW_PORT_AFTER_H */ diff --git a/usr/src/lib/libresolv2/include/sunw_port_before.h b/usr/src/lib/libresolv2/include/sunw_port_before.h new file mode 100644 index 0000000000..776e311fcc --- /dev/null +++ b/usr/src/lib/libresolv2/include/sunw_port_before.h @@ -0,0 +1,43 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _SUNW_PORT_BEFORE_H +#define _SUNW_PORT_BEFORE_H + +#ifdef SUNW_OPTIONS +#include <conf/sunoptions.h> +#endif + +/* version-specific defines */ +#include <os_version.h> +#if (OS_MAJOR == 5 && OS_MINOR < 6) +#ifndef SOLARIS_BITTYPES +#define NEED_SOLARIS_BITTYPES 1 +#endif +#endif + +#if (OS_MAJOR == 5 && OS_MINOR < 5) +#undef HAS_PTHREADS +#else +#define HAS_PTHREADS +#endif + +#if defined(HAS_PTHREADS) && defined(_REENTRANT) +#define DO_PTHREADS +#endif + +/* + * need these if we are using public versions of nameser.h, resolv.h, and + * inet.h + */ +#include <sys/param.h> +#if (!defined(BSD)) || (BSD < 199306) +#include <sys/bitypes.h> +#else +#include <sys/types.h> +#endif +#include <sys/cdefs.h> + +#endif /* _SUNW_PORT_BEFORE_H */ diff --git a/usr/src/lib/libresolv2/include/sys/bitypes.h b/usr/src/lib/libresolv2/include/sys/bitypes.h index 5228129f3b..54fb42bad7 100644 --- a/usr/src/lib/libresolv2/include/sys/bitypes.h +++ b/usr/src/lib/libresolv2/include/sys/bitypes.h @@ -1,26 +1,21 @@ /* - * Copyright (c) 1997-2000 by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* - * Copyright (c) 1996-1999 by Internet Software Consortium. + * Copyright (C) 2004, 2007, 2008 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 1998, 1999, 2001 Internet Software Consortium. * - * Permission to use, copy, modify, and distribute this software for any + * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. */ -#pragma ident "%Z%%M% %I% %E% SMI" +/* $Id: bitypes.h,v 1.7 2008/11/14 02:54:35 tbox Exp $ */ #ifndef __BIT_TYPES_DEFINED__ #define __BIT_TYPES_DEFINED__ @@ -29,18 +24,14 @@ * Basic integral types. Omit the typedef if * not possible for a machine/compiler combination. */ -#ifndef _SYS_INT_TYPES_H + +#ifdef NEED_SOLARIS_BITTYPES typedef /*signed*/ char int8_t; typedef short int16_t; typedef int int32_t; -#endif /* _SYS_INT_TYPES_H */ +#endif typedef unsigned char u_int8_t; typedef unsigned short u_int16_t; typedef unsigned int u_int32_t; -# if 0 /* don't fight with these unless you need them */ - typedef long long int64_t; - typedef unsigned long long u_int64_t; -# endif - #endif /* __BIT_TYPES_DEFINED__ */ diff --git a/usr/src/lib/libresolv2/include/sys/cdefs.h b/usr/src/lib/libresolv2/include/sys/cdefs.h index 9738c69582..67aac00cc7 100644 --- a/usr/src/lib/libresolv2/include/sys/cdefs.h +++ b/usr/src/lib/libresolv2/include/sys/cdefs.h @@ -1,9 +1,4 @@ /* - * Copyright (c) 1997, by Sun Microsystems, Inc. - * All rights reserved. - */ - -/* * ++Copyright++ 1991, 1993 * - * Copyright (c) 1991, 1993 @@ -60,11 +55,9 @@ /* * @(#)cdefs.h 8.1 (Berkeley) 6/2/93 - * $Id: cdefs.h,v 1.1 1996/11/22 02:20:19 vixie Exp $ + * $Id: cdefs.h,v 1.2 2004/07/19 05:54:07 marka Exp $ */ -#pragma ident "%Z%%M% %I% %E% SMI" - #ifndef _CDEFS_H_ #define _CDEFS_H_ @@ -134,7 +127,7 @@ * these work for GNU C++ (modulo a slight glitch in the C++ grammar * in the distribution version of 2.5.5). */ -#if !defined(__GNUC__) || __GNUC__ < 2 || __GNUC_MINOR__ < 5 +#if !defined(__GNUC__) || __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) #define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */ #if defined(__GNUC__) && !defined(__STRICT_ANSI__) #define __dead __volatile diff --git a/usr/src/lib/libresolv2/irs/Makefile b/usr/src/lib/libresolv2/irs/Makefile deleted file mode 100644 index 58a519e1de..0000000000 --- a/usr/src/lib/libresolv2/irs/Makefile +++ /dev/null @@ -1,80 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2008 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# - -include ../../../Makefile.master -include ../../Makefile.lib - -SUBDIRS = $(MACH) -$(BUILD64)SUBDIRS += $(MACH64) - -all := TARGET= all -clean := TARGET= clean -clobber := TARGET= clobber -delete := TARGET= delete -install := TARGET= install -lint := TARGET= lint -_msg := TARGET= _msg -package := TARGET= package - -LIBRARY= irs.a -TEXT_DOMAIN= SUNW_OST_OSLIB -XGETFLAGS= -a -POFILE= $(LIBRARY:.a=.po) -POFILES= generic.po - -SED= sed -GREP= grep - -.KEEP_STATE: - -all clean clobber delete install lint package: $(SUBDIRS) - -# install rule for install_h target -$(ROOTHDRDIR)/%: % - $(INS.file) - -install_h: $(ROOTHDRS) - -check: $(CHECKHDRS) - -$(SUBDIRS): FRC - @cd $@; pwd; $(MAKE) $(TARGET) - -_msg: $(MSGDOMAIN) $(POFILE) - $(RM) $(MSGDOMAIN)/$(POFILE) - $(CP) $(POFILE) $(MSGDOMAIN) - -$(POFILE): $(POFILES) - $(RM) $@ - $(CAT) $(POFILES) > $@ - -$(POFILES): - $(RM) messages.po - $(XGETTEXT) $(XGETFLAGS) *.[ch]* */*.[ch]* - $(SED) -e '/^# msg/d' -e '/^domain/d' messages.po > $@ - $(RM) messages.po - -FRC: diff --git a/usr/src/lib/libresolv2/irs/Makefile.com b/usr/src/lib/libresolv2/irs/Makefile.com deleted file mode 100644 index a8e27db89e..0000000000 --- a/usr/src/lib/libresolv2/irs/Makefile.com +++ /dev/null @@ -1,89 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# - -LIBRARY= irs.a -VERS= .1 - -IRSDYNOBJS= nis_nw.o nis_pr.o nis_pw.o nis_sv.o \ - nis.o nis_gr.o nis_ho.o nis_ng.o \ - irp.o irpmarshall.o irp_ho.o irp_nw.o \ - irp_pr.o irp_sv.o irp_gr.o irp_ng.o \ - irp_pw.o getnetent.o getpwent_r.o getgrent_r.o \ - getservent_r.o getnetent_r.o getnetgrent_r.o getgrent.o \ - getnetgrent.o getprotoent.o getpwent.o getservent.o \ - getprotoent_r.o getnameinfo.o gai_strerror.o - -SUNWOBJS= sunw_irs_nis_acc.o - -OBJECTS= $(IRSDYNOBJS) $(SUNWOBJS) - -include ../../../Makefile.lib - -LIBNAME= $(LIBRARY:%.a=%) -LIBS= $(DYNLIB) -LDLIBS += -lresolv -lnsl -lsocket -lc - -MAPFILES = ../mapfile-vers - -SRCDIR= ../../common/irs -SRCS= $(IRSDYNOBJS:%.o=$(SRCDIR)/%.c) \ - $(SUNWOBJS:%.o=../../common/sunw/%.c) - -ROOTLIBDIR= $(ROOT)/usr/lib/dns -ROOTLIBDIR64= $(ROOT)/usr/lib/dns/$(MACH64) - -# Local Libresolv definitions -SOLCOMPAT = -Dgethostbyname=res_gethostbyname \ - -Dgethostbyaddr=res_gethostbyaddr -Dgetnetbyname=res_getnetbyname \ - -Dgethostbyname2=res_gethostbyname2\ - -Dgetnetbyaddr=res_getnetbyaddr -Dsethostent=res_sethostent \ - -Dendhostent=res_endhostent -Dgethostent=res_gethostent \ - -Dsetnetent=res_setnetent -Dendnetent=res_endnetent \ - -Dgetnetent=res_getnetent -Dsocket=_socket - -CRYPTINCL= -I../../common/cylink -I../../common/dnssafe -CRYPTFLAGS= -DCYLINK_DSS -DHMAC_MD5 -DUSE_MD5 -DDNSSAFE - -CPPFLAGS += $(CRYPTFLAGS) $(CRYPTINCL) -CPPFLAGS += -D_SYS_STREAM_H -D_REENTRANT -DSVR4 -DSUNW_OPTIONS \ - -D__SUNW_IRS_INIT_NODEFINE $(SOLCOMPAT) \ - -I../../include -I../../../common/inc - -.KEEP_STATE: - -all: $(LIBS) - -lint: lintcheck - -$(ROOTLIBDIR) $(ROOTLIBDIR64): - $(INS.dir) - -include ../../../Makefile.targ - -pics/%.o: ../../common/sunw/%.c - $(COMPILE.c) -o $@ $< - $(POST_PROCESS_O) diff --git a/usr/src/lib/libresolv2/irs/amd64/Makefile b/usr/src/lib/libresolv2/irs/amd64/Makefile deleted file mode 100644 index 8df6381cfa..0000000000 --- a/usr/src/lib/libresolv2/irs/amd64/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# - -include ../Makefile.com -include ../../../Makefile.lib.64 - -all: $(LIBS) - -install: all $(ROOTLIBDIR64) .WAIT $(ROOTLIBS64) diff --git a/usr/src/lib/libresolv2/irs/i386/Makefile b/usr/src/lib/libresolv2/irs/i386/Makefile deleted file mode 100644 index 009d72b5eb..0000000000 --- a/usr/src/lib/libresolv2/irs/i386/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# -# lib/libresolv2/irs/i386/Makefile -# - -include ../Makefile.com - -install: all $(ROOTLIBDIR) .WAIT $(ROOTLIBS) diff --git a/usr/src/lib/libresolv2/irs/mapfile-vers b/usr/src/lib/libresolv2/irs/mapfile-vers deleted file mode 100644 index 083e9c033b..0000000000 --- a/usr/src/lib/libresolv2/irs/mapfile-vers +++ /dev/null @@ -1,46 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# -# -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -# -# MAPFILE HEADER START -# -# WARNING: STOP NOW. DO NOT MODIFY THIS FILE. -# Object versioning must comply with the rules detailed in -# -# usr/src/lib/README.mapfiles -# -# You should not be making modifications here until you've read the most current -# copy of that file. If you need help, contact a gatekeeper for guidance. -# -# MAPFILE HEADER END -# - -SUNWprivate_1.1 { - global: - __irs_irp_acc; - __irs_nis_acc; - local: - *; -}; diff --git a/usr/src/lib/libresolv2/irs/sparc/Makefile b/usr/src/lib/libresolv2/irs/sparc/Makefile deleted file mode 100644 index 8dd442702e..0000000000 --- a/usr/src/lib/libresolv2/irs/sparc/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# -# lib/libresolv2/irs/sparc/Makefile -# - -include ../Makefile.com - -install: all $(ROOTLIBDIR) .WAIT $(ROOTLIBS) diff --git a/usr/src/lib/libresolv2/irs/sparcv9/Makefile b/usr/src/lib/libresolv2/irs/sparcv9/Makefile deleted file mode 100644 index 51ec6b8a9d..0000000000 --- a/usr/src/lib/libresolv2/irs/sparcv9/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# ident "%Z%%M% %I% %E% SMI" -# -# lib/libresolv2/irs/sparcv9/Makefile -# - -include ../Makefile.com -include ../../../Makefile.lib.64 - -install: all $(ROOTLIBDIR64) .WAIT $(ROOTLIBS64) diff --git a/usr/src/pkgdefs/SUNWcsl/prototype_com b/usr/src/pkgdefs/SUNWcsl/prototype_com index dcbac34a9e..f6fc5b8cfd 100644 --- a/usr/src/pkgdefs/SUNWcsl/prototype_com +++ b/usr/src/pkgdefs/SUNWcsl/prototype_com @@ -60,12 +60,6 @@ f none usr/lib/cfgadm/usb.so.1 755 root bin s none usr/lib/cfgadm/usb.so=./usb.so.1 f none usr/lib/cfgadm/ib.so.1 755 root bin s none usr/lib/cfgadm/ib.so=./ib.so.1 -d none usr/lib/dns 755 root bin -# EXPORT DELETE START -f none usr/lib/dns/cylink.so.1 755 root bin -f none usr/lib/dns/dnssafe.so.1 755 root bin -# EXPORT DELETE END -f none usr/lib/dns/irs.so.1 755 root bin f none usr/lib/extendedFILE.so.1 755 root bin f none usr/lib/lib.b 444 root bin s none usr/lib/libadm.so=../../lib/libadm.so.1 diff --git a/usr/src/pkgdefs/SUNWcsl/prototype_i386 b/usr/src/pkgdefs/SUNWcsl/prototype_i386 index 5d0e41290f..0e389c13d5 100644 --- a/usr/src/pkgdefs/SUNWcsl/prototype_i386 +++ b/usr/src/pkgdefs/SUNWcsl/prototype_i386 @@ -77,12 +77,6 @@ f none usr/lib/cfgadm/sata.so.1 755 root bin s none usr/lib/cfgadm/sata.so=./sata.so.1 f none usr/lib/cfgadm/amd64/sata.so.1 755 root bin s none usr/lib/cfgadm/amd64/sata.so=./sata.so.1 -d none usr/lib/dns/amd64 755 root bin -# EXPORT DELETE START -f none usr/lib/dns/amd64/cylink.so.1 755 root bin -f none usr/lib/dns/amd64/dnssafe.so.1 755 root bin -# EXPORT DELETE END -f none usr/lib/dns/amd64/irs.so.1 755 root bin d none usr/lib/iconv/amd64 755 root bin d none usr/lib/lwp/amd64 755 root bin s none usr/lib/lwp/64=amd64 diff --git a/usr/src/pkgdefs/SUNWcsl/prototype_sparc b/usr/src/pkgdefs/SUNWcsl/prototype_sparc index 0bc57576ba..c423add8f5 100644 --- a/usr/src/pkgdefs/SUNWcsl/prototype_sparc +++ b/usr/src/pkgdefs/SUNWcsl/prototype_sparc @@ -70,12 +70,6 @@ f none usr/lib/cfgadm/sparcv9/usb.so.1 755 root bin s none usr/lib/cfgadm/sparcv9/usb.so=./usb.so.1 f none usr/lib/cfgadm/sparcv9/ib.so.1 755 root bin s none usr/lib/cfgadm/sparcv9/ib.so=./ib.so.1 -d none usr/lib/dns/sparcv9 755 root bin -# EXPORT DELETE START -f none usr/lib/dns/sparcv9/cylink.so.1 755 root bin -f none usr/lib/dns/sparcv9/dnssafe.so.1 755 root bin -# EXPORT DELETE END -f none usr/lib/dns/sparcv9/irs.so.1 755 root bin d none usr/lib/iconv/sparcv9 755 root bin d none usr/lib/lwp/sparcv9 755 root bin s none usr/lib/lwp/64=sparcv9 diff --git a/usr/src/tools/findunref/exception_list.open b/usr/src/tools/findunref/exception_list.open index cde763d1a4..0bf957051f 100644 --- a/usr/src/tools/findunref/exception_list.open +++ b/usr/src/tools/findunref/exception_list.open @@ -215,18 +215,6 @@ # Ignore files originally supplied by ISC (Internet Software Consortium) # as part of a BIND release. # -./usr/src/lib/libresolv2/common/cylink/bn68000.c -./usr/src/lib/libresolv2/common/cylink/bn8086.c -./usr/src/lib/libresolv2/common/cylink/lbn68000.c -./usr/src/lib/libresolv2/common/cylink/lbn68000.h -./usr/src/lib/libresolv2/common/cylink/lbn68020.c -./usr/src/lib/libresolv2/common/cylink/lbn68020.h -./usr/src/lib/libresolv2/common/cylink/lbn80386.h -./usr/src/lib/libresolv2/common/cylink/lbn8086.h -./usr/src/lib/libresolv2/common/cylink/lbnppc.c -./usr/src/lib/libresolv2/common/cylink/lbnppc.h -./usr/src/lib/libresolv2/common/cylink/ppcasm.h -./usr/src/lib/libresolv2/common/cylink/sizetest.c ./usr/src/lib/libresolv2/common/irs/getaddrinfo.c ./usr/src/lib/libresolv2/common/irs/nis_p.h ./usr/src/lib/libresolv2/common/resolv/res_mkupdate.h diff --git a/usr/src/xmod/xmod_files b/usr/src/xmod/xmod_files index 493fcd5578..2386b9f135 100644 --- a/usr/src/xmod/xmod_files +++ b/usr/src/xmod/xmod_files @@ -45,7 +45,6 @@ cmd/cmd-inet/usr.sbin/bootconfchk ../closed/uts/common/io/ib/clients/sdpib ../closed/uts/common/sys/ib/clients/sdpib lib/libresolv2/cylink -lib/libresolv2/dnssafe ../closed/lib/gss_mechs/mech_dh/backend/Makefile.export ../closed/lib/gss_mechs/mech_dh/backend/mapfile-vers-export ../closed/lib/gss_mechs/mech_dh/dh1024/Makefile.export |