head 1.23; access; symbols netbsd-10-0-RELEASE:1.23 netbsd-10-0-RC6:1.23 netbsd-10-0-RC5:1.23 netbsd-10-0-RC4:1.23 netbsd-10-0-RC3:1.23 netbsd-10-0-RC2:1.23 thorpej-ifq:1.23.0.44 thorpej-ifq-base:1.23 thorpej-altq-separation:1.23.0.42 thorpej-altq-separation-base:1.23 netbsd-10-0-RC1:1.23 netbsd-10:1.23.0.40 netbsd-10-base:1.23 bouyer-sunxi-drm:1.23.0.38 bouyer-sunxi-drm-base:1.23 netbsd-9-3-RELEASE:1.23 thorpej-i2c-spi-conf2:1.23.0.36 thorpej-i2c-spi-conf2-base:1.23 thorpej-futex2:1.23.0.34 thorpej-futex2-base:1.23 thorpej-cfargs2:1.23.0.32 thorpej-cfargs2-base:1.23 cjep_sun2x-base1:1.23 cjep_sun2x:1.23.0.30 cjep_sun2x-base:1.23 cjep_staticlib_x-base1:1.23 netbsd-9-2-RELEASE:1.23 cjep_staticlib_x:1.23.0.28 cjep_staticlib_x-base:1.23 thorpej-i2c-spi-conf:1.23.0.26 thorpej-i2c-spi-conf-base:1.23 thorpej-cfargs:1.23.0.24 thorpej-cfargs-base:1.23 thorpej-futex:1.23.0.22 thorpej-futex-base:1.23 netbsd-9-1-RELEASE:1.23 bouyer-xenpvh-base2:1.23 phil-wifi-20200421:1.23 bouyer-xenpvh-base1:1.23 phil-wifi-20200411:1.23 bouyer-xenpvh:1.23.0.20 bouyer-xenpvh-base:1.23 is-mlppp:1.23.0.18 is-mlppp-base:1.23 phil-wifi-20200406:1.23 netbsd-8-2-RELEASE:1.23 ad-namecache-base3:1.23 netbsd-9-0-RELEASE:1.23 netbsd-9-0-RC2:1.23 ad-namecache-base2:1.23 ad-namecache-base1:1.23 ad-namecache:1.23.0.16 ad-namecache-base:1.23 netbsd-9-0-RC1:1.23 phil-wifi-20191119:1.23 netbsd-9:1.23.0.14 netbsd-9-base:1.23 phil-wifi-20190609:1.23 netbsd-8-1-RELEASE:1.23 netbsd-8-1-RC1:1.23 isaki-audio2:1.23.0.12 isaki-audio2-base:1.23 pgoyette-compat-merge-20190127:1.23 pgoyette-compat-20190127:1.23 pgoyette-compat-20190118:1.23 pgoyette-compat-1226:1.23 pgoyette-compat-1126:1.23 pgoyette-compat-1020:1.23 pgoyette-compat-0930:1.23 pgoyette-compat-0906:1.23 netbsd-7-2-RELEASE:1.21 pgoyette-compat-0728:1.23 netbsd-8-0-RELEASE:1.23 phil-wifi:1.23.0.10 phil-wifi-base:1.23 pgoyette-compat-0625:1.23 netbsd-8-0-RC2:1.23 pgoyette-compat-0521:1.23 pgoyette-compat-0502:1.23 pgoyette-compat-0422:1.23 netbsd-8-0-RC1:1.23 pgoyette-compat-0415:1.23 pgoyette-compat-0407:1.23 pgoyette-compat-0330:1.23 pgoyette-compat-0322:1.23 pgoyette-compat-0315:1.23 netbsd-7-1-2-RELEASE:1.21 pgoyette-compat:1.23.0.8 pgoyette-compat-base:1.23 netbsd-7-1-1-RELEASE:1.21 tls-maxphys-base-20171202:1.23 matt-nb8-mediatek:1.23.0.6 matt-nb8-mediatek-base:1.23 nick-nhusb-base-20170825:1.23 perseant-stdc-iso10646:1.23.0.4 perseant-stdc-iso10646-base:1.23 netbsd-8:1.23.0.2 netbsd-8-base:1.23 prg-localcount2-base3:1.23 prg-localcount2-base2:1.22 prg-localcount2-base1:1.22 prg-localcount2:1.22.0.8 prg-localcount2-base:1.22 pgoyette-localcount-20170426:1.22 bouyer-socketcan-base1:1.22 jdolecek-ncq:1.22.0.6 jdolecek-ncq-base:1.22 pgoyette-localcount-20170320:1.22 netbsd-7-1:1.21.0.36 netbsd-7-1-RELEASE:1.21 netbsd-7-1-RC2:1.21 nick-nhusb-base-20170204:1.22 netbsd-7-nhusb-base-20170116:1.21 bouyer-socketcan:1.22.0.4 bouyer-socketcan-base:1.22 pgoyette-localcount-20170107:1.22 netbsd-7-1-RC1:1.21 nick-nhusb-base-20161204:1.22 pgoyette-localcount-20161104:1.22 netbsd-7-0-2-RELEASE:1.21 nick-nhusb-base-20161004:1.22 localcount-20160914:1.22 netbsd-7-nhusb:1.21.0.34 netbsd-7-nhusb-base:1.21 pgoyette-localcount-20160806:1.22 pgoyette-localcount-20160726:1.22 pgoyette-localcount:1.22.0.2 pgoyette-localcount-base:1.22 nick-nhusb-base-20160907:1.22 nick-nhusb-base-20160529:1.22 netbsd-7-0-1-RELEASE:1.21 nick-nhusb-base-20160422:1.22 nick-nhusb-base-20160319:1.22 nick-nhusb-base-20151226:1.22 netbsd-7-0:1.21.0.32 netbsd-7-0-RELEASE:1.21 nick-nhusb-base-20150921:1.22 netbsd-7-0-RC3:1.21 netbsd-7-0-RC2:1.21 netbsd-7-0-RC1:1.21 nick-nhusb-base-20150606:1.22 nick-nhusb-base-20150406:1.22 nick-nhusb:1.21.0.30 nick-nhusb-base:1.21 netbsd-5-2-3-RELEASE:1.11.10.1 netbsd-5-1-5-RELEASE:1.11.10.1 netbsd-6-0-6-RELEASE:1.21 netbsd-6-1-5-RELEASE:1.21 netbsd-7:1.21.0.28 netbsd-7-base:1.21 yamt-pagecache-base9:1.21 yamt-pagecache-tag8:1.21 netbsd-6-1-4-RELEASE:1.21 netbsd-6-0-5-RELEASE:1.21 tls-earlyentropy:1.21.0.26 tls-earlyentropy-base:1.21 riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.21 riastradh-drm2-base3:1.21 netbsd-6-1-3-RELEASE:1.21 netbsd-6-0-4-RELEASE:1.21 netbsd-5-2-2-RELEASE:1.11.10.1 netbsd-5-1-4-RELEASE:1.11.10.1 netbsd-6-1-2-RELEASE:1.21 netbsd-6-0-3-RELEASE:1.21 netbsd-5-2-1-RELEASE:1.11.10.1 netbsd-5-1-3-RELEASE:1.11.10.1 rmind-smpnet-nbase:1.21 netbsd-6-1-1-RELEASE:1.21 riastradh-drm2-base2:1.21 riastradh-drm2-base1:1.21 riastradh-drm2:1.21.0.24 riastradh-drm2-base:1.21 rmind-smpnet:1.21.0.16 rmind-smpnet-base:1.21 netbsd-6-1:1.21.0.22 netbsd-6-0-2-RELEASE:1.21 netbsd-6-1-RELEASE:1.21 khorben-n900:1.21.0.20 netbsd-6-1-RC4:1.21 netbsd-6-1-RC3:1.21 agc-symver:1.21.0.18 agc-symver-base:1.21 netbsd-6-1-RC2:1.21 netbsd-6-1-RC1:1.21 yamt-pagecache-base8:1.21 netbsd-5-2:1.11.10.1.0.6 netbsd-6-0-1-RELEASE:1.21 yamt-pagecache-base7:1.21 netbsd-5-2-RELEASE:1.11.10.1 netbsd-5-2-RC1:1.11.10.1 matt-nb6-plus-nbase:1.21 yamt-pagecache-base6:1.21 netbsd-6-0:1.21.0.14 netbsd-6-0-RELEASE:1.21 netbsd-6-0-RC2:1.21 tls-maxphys:1.21.0.12 tls-maxphys-base:1.21 matt-nb6-plus:1.21.0.10 matt-nb6-plus-base:1.21 netbsd-6-0-RC1:1.21 jmcneill-usbmp-base10:1.21 yamt-pagecache-base5:1.21 jmcneill-usbmp-base9:1.21 yamt-pagecache-base4:1.21 jmcneill-usbmp-base8:1.21 jmcneill-usbmp-base7:1.21 jmcneill-usbmp-base6:1.21 jmcneill-usbmp-base5:1.21 jmcneill-usbmp-base4:1.21 jmcneill-usbmp-base3:1.21 jmcneill-usbmp-pre-base2:1.21 jmcneill-usbmp-base2:1.21 netbsd-6:1.21.0.8 netbsd-6-base:1.21 netbsd-5-1-2-RELEASE:1.11.10.1 netbsd-5-1-1-RELEASE:1.11.10.1 jmcneill-usbmp:1.21.0.6 jmcneill-usbmp-base:1.21 jmcneill-audiomp3:1.21.0.4 jmcneill-audiomp3-base:1.21 yamt-pagecache-base3:1.21 yamt-pagecache-base2:1.21 yamt-pagecache:1.21.0.2 yamt-pagecache-base:1.21 rmind-uvmplock-nbase:1.20 cherry-xenmp:1.20.0.2 cherry-xenmp-base:1.20 bouyer-quota2-nbase:1.19 bouyer-quota2:1.13.0.8 bouyer-quota2-base:1.15 jruoho-x86intr:1.13.0.6 jruoho-x86intr-base:1.13 matt-mips64-premerge-20101231:1.13 matt-nb5-mips64-premerge-20101231:1.11 matt-nb5-pq3:1.11.10.1.0.4 matt-nb5-pq3-base:1.11.10.1 netbsd-5-1:1.11.10.1.0.2 netbsd-5-1-RELEASE:1.11.10.1 uebayasi-xip-base4:1.13 uebayasi-xip-base3:1.13 yamt-nfs-mp-base11:1.13 netbsd-5-1-RC4:1.11.10.1 matt-nb5-mips64-k15:1.11 uebayasi-xip-base2:1.13 yamt-nfs-mp-base10:1.13 netbsd-5-1-RC3:1.11.10.1 netbsd-5-1-RC2:1.11.10.1 uebayasi-xip-base1:1.13 netbsd-5-1-RC1:1.11.10.1 rmind-uvmplock:1.13.0.4 rmind-uvmplock-base:1.20 yamt-nfs-mp-base9:1.13 uebayasi-xip:1.13.0.2 uebayasi-xip-base:1.13 netbsd-5-0-2-RELEASE:1.11 matt-nb5-mips64-premerge-20091211:1.11 matt-premerge-20091211:1.13 yamt-nfs-mp-base8:1.13 matt-nb5-mips64-u2-k2-k4-k7-k8-k9:1.11 matt-nb4-mips64-k7-u2a-k9b:1.11 matt-nb5-mips64-u1-k1-k5:1.11 yamt-nfs-mp-base7:1.13 matt-nb5-mips64:1.11.0.18 netbsd-5-0-1-RELEASE:1.11 jymxensuspend-base:1.13 yamt-nfs-mp-base6:1.13 yamt-nfs-mp-base5:1.13 yamt-nfs-mp-base4:1.13 jym-xensuspend-nbase:1.13 yamt-nfs-mp-base3:1.13 nick-hppapmap-base4:1.13 nick-hppapmap-base3:1.13 netbsd-5-0:1.11.0.16 netbsd-5-0-RELEASE:1.11 netbsd-5-0-RC4:1.11 netbsd-5-0-RC3:1.11 nick-hppapmap-base2:1.11 netbsd-5-0-RC2:1.11 jym-xensuspend:1.11.0.14 jym-xensuspend-base:1.13 netbsd-5-0-RC1:1.11 haad-dm-base2:1.11 haad-nbase2:1.11 ad-audiomp2:1.11.0.12 ad-audiomp2-base:1.11 netbsd-5:1.11.0.10 netbsd-5-base:1.11 nick-hppapmap:1.11.0.8 nick-hppapmap-base:1.13 matt-mips64-base2:1.11 matt-mips64:1.8.0.10 haad-dm-base1:1.11 wrstuden-revivesa-base-4:1.11 netbsd-4-0-1-RELEASE:1.7.2.2 wrstuden-revivesa-base-3:1.11 wrstuden-revivesa-base-2:1.11 wrstuden-fixsa-newbase:1.7.2.2 nick-csl-alignment-base5:1.8 haad-dm:1.11.0.6 haad-dm-base:1.11 wrstuden-revivesa-base-1:1.11 simonb-wapbl-nbase:1.11 yamt-pf42-base4:1.11 simonb-wapbl:1.11.0.4 simonb-wapbl-base:1.11 yamt-pf42-base3:1.11 hpcarm-cleanup-nbase:1.11 yamt-pf42-baseX:1.9 yamt-pf42-base2:1.11 yamt-nfs-mp-base2:1.11 wrstuden-revivesa:1.11.0.2 wrstuden-revivesa-base:1.11 yamt-nfs-mp:1.9.0.24 yamt-nfs-mp-base:1.9 yamt-pf42:1.9.0.22 yamt-pf42-base:1.9 ad-socklock-base1:1.9 yamt-lazymbuf-base15:1.9 yamt-lazymbuf-base14:1.9 keiichi-mipv6-nbase:1.9 mjf-devfs2:1.9.0.20 mjf-devfs2-base:1.11 nick-net80211-sync:1.9.0.18 nick-net80211-sync-base:1.9 keiichi-mipv6:1.9.0.16 keiichi-mipv6-base:1.9 bouyer-xeni386-merge1:1.9 matt-armv6-prevmlocking:1.8.8.1 wrstuden-fixsa-base-1:1.7.2.2 vmlocking2-base3:1.9 netbsd-4-0:1.7.2.2.0.4 netbsd-4-0-RELEASE:1.7.2.2 bouyer-xeni386-nbase:1.9 yamt-kmem-base3:1.9 cube-autoconf:1.9.0.14 cube-autoconf-base:1.9 yamt-kmem-base2:1.9 bouyer-xeni386:1.9.0.12 bouyer-xeni386-base:1.9 yamt-kmem:1.9.0.10 yamt-kmem-base:1.9 vmlocking2-base2:1.9 reinoud-bufcleanup-nbase:1.9 vmlocking2:1.9.0.8 vmlocking2-base1:1.9 netbsd-4-0-RC5:1.7.2.2 matt-nb4-arm:1.7.2.2.0.2 matt-nb4-arm-base:1.7.2.2 matt-armv6-nbase:1.9 jmcneill-base:1.9 netbsd-4-0-RC4:1.7.2.2 mjf-devfs:1.9.0.6 mjf-devfs-base:1.9 bouyer-xenamd64-base2:1.9 vmlocking-nbase:1.9 yamt-x86pmap-base4:1.9 bouyer-xenamd64:1.9.0.4 bouyer-xenamd64-base:1.9 netbsd-4-0-RC3:1.7.2.2 yamt-x86pmap-base3:1.9 yamt-x86pmap-base2:1.9 netbsd-4-0-RC2:1.7.2.2 yamt-x86pmap:1.9.0.2 yamt-x86pmap-base:1.9 netbsd-4-0-RC1:1.7.2.1 matt-armv6:1.8.0.8 matt-armv6-base:1.9 matt-mips64-base:1.8 jmcneill-pm:1.8.0.6 jmcneill-pm-base:1.9 hpcarm-cleanup:1.8.0.4 hpcarm-cleanup-base:1.9 nick-csl-alignment:1.8.0.2 nick-csl-alignment-base:1.8 netbsd-3-1-1-RELEASE:1.3 netbsd-3-0-3-RELEASE:1.3 yamt-idlelwp-base8:1.7 wrstuden-fixsa:1.7.0.16 wrstuden-fixsa-base:1.7.2.2 thorpej-atomic:1.7.0.14 thorpej-atomic-base:1.7 reinoud-bufcleanup:1.7.0.12 reinoud-bufcleanup-base:1.9 mjf-ufs-trans:1.7.0.10 mjf-ufs-trans-base:1.8 vmlocking:1.7.0.8 vmlocking-base:1.9 ad-audiomp:1.7.0.6 ad-audiomp-base:1.7 yamt-idlelwp:1.7.0.4 post-newlock2-merge:1.7 newlock2-nbase:1.7 yamt-splraiseipl-base5:1.7 yamt-splraiseipl-base4:1.7 yamt-splraiseipl-base3:1.7 abandoned-netbsd-4-base:1.5 abandoned-netbsd-4:1.5.0.6 netbsd-3-1:1.3.0.14 netbsd-3-1-RELEASE:1.3 netbsd-3-0-2-RELEASE:1.3 yamt-splraiseipl-base2:1.6 netbsd-3-1-RC4:1.3 yamt-splraiseipl:1.5.0.10 yamt-splraiseipl-base:1.5 netbsd-3-1-RC3:1.3 yamt-pdpolicy-base9:1.5 newlock2:1.5.0.8 newlock2-base:1.7 yamt-pdpolicy-base8:1.5 netbsd-3-1-RC2:1.3 netbsd-3-1-RC1:1.3 yamt-pdpolicy-base7:1.5 netbsd-4:1.7.0.2 netbsd-4-base:1.7 yamt-pdpolicy-base6:1.5 chap-midi-nbase:1.5 netbsd-3-0-1-RELEASE:1.3 gdamore-uart:1.5.0.4 gdamore-uart-base:1.5 simonb-timcounters-final:1.4.6.1 yamt-pdpolicy-base5:1.5 chap-midi:1.5.0.2 chap-midi-base:1.5 yamt-pdpolicy-base4:1.5 yamt-pdpolicy-base3:1.5 peter-altq-base:1.4 peter-altq:1.4.0.12 yamt-pdpolicy-base2:1.4 elad-kernelauth-base:1.5 elad-kernelauth:1.4.0.10 yamt-pdpolicy:1.4.0.8 yamt-pdpolicy-base:1.4 yamt-uio_vmspace-base5:1.4 simonb-timecounters:1.4.0.6 simonb-timecounters-base:1.5 rpaulo-netinet-merge-pcb:1.4.0.4 rpaulo-netinet-merge-pcb-base:1.5 yamt-uio_vmspace:1.4.0.2 netbsd-3-0:1.3.0.12 netbsd-3-0-RELEASE:1.3 netbsd-3-0-RC6:1.3 yamt-readahead-base3:1.3 netbsd-3-0-RC5:1.3 netbsd-3-0-RC4:1.3 netbsd-3-0-RC3:1.3 yamt-readahead-base2:1.3 netbsd-3-0-RC2:1.3 yamt-readahead-pervnode:1.3 yamt-readahead-perfile:1.3 yamt-readahead:1.3.0.10 yamt-readahead-base:1.3 netbsd-3-0-RC1:1.3 yamt-vop-base3:1.3 netbsd-2-0-3-RELEASE:1.2 netbsd-2-1:1.2.0.16 yamt-vop-base2:1.3 thorpej-vnode-attr:1.3.0.8 thorpej-vnode-attr-base:1.3 netbsd-2-1-RELEASE:1.2 yamt-vop:1.3.0.6 yamt-vop-base:1.3 netbsd-2-1-RC6:1.2 netbsd-2-1-RC5:1.2 netbsd-2-1-RC4:1.2 netbsd-2-1-RC3:1.2 netbsd-2-1-RC2:1.2 netbsd-2-1-RC1:1.2 yamt-lazymbuf:1.3.0.4 yamt-km-base4:1.3 netbsd-2-0-2-RELEASE:1.2 yamt-km-base3:1.3 netbsd-3:1.3.0.2 netbsd-3-base:1.3 yamt-km-base2:1.2 yamt-km:1.2.0.12 yamt-km-base:1.2 kent-audio2:1.2.0.10 kent-audio2-base:1.3 netbsd-2-0-1-RELEASE:1.2 kent-audio1-beforemerge:1.2 netbsd-2:1.2.0.8 netbsd-2-base:1.2 kent-audio1:1.2.0.6 kent-audio1-base:1.2 netbsd-2-0-RELEASE:1.2 netbsd-2-0-RC5:1.2 netbsd-2-0-RC4:1.2 netbsd-2-0-RC3:1.2 netbsd-2-0-RC2:1.2 netbsd-2-0-RC1:1.2 ktrace-lwp-base:1.3 ktrace-lwp:1.2.0.4 netbsd-2-0:1.2.0.2 netbsd-2-0-base:1.2; locks; strict; comment @ * @; 1.23 date 2017.05.17.06.33.04; author knakahara; state Exp; branches; next 1.22; commitid 0HVrot8rlDmyZHRz; 1.22 date 2015.03.26.17.40.16; author prlw1; state Exp; branches 1.22.8.1; next 1.21; commitid zoAlw7Lry1ISQ8fy; 1.21 date 2011.07.03.01.01.06; author mrg; state Exp; branches 1.21.12.1 1.21.30.1; next 1.20; 1.20 date 2011.03.09.11.36.43; author drochner; state Exp; branches; next 1.19; 1.19 date 2011.02.24.20.03.41; author drochner; state Exp; branches; next 1.18; 1.18 date 2011.02.18.22.02.09; author drochner; state Exp; branches; next 1.17; 1.17 date 2011.02.18.10.50.56; author drochner; state Exp; branches; next 1.16; 1.16 date 2011.02.17.17.10.18; author drochner; state Exp; branches; next 1.15; 1.15 date 2011.02.16.19.08.57; author drochner; state Exp; branches; next 1.14; 1.14 date 2011.02.10.21.17.49; author drochner; state Exp; branches; next 1.13; 1.13 date 2009.03.25.01.26.13; author darran; state Exp; branches 1.13.4.1 1.13.6.1 1.13.8.1; next 1.12; 1.12 date 2009.03.14.15.36.24; author dsl; state Exp; branches; next 1.11; 1.11 date 2008.05.05.13.41.30; author ad; state Exp; branches 1.11.8.1 1.11.10.1 1.11.14.1 1.11.18.1; next 1.10; 1.10 date 2008.05.04.23.07.09; author ad; state Exp; branches; next 1.9; 1.9 date 2007.09.22.23.38.17; author degroote; state Exp; branches 1.9.24.1; next 1.8; 1.8 date 2007.05.21.11.35.16; author degroote; state Exp; branches 1.8.6.1 1.8.8.1; next 1.7; 1.7 date 2006.11.16.01.33.51; author christos; state Exp; branches 1.7.2.1 1.7.8.1 1.7.10.1 1.7.16.1; next 1.6; 1.6 date 2006.10.12.01.32.47; author christos; state Exp; branches; next 1.5; 1.5 date 2006.03.17.23.29.11; author christos; state Exp; branches 1.5.8.1 1.5.10.1; next 1.4; 1.4 date 2005.12.11.12.25.20; author christos; state Exp; branches 1.4.4.1 1.4.6.1 1.4.8.1 1.4.10.1 1.4.12.1; next 1.3; 1.3 date 2005.02.26.22.39.52; author perry; state Exp; branches 1.3.4.1; next 1.2; 1.2 date 2003.08.27.00.12.37; author thorpej; state Exp; branches 1.2.4.1 1.2.10.1 1.2.12.1; next 1.1; 1.1 date 2003.07.25.21.12.45; author jonathan; state Exp; branches; next ; 1.22.8.1 date 2017.05.19.00.22.58; author pgoyette; state Exp; branches; next ; commitid QNTxgGjVagwoSVRz; 1.21.12.1 date 2017.12.03.11.39.06; author jdolecek; state Exp; branches; next ; commitid XcIYRZTAh1LmerhA; 1.21.30.1 date 2015.04.06.15.18.24; author skrll; state Exp; branches; next 1.21.30.2; commitid pz01Zhy7RP6iGxgy; 1.21.30.2 date 2017.08.28.17.53.13; author skrll; state Exp; branches; next ; commitid UQQpnjvcNkUZn05A; 1.13.4.1 date 2011.03.05.20.56.05; author rmind; state Exp; branches; next 1.13.4.2; 1.13.4.2 date 2011.04.21.01.42.16; author rmind; state Exp; branches; next ; 1.13.6.1 date 2011.06.06.09.10.04; author jruoho; state Exp; branches; next ; 1.13.8.1 date 2011.02.17.12.00.50; author bouyer; state Exp; branches; next 1.13.8.2; 1.13.8.2 date 2011.03.05.15.10.48; author bouyer; state Exp; branches; next ; 1.11.8.1 date 2009.04.28.07.37.50; author skrll; state Exp; branches; next ; 1.11.10.1 date 2009.05.03.17.24.45; author snj; state Exp; branches; next ; 1.11.14.1 date 2009.05.13.17.22.56; author jym; state Exp; branches; next ; 1.11.18.1 date 2011.05.20.08.11.32; author matt; state Exp; branches; next ; 1.9.24.1 date 2009.05.04.08.14.24; author yamt; state Exp; branches; next ; 1.8.6.1 date 2007.10.02.18.29.25; author joerg; state Exp; branches; next ; 1.8.8.1 date 2007.11.06.23.34.26; author matt; state Exp; branches; next ; 1.7.2.1 date 2007.05.24.19.13.17; author pavel; state Exp; branches; next 1.7.2.2; 1.7.2.2 date 2007.09.25.00.49.39; author xtraeme; state Exp; branches; next ; 1.7.8.1 date 2007.06.08.14.18.08; author ad; state Exp; branches; next 1.7.8.2; 1.7.8.2 date 2007.10.09.13.45.00; author ad; state Exp; branches; next ; 1.7.10.1 date 2007.07.11.20.12.18; author mjf; state Exp; branches; next ; 1.7.16.1 date 2007.06.04.01.54.28; author wrstuden; state Exp; branches; next 1.7.16.2; 1.7.16.2 date 2007.09.30.03.39.17; author wrstuden; state Exp; branches; next ; 1.5.8.1 date 2006.11.18.21.39.44; author ad; state Exp; branches; next ; 1.5.10.1 date 2006.10.22.06.07.47; author yamt; state Exp; branches; next 1.5.10.2; 1.5.10.2 date 2006.12.10.07.19.28; author yamt; state Exp; branches; next ; 1.4.4.1 date 2006.09.09.02.59.41; author rpaulo; state Exp; branches; next ; 1.4.6.1 date 2006.04.22.11.40.18; author simonb; state Exp; branches; next ; 1.4.8.1 date 2006.04.01.12.07.51; author yamt; state Exp; branches; next ; 1.4.10.1 date 2006.04.19.04.33.31; author elad; state Exp; branches; next ; 1.4.12.1 date 2006.03.28.09.42.28; author tron; state Exp; branches; next ; 1.3.4.1 date 2006.06.21.15.12.02; author yamt; state Exp; branches; next 1.3.4.2; 1.3.4.2 date 2007.09.03.14.44.24; author yamt; state Exp; branches; next 1.3.4.3; 1.3.4.3 date 2007.10.27.11.36.18; author yamt; state Exp; branches; next ; 1.2.4.1 date 2003.08.27.00.12.37; author skrll; state dead; branches; next 1.2.4.2; 1.2.4.2 date 2004.08.03.10.56.25; author skrll; state Exp; branches; next 1.2.4.3; 1.2.4.3 date 2004.09.18.14.56.20; author skrll; state Exp; branches; next 1.2.4.4; 1.2.4.4 date 2004.09.21.13.38.44; author skrll; state Exp; branches; next 1.2.4.5; 1.2.4.5 date 2005.03.04.16.54.22; author skrll; state Exp; branches; next ; 1.2.10.1 date 2005.04.29.11.29.37; author kent; state Exp; branches; next ; 1.2.12.1 date 2005.03.19.08.36.52; author yamt; state Exp; branches; next ; desc @@ 1.23 log @opencrypto: cleanup debug messages. @ text @/* $NetBSD: deflate.c,v 1.22 2015/03/26 17:40:16 prlw1 Exp $ */ /* $FreeBSD: src/sys/opencrypto/deflate.c,v 1.1.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: deflate.c,v 1.3 2001/08/20 02:45:22 hugh Exp $ */ /* * Copyright (c) 2001 Jean-Jacques Bernard-Gundol (jj@@wabbitt.org) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * This file contains a wrapper around the deflate algo compression * functions using the zlib library (see net/zlib.{c,h}) */ #include __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.22 2015/03/26 17:40:16 prlw1 Exp $"); #include #include #include #include #include #include #include #define ZBUF 10 struct deflate_buf { u_int8_t *out; u_int32_t size; }; int window_inflate = -1 * MAX_WBITS; int window_deflate = -12; /* * This function takes a block of data and (de)compress it using the deflate * algorithm */ static void * ocf_zalloc(void *nil, u_int type, u_int size) { void *ptr; ptr = malloc(type *size, M_CRYPTO_DATA, M_NOWAIT); return ptr; } static void ocf_zfree(void *nil, void *ptr) { free(ptr, M_CRYPTO_DATA); } u_int32_t deflate_global(u_int8_t *data, u_int32_t size, int decomp, u_int8_t **out, int size_hint) { /* decomp indicates whether we compress (0) or decompress (1) */ z_stream zbuf; u_int8_t *output; u_int32_t count, result, tocopy; int error, i, j; struct deflate_buf buf[ZBUF]; DPRINTF("size %u\n", size); memset(&zbuf, 0, sizeof(z_stream)); zbuf.next_in = data; /* data that is going to be processed */ zbuf.zalloc = ocf_zalloc; zbuf.zfree = ocf_zfree; zbuf.opaque = Z_NULL; zbuf.avail_in = size; /* Total length of data to be processed */ if (!decomp) { buf[0].size = size; } else { /* * Choose a buffer with 4x the size of the input buffer * for the size of the output buffer in the case of * decompression. If it's not sufficient, it will need to be * updated while the decompression is going on */ buf[0].size = MAX(size * 4, size_hint); } buf[0].out = malloc(buf[0].size, M_CRYPTO_DATA, M_NOWAIT); if (buf[0].out == NULL) return 0; i = 1; zbuf.next_out = buf[0].out; zbuf.avail_out = buf[0].size; error = decomp ? inflateInit2(&zbuf, window_inflate) : deflateInit2(&zbuf, Z_DEFAULT_COMPRESSION, Z_METHOD, window_deflate, Z_MEMLEVEL, Z_DEFAULT_STRATEGY); if (error != Z_OK) goto bad2; for (;;) { error = decomp ? inflate(&zbuf, Z_SYNC_FLUSH) : deflate(&zbuf, Z_FINISH); if (error == Z_STREAM_END) /* success */ break; /* * XXX compensate for two problems: * -Former versions of this code didn't set Z_FINISH * on compression, so the compressed data are not correctly * terminated and the decompressor doesn't get Z_STREAM_END. * Accept such packets for interoperability. * -sys/net/zlib.c has a bug which makes that Z_BUF_ERROR is * set after successful decompression under rare conditions. */ else if (decomp && (error == Z_OK || error == Z_BUF_ERROR) && zbuf.avail_in == 0 && zbuf.avail_out != 0) break; else if (error != Z_OK) goto bad; else if (zbuf.avail_out == 0) { /* we need more output space, allocate size */ int nextsize = buf[i-1].size * 2; if (i == ZBUF || nextsize > 1000000) goto bad; buf[i].out = malloc(nextsize, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad; zbuf.next_out = buf[i].out; zbuf.avail_out = buf[i].size = nextsize; i++; } } result = count = zbuf.total_out; if (i != 1) { /* copy everything into one buffer */ output = malloc(result, M_CRYPTO_DATA, M_NOWAIT); if (output == NULL) goto bad; *out = output; for (j = 0; j < i; j++) { tocopy = MIN(count, buf[j].size); /* XXX the last buf can be empty */ KASSERT(tocopy || j == (i - 1)); memcpy(output, buf[j].out, tocopy); output += tocopy; free(buf[j].out, M_CRYPTO_DATA); count -= tocopy; } KASSERT(count == 0); } else { *out = buf[0].out; } if (decomp) inflateEnd(&zbuf); else deflateEnd(&zbuf); return result; bad: if (decomp) inflateEnd(&zbuf); else deflateEnd(&zbuf); bad2: for (j = 0; j < i; j++) free(buf[j].out, M_CRYPTO_DATA); return 0; } /* * Initial version will perform a single gzip encapsulation, * filling in the header, * and appending the crc and uncompressed length. * * Later version will support multiple buffers with * a flag indication final buffer. The crc is maintained * over all buffers and appended to the output along with * the uncompressed length after the final data buffer * has been compressed and output. * * Ditto for uncompress - CRC is extracted from the final packed * and compared against CRC of uncompressed data. * */ /* constant header for the gzip */ static const char gzip_header[10] = { 0x1f, 0x8b, /* ID1 ID2 */ Z_DEFLATED, /* CM */ 0, /* FLG */ 0, 0, 0, 0, /* MTIME */ 0, /* XFL */ 0x03 /* OS (Unix) */ }; /* Followed by compressed payload */ /* Followed by uint32_t CRC32 and uint32_t ISIZE */ #define GZIP_TAIL_SIZE 8 u_int32_t gzip_global(u_int8_t *data, u_int32_t size, int decomp, u_int8_t **out, int size_hint) { /* decomp indicates whether we compress (0) or decompress (1) */ z_stream zbuf; u_int8_t *output; u_int32_t count, result; int error, i, j; struct deflate_buf buf[ZBUF]; u_int32_t crc; u_int32_t isize = 0, icrc = 0; DPRINTF("decomp %d, size %u\n", decomp, size); memset(&zbuf, 0, sizeof(z_stream)); zbuf.zalloc = ocf_zalloc; zbuf.zfree = ocf_zfree; zbuf.opaque = Z_NULL; if (!decomp) { /* compress */ DPRINTF("compress malloc %u + %zu + %u = %zu\n", size, sizeof(gzip_header), GZIP_TAIL_SIZE, size + sizeof(gzip_header) + GZIP_TAIL_SIZE); buf[0].size = size; crc = crc32(0, data, size); DPRINTF("size %u, crc 0x%x\n", size, crc); zbuf.avail_in = size; /* Total length of data to be processed */ zbuf.next_in = data; /* data that is going to be processed */ } else { /* decompress */ /* check the gzip header */ if (size <= sizeof(gzip_header) + GZIP_TAIL_SIZE) { /* Not enough data for the header & tail */ DPRINTF("not enough data (%u)\n", size); return 0; } /* XXX this is pretty basic, * needs to be expanded to ignore MTIME, OS, * but still ensure flags are 0. * Q. Do we need to support the flags and * optional header fields? Likely. * XXX add flag and field support too. */ if (memcmp(data, gzip_header, sizeof(gzip_header)) != 0) { DPRINTF("unsupported gzip header (%02x%02x)\n", data[0], data[1]); return 0; } else { DPRINTF("%d: gzip header ok\n",__LINE__); } memcpy(&isize, &data[size-sizeof(uint32_t)], sizeof(uint32_t)); LE32TOH(isize); memcpy(&icrc, &data[size-2*sizeof(uint32_t)], sizeof(uint32_t)); LE32TOH(icrc); DPRINTF("isize = %u (%02x %02x %02x %02x)\n", isize, data[size-4], data[size-3], data[size-2], data[size-1]); buf[0].size = isize; crc = crc32(0, NULL, 0); /* get initial crc value */ /* skip over the gzip header */ zbuf.next_in = data + sizeof(gzip_header); /* actual payload size stripped of gzip header and tail */ zbuf.avail_in = size - sizeof(gzip_header) - GZIP_TAIL_SIZE; } buf[0].out = malloc(buf[0].size, M_CRYPTO_DATA, M_NOWAIT); if (buf[0].out == NULL) return 0; zbuf.next_out = buf[0].out; zbuf.avail_out = buf[0].size; DPRINTF("zbuf avail_in %u, avail_out %u\n", zbuf.avail_in, zbuf.avail_out); i = 1; error = decomp ? inflateInit2(&zbuf, window_inflate) : deflateInit2(&zbuf, Z_DEFAULT_COMPRESSION, Z_METHOD, window_deflate, Z_MEMLEVEL, Z_DEFAULT_STRATEGY); if (error != Z_OK) { printf("deflateInit2() failed\n"); goto bad2; } for (;;) { DPRINTF("pre: %s in:%u out:%u\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out); error = decomp ? inflate(&zbuf, Z_SYNC_FLUSH) : deflate(&zbuf, Z_FINISH); DPRINTF("post: %s in:%u out:%u\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out); if (error == Z_STREAM_END) /* success */ break; /* * XXX compensate for a zlib problem: * -sys/net/zlib.c has a bug which makes that Z_BUF_ERROR is * set after successful decompression under rare conditions. */ else if (decomp && error == Z_BUF_ERROR && zbuf.avail_in == 0 && zbuf.avail_out != 0) break; else if (error != Z_OK) goto bad; else if (zbuf.avail_out == 0) { /* we need more output space, allocate size */ int nextsize = buf[i-1].size * 2; if (i == ZBUF || nextsize > 1000000) goto bad; buf[i].out = malloc(nextsize, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad; zbuf.next_out = buf[i].out; zbuf.avail_out = buf[i].size = nextsize; i++; } } if (decomp) { count = result = zbuf.total_out; } else { /* need room for header, CRC, and ISIZE */ result = zbuf.total_out + sizeof(gzip_header) + GZIP_TAIL_SIZE; count = zbuf.total_out; } DPRINTF("in %u -> out %u\n", size, result); *out = malloc(result, M_CRYPTO_DATA, M_NOWAIT); if (*out == NULL) goto bad; output = *out; if (decomp) inflateEnd(&zbuf); else { deflateEnd(&zbuf); /* fill in gzip header */ memcpy(output, gzip_header, sizeof(gzip_header)); output += sizeof(gzip_header); } for (j = 0; j < i; j++) { if (decomp) { /* update crc for decompressed data */ crc = crc32(crc, buf[j].out, MIN(count, buf[j].size)); } if (count > buf[j].size) { memcpy(output, buf[j].out, buf[j].size); output += buf[j].size; free(buf[j].out, M_CRYPTO_DATA); count -= buf[j].size; } else { /* it should be the last buffer */ memcpy(output, buf[j].out, count); output += count; free(buf[j].out, M_CRYPTO_DATA); count = 0; } } if (!decomp) { /* fill in CRC and ISIZE */ HTOLE32(crc); memcpy(output, &crc, sizeof(uint32_t)); HTOLE32(size); memcpy(output + sizeof(uint32_t), &size, sizeof(uint32_t)); DPRINTF("size = 0x%x (%02x %02x %02x %02x)\n", size, output[7], output[3], output[5], output[4]); } else { if (crc != icrc || result != isize) { DPRINTF("crc/size mismatch\n"); free(*out, M_CRYPTO_DATA); *out = NULL; return 0; } } return result; bad: if (decomp) inflateEnd(&zbuf); else deflateEnd(&zbuf); bad2: *out = NULL; for (j = 0; j < i; j++) free(buf[j].out, M_CRYPTO_DATA); return 0; } @ 1.22 log @Trivial printf format changes and typo fix @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.21 2011/07/03 01:01:06 mrg Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.21 2011/07/03 01:01:06 mrg Exp $"); d91 1 a91 1 DPRINTF(("deflate_global: size %u\n", size)); d239 1 a239 1 DPRINTF(("gzip_global: decomp %d, size %u\n", decomp, size)); d248 1 a248 1 DPRINTF(("gzip_global: compress malloc %u + %zu + %u = %zu\n", d250 1 a250 1 size + sizeof(gzip_header) + GZIP_TAIL_SIZE)); d254 1 a254 1 DPRINTF(("gzip_compress: size %u, crc 0x%x\n", size, crc)); d262 1 a262 2 DPRINTF(("gzip_global: not enough data (%u)\n", size)); d274 2 a275 2 DPRINTF(("gzip_global: unsupported gzip header (%02x%02x)\n", data[0], data[1])); d278 1 a278 1 DPRINTF(("gzip_global.%d: gzip header ok\n",__LINE__)); d286 1 a286 1 DPRINTF(("gzip_global: isize = %u (%02x %02x %02x %02x)\n", d291 1 a291 1 data[size-1])); d308 2 a309 2 DPRINTF(("zbuf avail_in %u, avail_out %u\n", zbuf.avail_in, zbuf.avail_out)); d321 2 a322 2 DPRINTF(("pre: %s in:%u out:%u\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out)); d325 2 a326 2 DPRINTF(("post: %s in:%u out:%u\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out)); d361 1 a361 1 DPRINTF(("gzip_global: in %u -> out %u\n", size, result)); d402 1 a402 1 DPRINTF(("gzip_global: size = 0x%x (%02x %02x %02x %02x)\n", d407 1 a407 1 output[4])); d410 1 a410 1 DPRINTF(("gzip_global: crc/size mismatch\n")); @ 1.22.8.1 log @Resolve conflicts from previous merge (all resulting from $NetBSD keywork expansion) @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.23 2017/05/17 06:33:04 knakahara Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.23 2017/05/17 06:33:04 knakahara Exp $"); d91 1 a91 1 DPRINTF("size %u\n", size); d239 1 a239 1 DPRINTF("decomp %d, size %u\n", decomp, size); d248 1 a248 1 DPRINTF("compress malloc %u + %zu + %u = %zu\n", d250 1 a250 1 size + sizeof(gzip_header) + GZIP_TAIL_SIZE); d254 1 a254 1 DPRINTF("size %u, crc 0x%x\n", size, crc); d262 2 a263 1 DPRINTF("not enough data (%u)\n", size); d275 2 a276 2 DPRINTF("unsupported gzip header (%02x%02x)\n", data[0], data[1]); d279 1 a279 1 DPRINTF("%d: gzip header ok\n",__LINE__); d287 1 a287 1 DPRINTF("isize = %u (%02x %02x %02x %02x)\n", d292 1 a292 1 data[size-1]); d309 2 a310 2 DPRINTF("zbuf avail_in %u, avail_out %u\n", zbuf.avail_in, zbuf.avail_out); d322 2 a323 2 DPRINTF("pre: %s in:%u out:%u\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out); d326 2 a327 2 DPRINTF("post: %s in:%u out:%u\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out); d362 1 a362 1 DPRINTF("in %u -> out %u\n", size, result); d403 1 a403 1 DPRINTF("size = 0x%x (%02x %02x %02x %02x)\n", d408 1 a408 1 output[4]); d411 1 a411 1 DPRINTF("crc/size mismatch\n"); @ 1.21 log @avoid some uninitialised warning issues GCC 4.5 complains about. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.20 2011/03/09 11:36:43 drochner Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.20 2011/03/09 11:36:43 drochner Exp $"); d91 1 a91 1 DPRINTF(("deflate_global: size %d\n", size)); d239 1 a239 1 DPRINTF(("gzip_global: decomp %d, size %d\n", decomp, size)); d248 1 a248 1 DPRINTF(("gzip_global: compress malloc %d + %d + %d = %d\n", d254 1 a254 1 DPRINTF(("gzip_compress: size %d, crc 0x%x\n", size, crc)); d262 1 a262 1 DPRINTF(("gzip_global: not enough data (%d)\n", d287 1 a287 1 DPRINTF(("gzip_global: isize = %d (%02x %02x %02x %02x)\n", d309 1 a309 1 DPRINTF(("zbuf avail_in %d, avail_out %d\n", d322 1 a322 1 DPRINTF(("pre: %s in:%d out:%d\n", decomp ? "deflate()" : "inflate()", d326 1 a326 1 DPRINTF(("post: %s in:%d out:%d\n", decomp ? "deflate()" : "inflate()", d362 1 a362 1 DPRINTF(("gzip_global: in %d -> out %d\n", size, result)); @ 1.21.12.1 log @update from HEAD @ text @d1 1 a1 1 /* $NetBSD$ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD$"); d91 1 a91 1 DPRINTF("size %u\n", size); d239 1 a239 1 DPRINTF("decomp %d, size %u\n", decomp, size); d248 1 a248 1 DPRINTF("compress malloc %u + %zu + %u = %zu\n", d250 1 a250 1 size + sizeof(gzip_header) + GZIP_TAIL_SIZE); d254 1 a254 1 DPRINTF("size %u, crc 0x%x\n", size, crc); d262 2 a263 1 DPRINTF("not enough data (%u)\n", size); d275 2 a276 2 DPRINTF("unsupported gzip header (%02x%02x)\n", data[0], data[1]); d279 1 a279 1 DPRINTF("%d: gzip header ok\n",__LINE__); d287 1 a287 1 DPRINTF("isize = %u (%02x %02x %02x %02x)\n", d292 1 a292 1 data[size-1]); d309 2 a310 2 DPRINTF("zbuf avail_in %u, avail_out %u\n", zbuf.avail_in, zbuf.avail_out); d322 2 a323 2 DPRINTF("pre: %s in:%u out:%u\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out); d326 2 a327 2 DPRINTF("post: %s in:%u out:%u\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out); d362 1 a362 1 DPRINTF("in %u -> out %u\n", size, result); d403 1 a403 1 DPRINTF("size = 0x%x (%02x %02x %02x %02x)\n", d408 1 a408 1 output[4]); d411 1 a411 1 DPRINTF("crc/size mismatch\n"); @ 1.21.30.1 log @Sync with HEAD @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.22 2015/03/26 17:40:16 prlw1 Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.22 2015/03/26 17:40:16 prlw1 Exp $"); d91 1 a91 1 DPRINTF(("deflate_global: size %u\n", size)); d239 1 a239 1 DPRINTF(("gzip_global: decomp %d, size %u\n", decomp, size)); d248 1 a248 1 DPRINTF(("gzip_global: compress malloc %u + %zu + %u = %zu\n", d254 1 a254 1 DPRINTF(("gzip_compress: size %u, crc 0x%x\n", size, crc)); d262 1 a262 1 DPRINTF(("gzip_global: not enough data (%u)\n", d287 1 a287 1 DPRINTF(("gzip_global: isize = %u (%02x %02x %02x %02x)\n", d309 1 a309 1 DPRINTF(("zbuf avail_in %u, avail_out %u\n", d322 1 a322 1 DPRINTF(("pre: %s in:%u out:%u\n", decomp ? "deflate()" : "inflate()", d326 1 a326 1 DPRINTF(("post: %s in:%u out:%u\n", decomp ? "deflate()" : "inflate()", d362 1 a362 1 DPRINTF(("gzip_global: in %u -> out %u\n", size, result)); @ 1.21.30.2 log @Sync with HEAD @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.21.30.1 2015/04/06 15:18:24 skrll Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.21.30.1 2015/04/06 15:18:24 skrll Exp $"); d91 1 a91 1 DPRINTF("size %u\n", size); d239 1 a239 1 DPRINTF("decomp %d, size %u\n", decomp, size); d248 1 a248 1 DPRINTF("compress malloc %u + %zu + %u = %zu\n", d250 1 a250 1 size + sizeof(gzip_header) + GZIP_TAIL_SIZE); d254 1 a254 1 DPRINTF("size %u, crc 0x%x\n", size, crc); d262 2 a263 1 DPRINTF("not enough data (%u)\n", size); d275 2 a276 2 DPRINTF("unsupported gzip header (%02x%02x)\n", data[0], data[1]); d279 1 a279 1 DPRINTF("%d: gzip header ok\n",__LINE__); d287 1 a287 1 DPRINTF("isize = %u (%02x %02x %02x %02x)\n", d292 1 a292 1 data[size-1]); d309 2 a310 2 DPRINTF("zbuf avail_in %u, avail_out %u\n", zbuf.avail_in, zbuf.avail_out); d322 2 a323 2 DPRINTF("pre: %s in:%u out:%u\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out); d326 2 a327 2 DPRINTF("post: %s in:%u out:%u\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out); d362 1 a362 1 DPRINTF("in %u -> out %u\n", size, result); d403 1 a403 1 DPRINTF("size = 0x%x (%02x %02x %02x %02x)\n", d408 1 a408 1 output[4]); d411 1 a411 1 DPRINTF("crc/size mismatch\n"); @ 1.20 log @-start to make the GZIP code similar to DEFLATE: make error handling work the same way, grow output buffer exponentially and kill reallocation of metadata -minor cleanup, make definitions private which are implementation details of deflate.gzip @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.19 2011/02/24 20:03:41 drochner Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.19 2011/02/24 20:03:41 drochner Exp $"); d237 1 a237 1 u_int32_t isize, icrc; @ 1.19 log @small modifications in dealing with the unknown result size of compression/ decompression: -seperate the IPCOMP specific rule that compression must not grow the data from general compression semantics: Introduce a special name CRYPTO_DEFLATE_COMP_NOGROW/comp_algo_deflate_nogrow to describe the IPCOMP semantics and use it there. (being here, fix the check so that equal size is considered failure as well as required by RFC2393) Customers of CRYPTO_DEFLATE_COMP/comp_algo_deflate now always get deflated data back, even if they are not smaller than the original. -allow to pass a "size hint" to the DEFLATE decompression function which is used for the initial buffer allocation. Due to the changes done there, additional allocations and extra copies are avoided if the initial allocation is sufficient. Set the size hint to MCLBYTES (=2k) in IPCOMP which should be good for many use cases. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.18 2011/02/18 22:02:09 drochner Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.18 2011/02/18 22:02:09 drochner Exp $"); d49 6 d234 2 a235 3 int error, i = 0, j; struct deflate_buf *buf, *tmp; size_t nbufs; a240 8 nbufs = ZBUF; buf = malloc(nbufs*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (buf == NULL) { DPRINTF(("gzip_global.%d: failed to malloc %d\n", __LINE__, nbufs*sizeof(struct deflate_buf))); return 0; } a245 5 crc = crc32(0, NULL, 0); /* get initial crc value */ zbuf.avail_in = size; /* Total length of data to be processed */ zbuf.next_in = data; /* data that is going to be processed */ d248 2 a249 2 DPRINTF(("gzip_global: compress[%d] malloc %d + %d + %d = %d\n", i, size, sizeof(gzip_header), GZIP_TAIL_SIZE, d253 1 a253 2 crc = crc32(crc, data, size); d255 2 d260 1 a260 1 if (zbuf.avail_in <= 0) { d264 1 a264 1 goto bad2; d277 1 a277 1 goto bad2; d295 1 d306 1 a306 1 goto bad2; d319 1 a319 1 goto bad; d328 11 a338 2 if (error != Z_OK && error != Z_STREAM_END) { printf("deflate() or inflate() failed, error=%d\n", error); d340 1 a340 15 } else if (zbuf.avail_in == 0 && zbuf.avail_out != 0) { DPRINTF(("gzip_global: avail_in == 0, ending\n")); goto end; } else if (zbuf.avail_in == 0 && zbuf.avail_out == 0) { DPRINTF(("gzip_global: avail_in == 0, avail_out == 0, ending\n")); goto end; } else if (zbuf.avail_out == 0) { if (i == nbufs) { nbufs += ZBUF; tmp = realloc(buf,nbufs*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (tmp == NULL) goto bad; buf = tmp; } d342 4 a345 1 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); d349 1 a349 2 buf[i].size = size; zbuf.avail_out = buf[i].size; d351 1 a351 2 } else goto bad; a353 1 end: a394 1 free(buf, M_CRYPTO_DATA); d411 1 a428 1 free(buf, M_CRYPTO_DATA); @ 1.18 log @redo result buffer allocation, to avoid dynamic allocations: -use exponentially growing buffer sizes instead of just linear extension -drop the dynamic allocation of buffer metadata introduced in rev.1.8 -- if the initial array is not sufficient something is wrong -apply some (arbitrary, heuristic) limit so that compressed data which extract into insane amounts of constant data don't kill the system This addresses PR kern/36864 by Wolfgang Stukenbrock. Some tuning might be useful, but hopefully this is an improvement already. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.17 2011/02/18 10:50:56 drochner Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.17 2011/02/18 10:50:56 drochner Exp $"); d74 2 a75 1 deflate_global(u_int8_t *data, u_int32_t size, int decomp, u_int8_t **out) d104 1 a104 1 buf[0].size = size * 4; d222 1 a222 1 int decomp, u_int8_t **out) @ 1.17 log @address the obvious byteorder and alignment problems in gzip size/crc tail, should fix PR kern/44210 by Wolfgang Stukenbrock being here, fix a bug in crc calculation of decompressed data, and actually verify the crc @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.16 2011/02/17 17:10:18 drochner Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.16 2011/02/17 17:10:18 drochner Exp $"); d82 1 a82 2 struct deflate_buf *buf, *tmp; size_t len; a85 5 len = ZBUF; buf = malloc(len*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (buf == NULL) return 0; d107 1 a107 1 goto bad3; a138 8 if (i == len) { len += ZBUF; tmp = realloc(buf,len*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (tmp == NULL) goto bad; buf = tmp; } d140 4 a143 1 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); d147 1 a147 2 buf[i].size = size; zbuf.avail_out = buf[i].size; a171 1 free(buf, M_CRYPTO_DATA); a185 2 bad3: free(buf, M_CRYPTO_DATA); @ 1.16 log @The decompressor in sys/net/zlib.c has a bug: It returns Z_BUF_ERROR after a successful decompression in rare cases. A necessary but not sufficient condition seems to be that the decompressed data end exactly at the end of an allocated output buffer. (I can reproduce this reliably with a userland program built against kernel zlib. Userland libz is much newer and not affected.) Since kernel zlib is based on an old version and heavily modified, I don't dare to touch it. So catch this case in the wrapper. Being here, reorder deflate/inflate error handling and add comments to make understandable what is tested and why. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.15 2011/02/16 19:08:57 drochner Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.15 2011/02/16 19:08:57 drochner Exp $"); d246 1 a246 1 u_int32_t isize; d303 4 a306 1 isize = *((uint32_t *)&data[size-sizeof(uint32_t)]); d405 1 a405 1 crc = crc32(crc, buf[j].out, buf[j].size); d424 4 a427 2 ((uint32_t *)output)[0] = crc; ((uint32_t *)output)[1] = size; d435 6 @ 1.15 log @-avoid allocation of an extra result buffer and data copy in case the DEFLATE complssion/decompression result is within a single buffer already -simplify bookkeeping of allocated buffers (and don't waste the last member of the metadata array) from Wolfgang Stukenbrock per PR kern/36865 (with some cleanup of error handling by me) The Gzip compression case can be improved too, but for now I've applied the buffer bookkeeping changes. tested with IP4 IPCOMP @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.14 2011/02/10 21:17:49 drochner Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.14 2011/02/10 21:17:49 drochner Exp $"); d128 15 a142 1 if (error != Z_OK && error != Z_STREAM_END) a143 2 else if (zbuf.avail_in == 0 && zbuf.avail_out != 0) goto end; d161 1 a161 2 } else goto bad; a163 1 end: @ 1.14 log @whan compressing, set the Z_FINISH flag to zlib to tell that the data chunk is the final one, which makes that zlib issues the proper termination marker (KAME IPSEC does this, but doesn't check eagerly in the receive path, so the missing termination didn't cause problems so far) closes my PR kern/44539 being here, replace the Z_PARTIAL_FLUSH flag which is marked deprecated by zlib by Z_SYNC_FLUSH in the decompression path (tested with IPv4 IPCOMP on i386) @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.13 2009/03/25 01:26:13 darran Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.13 2009/03/25 01:26:13 darran Exp $"); d80 2 a81 2 u_int32_t count, result; int error, i = 0, j; d83 1 a83 1 size_t len, old_len; a92 3 for (j = 0; j < len; j++) buf[j].flag = 0; d100 1 a100 6 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad; buf[i].size = size; buf[i].flag = 1; i++; d109 1 a109 6 buf[i].size = size * 4; buf[i].out = malloc(buf[i].size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad; buf[i].flag = 1; i++; d111 4 d124 1 a124 1 goto bad; d133 1 a133 2 if (i == (len-1)) { old_len = i; a139 2 for (j = old_len; j < len; j++) buf[j].flag = 0; a146 1 buf[i].flag = 1; d156 19 a174 3 *out = malloc(result, M_CRYPTO_DATA, M_NOWAIT); if (*out == NULL) goto bad; a178 17 output = *out; for (j = 0; buf[j].flag != 0; j++) { if (count > buf[j].size) { memcpy(*out, buf[j].out, buf[j].size); *out += buf[j].size; free(buf[j].out, M_CRYPTO_DATA); count -= buf[j].size; } else { /* it should be the last buffer */ memcpy(*out, buf[j].out, count); *out += count; free(buf[j].out, M_CRYPTO_DATA); count = 0; } } free(buf, M_CRYPTO_DATA); *out = output; a181 4 *out = NULL; for (j = 0; buf[j].flag != 0; j++) free(buf[j].out, M_CRYPTO_DATA); free(buf, M_CRYPTO_DATA); d186 5 d234 1 a234 1 size_t nbufs, old_nbufs; a248 3 for (j = 0; j < nbufs; j++) buf[j].flag = 0; d264 1 a264 5 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad2; buf[i].size = size; buf[i].flag = 1; a265 4 zbuf.next_out = buf[i].out; zbuf.avail_out = buf[i].size; i++; d302 1 a302 8 buf[i].size = isize; buf[i].out = malloc(buf[i].size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad2; buf[i].flag = 1; zbuf.next_out = buf[i].out; zbuf.avail_out = buf[i].size; i++; a308 3 DPRINTF(("zbuf avail_in %d, avail_out %d\n", zbuf.avail_in, zbuf.avail_out)); d311 8 d345 1 a345 2 if (i == (nbufs-1)) { old_nbufs = i; a351 2 for (j = old_nbufs; j < nbufs; j++) buf[j].flag = 0; a358 1 buf[i].flag = 1; d389 1 a389 1 for (j = 0; buf[j].flag != 0; j++) { d431 1 a431 1 for (j = 0; buf[j].flag != 0; j++) @ 1.13 log @Fixes PR kern/41069 and PR kern/41070. Extends the Opencrypto API to allow the destination buffer size to be specified when its not the same size as the input buffer (i.e. for operations like compress and decompress). The crypto_op and crypt_n_op structures gain a u_int dst_len field. The session_op structure gains a comp_alg field to specify a compression algorithm. Moved four ioctls to new ids; CIOCGSESSION, CIOCNGSESSION, CIOCCRYPT, and CIOCNCRYPTM. Added four backward compatible ioctls; OCIOCGSESSION, OCIOCNGSESSION, OCIOCCRYPT, and OCIOCNCRYPTM. Backward compatibility is maintained in ocryptodev.h and ocryptodev.c which implement the original ioctls and set dst_len and comp_alg to 0. Adds user-space access to compression features. Adds software gzip support (CRYPTO_GZIP_COMP). Adds the fast version of crc32 from zlib to libkern. This should be generally useful and provide a place to start normalizing the various crc32 routines in the kernel. The crc32 routine is used in this patch to support GZIP. With input and support from tls@@NetBSD.org. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.12 2009/03/14 15:36:24 dsl Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.12 2009/03/14 15:36:24 dsl Exp $"); d135 2 a136 2 error = decomp ? inflate(&zbuf, Z_PARTIAL_FLUSH) : deflate(&zbuf, Z_PARTIAL_FLUSH); d357 2 a358 2 error = decomp ? inflate(&zbuf, Z_PARTIAL_FLUSH) : deflate(&zbuf, Z_PARTIAL_FLUSH); @ 1.13.6.1 log @Sync with HEAD. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.20 2011/03/09 11:36:43 drochner Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.20 2011/03/09 11:36:43 drochner Exp $"); a48 6 #define ZBUF 10 struct deflate_buf { u_int8_t *out; u_int32_t size; }; d74 1 a74 2 deflate_global(u_int8_t *data, u_int32_t size, int decomp, u_int8_t **out, int size_hint) d80 4 a83 3 u_int32_t count, result, tocopy; int error, i, j; struct deflate_buf buf[ZBUF]; d87 5 d93 3 d103 6 a108 1 buf[0].size = size; d117 6 a122 1 buf[0].size = MAX(size * 4, size_hint); a123 4 buf[0].out = malloc(buf[0].size, M_CRYPTO_DATA, M_NOWAIT); if (buf[0].out == NULL) return 0; i = 1; d133 1 a133 1 goto bad2; d135 3 a137 17 error = decomp ? inflate(&zbuf, Z_SYNC_FLUSH) : deflate(&zbuf, Z_FINISH); if (error == Z_STREAM_END) /* success */ break; /* * XXX compensate for two problems: * -Former versions of this code didn't set Z_FINISH * on compression, so the compressed data are not correctly * terminated and the decompressor doesn't get Z_STREAM_END. * Accept such packets for interoperability. * -sys/net/zlib.c has a bug which makes that Z_BUF_ERROR is * set after successful decompression under rare conditions. */ else if (decomp && (error == Z_OK || error == Z_BUF_ERROR) && zbuf.avail_in == 0 && zbuf.avail_out != 0) break; else if (error != Z_OK) d139 2 d142 11 d154 1 a154 4 int nextsize = buf[i-1].size * 2; if (i == ZBUF || nextsize > 1000000) goto bad; buf[i].out = malloc(nextsize, M_CRYPTO_DATA, M_NOWAIT); d158 3 a160 1 zbuf.avail_out = buf[i].size = nextsize; d162 2 a163 1 } d166 1 d169 3 a171 18 if (i != 1) { /* copy everything into one buffer */ output = malloc(result, M_CRYPTO_DATA, M_NOWAIT); if (output == NULL) goto bad; *out = output; for (j = 0; j < i; j++) { tocopy = MIN(count, buf[j].size); /* XXX the last buf can be empty */ KASSERT(tocopy || j == (i - 1)); memcpy(output, buf[j].out, tocopy); output += tocopy; free(buf[j].out, M_CRYPTO_DATA); count -= tocopy; } KASSERT(count == 0); } else { *out = buf[0].out; } d176 17 d196 4 a203 3 bad2: for (j = 0; j < i; j++) free(buf[j].out, M_CRYPTO_DATA); d239 1 a239 1 int decomp, u_int8_t **out, int size_hint) d245 3 a247 2 int error, i, j; struct deflate_buf buf[ZBUF]; d249 1 a249 1 u_int32_t isize, icrc; d253 8 d262 3 d269 5 d276 2 a277 2 DPRINTF(("gzip_global: compress malloc %d + %d + %d = %d\n", size, sizeof(gzip_header), GZIP_TAIL_SIZE, d280 11 a290 2 buf[0].size = size; crc = crc32(0, data, size); a291 2 zbuf.avail_in = size; /* Total length of data to be processed */ zbuf.next_in = data; /* data that is going to be processed */ d295 1 a295 1 if (size <= sizeof(gzip_header) + GZIP_TAIL_SIZE) { d299 1 a299 1 return 0; d312 1 a312 1 return 0; d317 1 a317 4 memcpy(&isize, &data[size-sizeof(uint32_t)], sizeof(uint32_t)); LE32TOH(isize); memcpy(&icrc, &data[size-2*sizeof(uint32_t)], sizeof(uint32_t)); LE32TOH(icrc); d326 8 a333 2 buf[0].size = isize; crc = crc32(0, NULL, 0); /* get initial crc value */ d340 3 a344 8 buf[0].out = malloc(buf[0].size, M_CRYPTO_DATA, M_NOWAIT); if (buf[0].out == NULL) return 0; zbuf.next_out = buf[0].out; zbuf.avail_out = buf[0].size; DPRINTF(("zbuf avail_in %d, avail_out %d\n", zbuf.avail_in, zbuf.avail_out)); i = 1; d352 1 a352 1 goto bad2; d357 2 a358 2 error = decomp ? inflate(&zbuf, Z_SYNC_FLUSH) : deflate(&zbuf, Z_FINISH); d361 2 a362 11 if (error == Z_STREAM_END) /* success */ break; /* * XXX compensate for a zlib problem: * -sys/net/zlib.c has a bug which makes that Z_BUF_ERROR is * set after successful decompression under rare conditions. */ else if (decomp && error == Z_BUF_ERROR && zbuf.avail_in == 0 && zbuf.avail_out != 0) break; else if (error != Z_OK) d364 18 a381 1 else if (zbuf.avail_out == 0) { d383 1 a383 4 int nextsize = buf[i-1].size * 2; if (i == ZBUF || nextsize > 1000000) goto bad; buf[i].out = malloc(nextsize, M_CRYPTO_DATA, M_NOWAIT); d387 3 a389 1 zbuf.avail_out = buf[i].size = nextsize; d391 2 a392 1 } d395 1 d419 1 a419 1 for (j = 0; j < i; j++) { d422 1 a422 1 crc = crc32(crc, buf[j].out, MIN(count, buf[j].size)); d437 1 d441 2 a442 4 HTOLE32(crc); memcpy(output, &crc, sizeof(uint32_t)); HTOLE32(size); memcpy(output + sizeof(uint32_t), &size, sizeof(uint32_t)); a449 7 } else { if (crc != icrc || result != isize) { DPRINTF(("gzip_global: crc/size mismatch\n")); free(*out, M_CRYPTO_DATA); *out = NULL; return 0; } d461 1 a461 1 for (j = 0; j < i; j++) d463 1 @ 1.13.4.1 log @sync with head @ text @d1 1 a1 1 /* $NetBSD$ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD$"); d74 1 a74 2 deflate_global(u_int8_t *data, u_int32_t size, int decomp, u_int8_t **out, int size_hint) d80 4 a83 3 u_int32_t count, result, tocopy; int error, i, j; struct deflate_buf buf[ZBUF]; d87 5 d93 3 d103 6 a108 1 buf[0].size = size; d117 6 a122 1 buf[0].size = MAX(size * 4, size_hint); a123 4 buf[0].out = malloc(buf[0].size, M_CRYPTO_DATA, M_NOWAIT); if (buf[0].out == NULL) return 0; i = 1; d133 1 a133 1 goto bad2; d135 3 a137 17 error = decomp ? inflate(&zbuf, Z_SYNC_FLUSH) : deflate(&zbuf, Z_FINISH); if (error == Z_STREAM_END) /* success */ break; /* * XXX compensate for two problems: * -Former versions of this code didn't set Z_FINISH * on compression, so the compressed data are not correctly * terminated and the decompressor doesn't get Z_STREAM_END. * Accept such packets for interoperability. * -sys/net/zlib.c has a bug which makes that Z_BUF_ERROR is * set after successful decompression under rare conditions. */ else if (decomp && (error == Z_OK || error == Z_BUF_ERROR) && zbuf.avail_in == 0 && zbuf.avail_out != 0) break; else if (error != Z_OK) d139 2 d142 11 d154 1 a154 4 int nextsize = buf[i-1].size * 2; if (i == ZBUF || nextsize > 1000000) goto bad; buf[i].out = malloc(nextsize, M_CRYPTO_DATA, M_NOWAIT); d158 3 a160 1 zbuf.avail_out = buf[i].size = nextsize; d162 2 a163 1 } d166 1 d169 3 a171 18 if (i != 1) { /* copy everything into one buffer */ output = malloc(result, M_CRYPTO_DATA, M_NOWAIT); if (output == NULL) goto bad; *out = output; for (j = 0; j < i; j++) { tocopy = MIN(count, buf[j].size); /* XXX the last buf can be empty */ KASSERT(tocopy || j == (i - 1)); memcpy(output, buf[j].out, tocopy); output += tocopy; free(buf[j].out, M_CRYPTO_DATA); count -= tocopy; } KASSERT(count == 0); } else { *out = buf[0].out; } d176 17 d196 4 a203 3 bad2: for (j = 0; j < i; j++) free(buf[j].out, M_CRYPTO_DATA); d239 1 a239 1 int decomp, u_int8_t **out, int size_hint) d247 1 a247 1 size_t nbufs; d249 1 a249 1 u_int32_t isize, icrc; d262 3 d280 5 a284 1 buf[0].size = size; d286 4 d317 1 a317 4 memcpy(&isize, &data[size-sizeof(uint32_t)], sizeof(uint32_t)); LE32TOH(isize); memcpy(&icrc, &data[size-2*sizeof(uint32_t)], sizeof(uint32_t)); LE32TOH(icrc); d326 8 a333 1 buf[0].size = isize; d340 3 a344 8 buf[0].out = malloc(buf[0].size, M_CRYPTO_DATA, M_NOWAIT); if (buf[0].out == NULL) goto bad2; zbuf.next_out = buf[0].out; zbuf.avail_out = buf[0].size; DPRINTF(("zbuf avail_in %d, avail_out %d\n", zbuf.avail_in, zbuf.avail_out)); i = 1; d357 2 a358 2 error = decomp ? inflate(&zbuf, Z_SYNC_FLUSH) : deflate(&zbuf, Z_FINISH); d371 2 a372 1 if (i == nbufs) { d379 2 d388 1 d419 1 a419 1 for (j = 0; j < i; j++) { d422 1 a422 1 crc = crc32(crc, buf[j].out, MIN(count, buf[j].size)); d441 2 a442 4 HTOLE32(crc); memcpy(output, &crc, sizeof(uint32_t)); HTOLE32(size); memcpy(output + sizeof(uint32_t), &size, sizeof(uint32_t)); a449 6 } else { if (crc != icrc || result != isize) { free(*out, M_CRYPTO_DATA); *out = NULL; return 0; } d461 1 a461 1 for (j = 0; j < i; j++) @ 1.13.4.2 log @sync with head @ text @a48 6 #define ZBUF 10 struct deflate_buf { u_int8_t *out; u_int32_t size; }; d228 3 a230 2 int error, i, j; struct deflate_buf buf[ZBUF]; d236 8 d249 5 d256 2 a257 2 DPRINTF(("gzip_global: compress malloc %d + %d + %d = %d\n", size, sizeof(gzip_header), GZIP_TAIL_SIZE, d261 2 a262 1 crc = crc32(0, data, size); a263 2 zbuf.avail_in = size; /* Total length of data to be processed */ zbuf.next_in = data; /* data that is going to be processed */ d267 1 a267 1 if (size <= sizeof(gzip_header) + GZIP_TAIL_SIZE) { d271 1 a271 1 return 0; d284 1 a284 1 return 0; a301 1 crc = crc32(0, NULL, 0); /* get initial crc value */ d312 1 a312 1 return 0; d325 1 a325 1 goto bad2; d334 2 a335 11 if (error == Z_STREAM_END) /* success */ break; /* * XXX compensate for a zlib problem: * -sys/net/zlib.c has a bug which makes that Z_BUF_ERROR is * set after successful decompression under rare conditions. */ else if (decomp && error == Z_BUF_ERROR && zbuf.avail_in == 0 && zbuf.avail_out != 0) break; else if (error != Z_OK) d337 15 a351 1 else if (zbuf.avail_out == 0) { d353 1 a353 4 int nextsize = buf[i-1].size * 2; if (i == ZBUF || nextsize > 1000000) goto bad; buf[i].out = malloc(nextsize, M_CRYPTO_DATA, M_NOWAIT); d357 2 a358 1 zbuf.avail_out = buf[i].size = nextsize; d360 2 a361 1 } d364 1 d406 1 a422 1 DPRINTF(("gzip_global: crc/size mismatch\n")); d440 1 @ 1.13.8.1 log @Sync with HEAD @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.15 2011/02/16 19:08:57 drochner Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.15 2011/02/16 19:08:57 drochner Exp $"); d80 2 a81 2 u_int32_t count, result, tocopy; int error, i, j; d83 1 a83 1 size_t len; d93 3 d103 6 a108 1 buf[0].size = size; d117 6 a122 1 buf[0].size = size * 4; a123 4 buf[0].out = malloc(buf[0].size, M_CRYPTO_DATA, M_NOWAIT); if (buf[0].out == NULL) goto bad3; i = 1; d133 1 a133 1 goto bad2; d135 2 a136 2 error = decomp ? inflate(&zbuf, Z_SYNC_FLUSH) : deflate(&zbuf, Z_FINISH); d142 2 a143 1 if (i == len) { d150 2 d159 1 d169 18 a186 11 if (i != 1) { /* copy everything into one buffer */ output = malloc(result, M_CRYPTO_DATA, M_NOWAIT); if (output == NULL) goto bad; *out = output; for (j = 0; j < i; j++) { tocopy = MIN(count, buf[j].size); /* XXX the last buf can be empty */ KASSERT(tocopy || j == (i - 1)); memcpy(output, buf[j].out, tocopy); output += tocopy; d188 1 a188 1 count -= tocopy; a189 3 KASSERT(count == 0); } else { *out = buf[0].out; d192 1 a192 4 if (decomp) inflateEnd(&zbuf); else deflateEnd(&zbuf); d196 4 a203 5 bad2: for (j = 0; j < i; j++) free(buf[j].out, M_CRYPTO_DATA); bad3: free(buf, M_CRYPTO_DATA); d247 1 a247 1 size_t nbufs; d262 3 d280 5 a284 1 buf[0].size = size; d286 4 d326 8 a333 1 buf[0].size = isize; d340 3 a344 8 buf[0].out = malloc(buf[0].size, M_CRYPTO_DATA, M_NOWAIT); if (buf[0].out == NULL) goto bad2; zbuf.next_out = buf[0].out; zbuf.avail_out = buf[0].size; DPRINTF(("zbuf avail_in %d, avail_out %d\n", zbuf.avail_in, zbuf.avail_out)); i = 1; d357 2 a358 2 error = decomp ? inflate(&zbuf, Z_SYNC_FLUSH) : deflate(&zbuf, Z_FINISH); d371 2 a372 1 if (i == nbufs) { d379 2 d388 1 d419 1 a419 1 for (j = 0; j < i; j++) { d461 1 a461 1 for (j = 0; j < i; j++) @ 1.13.8.2 log @Sync with HEAD @ text @d1 1 a1 1 /* $NetBSD$ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD$"); d74 1 a74 2 deflate_global(u_int8_t *data, u_int32_t size, int decomp, u_int8_t **out, int size_hint) d82 2 a83 1 struct deflate_buf buf[ZBUF]; d87 5 d109 1 a109 1 buf[0].size = MAX(size * 4, size_hint); d113 1 a113 1 return 0; d128 1 a128 15 if (error == Z_STREAM_END) /* success */ break; /* * XXX compensate for two problems: * -Former versions of this code didn't set Z_FINISH * on compression, so the compressed data are not correctly * terminated and the decompressor doesn't get Z_STREAM_END. * Accept such packets for interoperability. * -sys/net/zlib.c has a bug which makes that Z_BUF_ERROR is * set after successful decompression under rare conditions. */ else if (decomp && (error == Z_OK || error == Z_BUF_ERROR) && zbuf.avail_in == 0 && zbuf.avail_out != 0) break; else if (error != Z_OK) d130 2 d133 8 d142 1 a142 4 int nextsize = buf[i-1].size * 2; if (i == ZBUF || nextsize > 1000000) goto bad; buf[i].out = malloc(nextsize, M_CRYPTO_DATA, M_NOWAIT); d146 2 a147 1 zbuf.avail_out = buf[i].size = nextsize; d149 2 a150 1 } d153 1 d174 1 d189 2 d226 1 a226 1 int decomp, u_int8_t **out, int size_hint) d236 1 a236 1 u_int32_t isize, icrc; d293 1 a293 4 memcpy(&isize, &data[size-sizeof(uint32_t)], sizeof(uint32_t)); LE32TOH(isize); memcpy(&icrc, &data[size-2*sizeof(uint32_t)], sizeof(uint32_t)); LE32TOH(icrc); d392 1 a392 1 crc = crc32(crc, buf[j].out, MIN(count, buf[j].size)); d411 2 a412 4 HTOLE32(crc); memcpy(output, &crc, sizeof(uint32_t)); HTOLE32(size); memcpy(output + sizeof(uint32_t), &size, sizeof(uint32_t)); a419 6 } else { if (crc != icrc || result != isize) { free(*out, M_CRYPTO_DATA); *out = NULL; return 0; } @ 1.12 log @Change about 4500 of the K&R function definitions to ANSI ones. There are still about 1600 left, but they have ',' or /* ... */ in the actual variable definitions - which my awk script doesn't handle. There are also many that need () -> (void). (The script does handle misordered arguments.) @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.11 2008/05/05 13:41:30 ad Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.11 2008/05/05 13:41:30 ad Exp $"); d49 1 d85 2 d206 260 @ 1.11 log @Back out previous. It broke the build. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.10 2008/05/04 23:07:09 ad Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.9 2007/09/22 23:38:17 degroote Exp $"); d73 1 a73 5 deflate_global(data, size, decomp, out) u_int8_t *data; u_int32_t size; int decomp; u_int8_t **out; @ 1.11.18.1 log @bring matt-nb5-mips64 up to date with netbsd-5-1-RELEASE (except compat). @ text @d1 1 a1 1 /* $NetBSD$ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD$"); a48 1 a87 2 DPRINTF(("deflate_global: size %d\n", size)); a206 260 /* * Initial version will perform a single gzip encapsulation, * filling in the header, * and appending the crc and uncompressed length. * * Later version will support multiple buffers with * a flag indication final buffer. The crc is maintained * over all buffers and appended to the output along with * the uncompressed length after the final data buffer * has been compressed and output. * * Ditto for uncompress - CRC is extracted from the final packed * and compared against CRC of uncompressed data. * */ /* constant header for the gzip */ static const char gzip_header[10] = { 0x1f, 0x8b, /* ID1 ID2 */ Z_DEFLATED, /* CM */ 0, /* FLG */ 0, 0, 0, 0, /* MTIME */ 0, /* XFL */ 0x03 /* OS (Unix) */ }; /* Followed by compressed payload */ /* Followed by uint32_t CRC32 and uint32_t ISIZE */ #define GZIP_TAIL_SIZE 8 u_int32_t gzip_global(u_int8_t *data, u_int32_t size, int decomp, u_int8_t **out) { /* decomp indicates whether we compress (0) or decompress (1) */ z_stream zbuf; u_int8_t *output; u_int32_t count, result; int error, i = 0, j; struct deflate_buf *buf, *tmp; size_t nbufs, old_nbufs; u_int32_t crc; u_int32_t isize; DPRINTF(("gzip_global: decomp %d, size %d\n", decomp, size)); nbufs = ZBUF; buf = malloc(nbufs*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (buf == NULL) { DPRINTF(("gzip_global.%d: failed to malloc %d\n", __LINE__, nbufs*sizeof(struct deflate_buf))); return 0; } memset(&zbuf, 0, sizeof(z_stream)); for (j = 0; j < nbufs; j++) buf[j].flag = 0; zbuf.zalloc = ocf_zalloc; zbuf.zfree = ocf_zfree; zbuf.opaque = Z_NULL; crc = crc32(0, NULL, 0); /* get initial crc value */ zbuf.avail_in = size; /* Total length of data to be processed */ zbuf.next_in = data; /* data that is going to be processed */ if (!decomp) { /* compress */ DPRINTF(("gzip_global: compress[%d] malloc %d + %d + %d = %d\n", i, size, sizeof(gzip_header), GZIP_TAIL_SIZE, size + sizeof(gzip_header) + GZIP_TAIL_SIZE)); buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad2; buf[i].size = size; buf[i].flag = 1; zbuf.next_out = buf[i].out; zbuf.avail_out = buf[i].size; i++; crc = crc32(crc, data, size); DPRINTF(("gzip_compress: size %d, crc 0x%x\n", size, crc)); } else { /* decompress */ /* check the gzip header */ if (zbuf.avail_in <= 0) { /* Not enough data for the header & tail */ DPRINTF(("gzip_global: not enough data (%d)\n", size)); goto bad2; } /* XXX this is pretty basic, * needs to be expanded to ignore MTIME, OS, * but still ensure flags are 0. * Q. Do we need to support the flags and * optional header fields? Likely. * XXX add flag and field support too. */ if (memcmp(data, gzip_header, sizeof(gzip_header)) != 0) { DPRINTF(("gzip_global: unsupported gzip header (%02x%02x)\n", data[0], data[1])); goto bad2; } else { DPRINTF(("gzip_global.%d: gzip header ok\n",__LINE__)); } isize = *((uint32_t *)&data[size-sizeof(uint32_t)]); DPRINTF(("gzip_global: isize = %d (%02x %02x %02x %02x)\n", isize, data[size-4], data[size-3], data[size-2], data[size-1])); buf[i].size = isize; buf[i].out = malloc(buf[i].size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad2; buf[i].flag = 1; zbuf.next_out = buf[i].out; zbuf.avail_out = buf[i].size; i++; /* skip over the gzip header */ zbuf.next_in = data + sizeof(gzip_header); /* actual payload size stripped of gzip header and tail */ zbuf.avail_in = size - sizeof(gzip_header) - GZIP_TAIL_SIZE; DPRINTF(("zbuf avail_in %d, avail_out %d\n", zbuf.avail_in, zbuf.avail_out)); } error = decomp ? inflateInit2(&zbuf, window_inflate) : deflateInit2(&zbuf, Z_DEFAULT_COMPRESSION, Z_METHOD, window_deflate, Z_MEMLEVEL, Z_DEFAULT_STRATEGY); if (error != Z_OK) { printf("deflateInit2() failed\n"); goto bad; } for (;;) { DPRINTF(("pre: %s in:%d out:%d\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out)); error = decomp ? inflate(&zbuf, Z_PARTIAL_FLUSH) : deflate(&zbuf, Z_PARTIAL_FLUSH); DPRINTF(("post: %s in:%d out:%d\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out)); if (error != Z_OK && error != Z_STREAM_END) { printf("deflate() or inflate() failed, error=%d\n", error); goto bad; } else if (zbuf.avail_in == 0 && zbuf.avail_out != 0) { DPRINTF(("gzip_global: avail_in == 0, ending\n")); goto end; } else if (zbuf.avail_in == 0 && zbuf.avail_out == 0) { DPRINTF(("gzip_global: avail_in == 0, avail_out == 0, ending\n")); goto end; } else if (zbuf.avail_out == 0) { if (i == (nbufs-1)) { old_nbufs = i; nbufs += ZBUF; tmp = realloc(buf,nbufs*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (tmp == NULL) goto bad; buf = tmp; for (j = old_nbufs; j < nbufs; j++) buf[j].flag = 0; } /* we need more output space, allocate size */ buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad; zbuf.next_out = buf[i].out; buf[i].size = size; buf[i].flag = 1; zbuf.avail_out = buf[i].size; i++; } else goto bad; } end: if (decomp) { count = result = zbuf.total_out; } else { /* need room for header, CRC, and ISIZE */ result = zbuf.total_out + sizeof(gzip_header) + GZIP_TAIL_SIZE; count = zbuf.total_out; } DPRINTF(("gzip_global: in %d -> out %d\n", size, result)); *out = malloc(result, M_CRYPTO_DATA, M_NOWAIT); if (*out == NULL) goto bad; output = *out; if (decomp) inflateEnd(&zbuf); else { deflateEnd(&zbuf); /* fill in gzip header */ memcpy(output, gzip_header, sizeof(gzip_header)); output += sizeof(gzip_header); } for (j = 0; buf[j].flag != 0; j++) { if (decomp) { /* update crc for decompressed data */ crc = crc32(crc, buf[j].out, buf[j].size); } if (count > buf[j].size) { memcpy(output, buf[j].out, buf[j].size); output += buf[j].size; free(buf[j].out, M_CRYPTO_DATA); count -= buf[j].size; } else { /* it should be the last buffer */ memcpy(output, buf[j].out, count); output += count; free(buf[j].out, M_CRYPTO_DATA); count = 0; } } free(buf, M_CRYPTO_DATA); if (!decomp) { /* fill in CRC and ISIZE */ ((uint32_t *)output)[0] = crc; ((uint32_t *)output)[1] = size; DPRINTF(("gzip_global: size = 0x%x (%02x %02x %02x %02x)\n", size, output[7], output[3], output[5], output[4])); } return result; bad: if (decomp) inflateEnd(&zbuf); else deflateEnd(&zbuf); bad2: *out = NULL; for (j = 0; buf[j].flag != 0; j++) free(buf[j].out, M_CRYPTO_DATA); free(buf, M_CRYPTO_DATA); return 0; } @ 1.11.14.1 log @Sync with HEAD. Commit is split, to avoid a "too many arguments" protocol error. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.13 2009/03/25 01:26:13 darran Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.13 2009/03/25 01:26:13 darran Exp $"); a48 1 d73 5 a77 1 deflate_global(u_int8_t *data, u_int32_t size, int decomp, u_int8_t **out) a87 2 DPRINTF(("deflate_global: size %d\n", size)); a206 260 /* * Initial version will perform a single gzip encapsulation, * filling in the header, * and appending the crc and uncompressed length. * * Later version will support multiple buffers with * a flag indication final buffer. The crc is maintained * over all buffers and appended to the output along with * the uncompressed length after the final data buffer * has been compressed and output. * * Ditto for uncompress - CRC is extracted from the final packed * and compared against CRC of uncompressed data. * */ /* constant header for the gzip */ static const char gzip_header[10] = { 0x1f, 0x8b, /* ID1 ID2 */ Z_DEFLATED, /* CM */ 0, /* FLG */ 0, 0, 0, 0, /* MTIME */ 0, /* XFL */ 0x03 /* OS (Unix) */ }; /* Followed by compressed payload */ /* Followed by uint32_t CRC32 and uint32_t ISIZE */ #define GZIP_TAIL_SIZE 8 u_int32_t gzip_global(u_int8_t *data, u_int32_t size, int decomp, u_int8_t **out) { /* decomp indicates whether we compress (0) or decompress (1) */ z_stream zbuf; u_int8_t *output; u_int32_t count, result; int error, i = 0, j; struct deflate_buf *buf, *tmp; size_t nbufs, old_nbufs; u_int32_t crc; u_int32_t isize; DPRINTF(("gzip_global: decomp %d, size %d\n", decomp, size)); nbufs = ZBUF; buf = malloc(nbufs*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (buf == NULL) { DPRINTF(("gzip_global.%d: failed to malloc %d\n", __LINE__, nbufs*sizeof(struct deflate_buf))); return 0; } memset(&zbuf, 0, sizeof(z_stream)); for (j = 0; j < nbufs; j++) buf[j].flag = 0; zbuf.zalloc = ocf_zalloc; zbuf.zfree = ocf_zfree; zbuf.opaque = Z_NULL; crc = crc32(0, NULL, 0); /* get initial crc value */ zbuf.avail_in = size; /* Total length of data to be processed */ zbuf.next_in = data; /* data that is going to be processed */ if (!decomp) { /* compress */ DPRINTF(("gzip_global: compress[%d] malloc %d + %d + %d = %d\n", i, size, sizeof(gzip_header), GZIP_TAIL_SIZE, size + sizeof(gzip_header) + GZIP_TAIL_SIZE)); buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad2; buf[i].size = size; buf[i].flag = 1; zbuf.next_out = buf[i].out; zbuf.avail_out = buf[i].size; i++; crc = crc32(crc, data, size); DPRINTF(("gzip_compress: size %d, crc 0x%x\n", size, crc)); } else { /* decompress */ /* check the gzip header */ if (zbuf.avail_in <= 0) { /* Not enough data for the header & tail */ DPRINTF(("gzip_global: not enough data (%d)\n", size)); goto bad2; } /* XXX this is pretty basic, * needs to be expanded to ignore MTIME, OS, * but still ensure flags are 0. * Q. Do we need to support the flags and * optional header fields? Likely. * XXX add flag and field support too. */ if (memcmp(data, gzip_header, sizeof(gzip_header)) != 0) { DPRINTF(("gzip_global: unsupported gzip header (%02x%02x)\n", data[0], data[1])); goto bad2; } else { DPRINTF(("gzip_global.%d: gzip header ok\n",__LINE__)); } isize = *((uint32_t *)&data[size-sizeof(uint32_t)]); DPRINTF(("gzip_global: isize = %d (%02x %02x %02x %02x)\n", isize, data[size-4], data[size-3], data[size-2], data[size-1])); buf[i].size = isize; buf[i].out = malloc(buf[i].size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad2; buf[i].flag = 1; zbuf.next_out = buf[i].out; zbuf.avail_out = buf[i].size; i++; /* skip over the gzip header */ zbuf.next_in = data + sizeof(gzip_header); /* actual payload size stripped of gzip header and tail */ zbuf.avail_in = size - sizeof(gzip_header) - GZIP_TAIL_SIZE; DPRINTF(("zbuf avail_in %d, avail_out %d\n", zbuf.avail_in, zbuf.avail_out)); } error = decomp ? inflateInit2(&zbuf, window_inflate) : deflateInit2(&zbuf, Z_DEFAULT_COMPRESSION, Z_METHOD, window_deflate, Z_MEMLEVEL, Z_DEFAULT_STRATEGY); if (error != Z_OK) { printf("deflateInit2() failed\n"); goto bad; } for (;;) { DPRINTF(("pre: %s in:%d out:%d\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out)); error = decomp ? inflate(&zbuf, Z_PARTIAL_FLUSH) : deflate(&zbuf, Z_PARTIAL_FLUSH); DPRINTF(("post: %s in:%d out:%d\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out)); if (error != Z_OK && error != Z_STREAM_END) { printf("deflate() or inflate() failed, error=%d\n", error); goto bad; } else if (zbuf.avail_in == 0 && zbuf.avail_out != 0) { DPRINTF(("gzip_global: avail_in == 0, ending\n")); goto end; } else if (zbuf.avail_in == 0 && zbuf.avail_out == 0) { DPRINTF(("gzip_global: avail_in == 0, avail_out == 0, ending\n")); goto end; } else if (zbuf.avail_out == 0) { if (i == (nbufs-1)) { old_nbufs = i; nbufs += ZBUF; tmp = realloc(buf,nbufs*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (tmp == NULL) goto bad; buf = tmp; for (j = old_nbufs; j < nbufs; j++) buf[j].flag = 0; } /* we need more output space, allocate size */ buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad; zbuf.next_out = buf[i].out; buf[i].size = size; buf[i].flag = 1; zbuf.avail_out = buf[i].size; i++; } else goto bad; } end: if (decomp) { count = result = zbuf.total_out; } else { /* need room for header, CRC, and ISIZE */ result = zbuf.total_out + sizeof(gzip_header) + GZIP_TAIL_SIZE; count = zbuf.total_out; } DPRINTF(("gzip_global: in %d -> out %d\n", size, result)); *out = malloc(result, M_CRYPTO_DATA, M_NOWAIT); if (*out == NULL) goto bad; output = *out; if (decomp) inflateEnd(&zbuf); else { deflateEnd(&zbuf); /* fill in gzip header */ memcpy(output, gzip_header, sizeof(gzip_header)); output += sizeof(gzip_header); } for (j = 0; buf[j].flag != 0; j++) { if (decomp) { /* update crc for decompressed data */ crc = crc32(crc, buf[j].out, buf[j].size); } if (count > buf[j].size) { memcpy(output, buf[j].out, buf[j].size); output += buf[j].size; free(buf[j].out, M_CRYPTO_DATA); count -= buf[j].size; } else { /* it should be the last buffer */ memcpy(output, buf[j].out, count); output += count; free(buf[j].out, M_CRYPTO_DATA); count = 0; } } free(buf, M_CRYPTO_DATA); if (!decomp) { /* fill in CRC and ISIZE */ ((uint32_t *)output)[0] = crc; ((uint32_t *)output)[1] = size; DPRINTF(("gzip_global: size = 0x%x (%02x %02x %02x %02x)\n", size, output[7], output[3], output[5], output[4])); } return result; bad: if (decomp) inflateEnd(&zbuf); else deflateEnd(&zbuf); bad2: *out = NULL; for (j = 0; buf[j].flag != 0; j++) free(buf[j].out, M_CRYPTO_DATA); free(buf, M_CRYPTO_DATA); return 0; } @ 1.11.10.1 log @Pull up following revision(s) (requested by tls in ticket #611): sys/lib/libkern/Makefile: patch sys/lib/libkern/crc32.c: revision 1.1 sys/lib/libkern/crc32.h: revision 1.1 sys/lib/libkern/libkern.h: revision 1.89 sys/lib/libkern/arch/i386/Makefile.inc: revision 1.28 sys/net/zlib.h: revision 1.14 via patch sys/opencrypto/crypto.c: revision 1.33 sys/opencrypto/cryptodev.c: revision 1.46 sys/opencrypto/cryptodev.h: revision 1.16 sys/opencrypto/cryptosoft.c: revision 1.24 sys/opencrypto/cryptosoft.h: revision 1.6 sys/opencrypto/deflate.h: revision 1.6 sys/opencrypto/cryptosoft_xform.c: revision 1.12 sys/opencrypto/deflate.c: revision 1.13 sys/opencrypto/files.opencrypto: revision 1.20 sys/opencrypto/ocryptodev.c: revision 1.1 sys/opencrypto/ocryptodev.h: revision 1.1 sys/opencrypto/xform.c: revision 1.18 sys/opencrypto/xform.h: revision 1.10 Fixes PR kern/41069 and PR kern/41070. Extends the Opencrypto API to allow the destination buffer size to be specified when its not the same size as the input buffer (i.e. for operations like compress and decompress). The crypto_op and crypt_n_op structures gain a u_int dst_len field. The session_op structure gains a comp_alg field to specify a compression algorithm. Moved four ioctls to new ids; CIOCGSESSION, CIOCNGSESSION, CIOCCRYPT, and CIOCNCRYPTM. Added four backward compatible ioctls; OCIOCGSESSION, OCIOCNGSESSION, OCIOCCRYPT, and OCIOCNCRYPTM. Backward compatibility is maintained in ocryptodev.h and ocryptodev.c which implement the original ioctls and set dst_len and comp_alg to 0. Adds user-space access to compression features. Adds software gzip support (CRYPTO_GZIP_COMP). Adds the fast version of crc32 from zlib to libkern. This should be generally useful and provide a place to start normalizing the various crc32 routines in the kernel. The crc32 routine is used in this patch to support GZIP. With input and support from tls@@NetBSD.org. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.11 2008/05/05 13:41:30 ad Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.11 2008/05/05 13:41:30 ad Exp $"); a48 1 a87 2 DPRINTF(("deflate_global: size %d\n", size)); a206 260 /* * Initial version will perform a single gzip encapsulation, * filling in the header, * and appending the crc and uncompressed length. * * Later version will support multiple buffers with * a flag indication final buffer. The crc is maintained * over all buffers and appended to the output along with * the uncompressed length after the final data buffer * has been compressed and output. * * Ditto for uncompress - CRC is extracted from the final packed * and compared against CRC of uncompressed data. * */ /* constant header for the gzip */ static const char gzip_header[10] = { 0x1f, 0x8b, /* ID1 ID2 */ Z_DEFLATED, /* CM */ 0, /* FLG */ 0, 0, 0, 0, /* MTIME */ 0, /* XFL */ 0x03 /* OS (Unix) */ }; /* Followed by compressed payload */ /* Followed by uint32_t CRC32 and uint32_t ISIZE */ #define GZIP_TAIL_SIZE 8 u_int32_t gzip_global(u_int8_t *data, u_int32_t size, int decomp, u_int8_t **out) { /* decomp indicates whether we compress (0) or decompress (1) */ z_stream zbuf; u_int8_t *output; u_int32_t count, result; int error, i = 0, j; struct deflate_buf *buf, *tmp; size_t nbufs, old_nbufs; u_int32_t crc; u_int32_t isize; DPRINTF(("gzip_global: decomp %d, size %d\n", decomp, size)); nbufs = ZBUF; buf = malloc(nbufs*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (buf == NULL) { DPRINTF(("gzip_global.%d: failed to malloc %d\n", __LINE__, nbufs*sizeof(struct deflate_buf))); return 0; } memset(&zbuf, 0, sizeof(z_stream)); for (j = 0; j < nbufs; j++) buf[j].flag = 0; zbuf.zalloc = ocf_zalloc; zbuf.zfree = ocf_zfree; zbuf.opaque = Z_NULL; crc = crc32(0, NULL, 0); /* get initial crc value */ zbuf.avail_in = size; /* Total length of data to be processed */ zbuf.next_in = data; /* data that is going to be processed */ if (!decomp) { /* compress */ DPRINTF(("gzip_global: compress[%d] malloc %d + %d + %d = %d\n", i, size, sizeof(gzip_header), GZIP_TAIL_SIZE, size + sizeof(gzip_header) + GZIP_TAIL_SIZE)); buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad2; buf[i].size = size; buf[i].flag = 1; zbuf.next_out = buf[i].out; zbuf.avail_out = buf[i].size; i++; crc = crc32(crc, data, size); DPRINTF(("gzip_compress: size %d, crc 0x%x\n", size, crc)); } else { /* decompress */ /* check the gzip header */ if (zbuf.avail_in <= 0) { /* Not enough data for the header & tail */ DPRINTF(("gzip_global: not enough data (%d)\n", size)); goto bad2; } /* XXX this is pretty basic, * needs to be expanded to ignore MTIME, OS, * but still ensure flags are 0. * Q. Do we need to support the flags and * optional header fields? Likely. * XXX add flag and field support too. */ if (memcmp(data, gzip_header, sizeof(gzip_header)) != 0) { DPRINTF(("gzip_global: unsupported gzip header (%02x%02x)\n", data[0], data[1])); goto bad2; } else { DPRINTF(("gzip_global.%d: gzip header ok\n",__LINE__)); } isize = *((uint32_t *)&data[size-sizeof(uint32_t)]); DPRINTF(("gzip_global: isize = %d (%02x %02x %02x %02x)\n", isize, data[size-4], data[size-3], data[size-2], data[size-1])); buf[i].size = isize; buf[i].out = malloc(buf[i].size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad2; buf[i].flag = 1; zbuf.next_out = buf[i].out; zbuf.avail_out = buf[i].size; i++; /* skip over the gzip header */ zbuf.next_in = data + sizeof(gzip_header); /* actual payload size stripped of gzip header and tail */ zbuf.avail_in = size - sizeof(gzip_header) - GZIP_TAIL_SIZE; DPRINTF(("zbuf avail_in %d, avail_out %d\n", zbuf.avail_in, zbuf.avail_out)); } error = decomp ? inflateInit2(&zbuf, window_inflate) : deflateInit2(&zbuf, Z_DEFAULT_COMPRESSION, Z_METHOD, window_deflate, Z_MEMLEVEL, Z_DEFAULT_STRATEGY); if (error != Z_OK) { printf("deflateInit2() failed\n"); goto bad; } for (;;) { DPRINTF(("pre: %s in:%d out:%d\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out)); error = decomp ? inflate(&zbuf, Z_PARTIAL_FLUSH) : deflate(&zbuf, Z_PARTIAL_FLUSH); DPRINTF(("post: %s in:%d out:%d\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out)); if (error != Z_OK && error != Z_STREAM_END) { printf("deflate() or inflate() failed, error=%d\n", error); goto bad; } else if (zbuf.avail_in == 0 && zbuf.avail_out != 0) { DPRINTF(("gzip_global: avail_in == 0, ending\n")); goto end; } else if (zbuf.avail_in == 0 && zbuf.avail_out == 0) { DPRINTF(("gzip_global: avail_in == 0, avail_out == 0, ending\n")); goto end; } else if (zbuf.avail_out == 0) { if (i == (nbufs-1)) { old_nbufs = i; nbufs += ZBUF; tmp = realloc(buf,nbufs*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (tmp == NULL) goto bad; buf = tmp; for (j = old_nbufs; j < nbufs; j++) buf[j].flag = 0; } /* we need more output space, allocate size */ buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad; zbuf.next_out = buf[i].out; buf[i].size = size; buf[i].flag = 1; zbuf.avail_out = buf[i].size; i++; } else goto bad; } end: if (decomp) { count = result = zbuf.total_out; } else { /* need room for header, CRC, and ISIZE */ result = zbuf.total_out + sizeof(gzip_header) + GZIP_TAIL_SIZE; count = zbuf.total_out; } DPRINTF(("gzip_global: in %d -> out %d\n", size, result)); *out = malloc(result, M_CRYPTO_DATA, M_NOWAIT); if (*out == NULL) goto bad; output = *out; if (decomp) inflateEnd(&zbuf); else { deflateEnd(&zbuf); /* fill in gzip header */ memcpy(output, gzip_header, sizeof(gzip_header)); output += sizeof(gzip_header); } for (j = 0; buf[j].flag != 0; j++) { if (decomp) { /* update crc for decompressed data */ crc = crc32(crc, buf[j].out, buf[j].size); } if (count > buf[j].size) { memcpy(output, buf[j].out, buf[j].size); output += buf[j].size; free(buf[j].out, M_CRYPTO_DATA); count -= buf[j].size; } else { /* it should be the last buffer */ memcpy(output, buf[j].out, count); output += count; free(buf[j].out, M_CRYPTO_DATA); count = 0; } } free(buf, M_CRYPTO_DATA); if (!decomp) { /* fill in CRC and ISIZE */ ((uint32_t *)output)[0] = crc; ((uint32_t *)output)[1] = size; DPRINTF(("gzip_global: size = 0x%x (%02x %02x %02x %02x)\n", size, output[7], output[3], output[5], output[4])); } return result; bad: if (decomp) inflateEnd(&zbuf); else deflateEnd(&zbuf); bad2: *out = NULL; for (j = 0; buf[j].flag != 0; j++) free(buf[j].out, M_CRYPTO_DATA); free(buf, M_CRYPTO_DATA); return 0; } @ 1.11.8.1 log @Sync with HEAD. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.13 2009/03/25 01:26:13 darran Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.13 2009/03/25 01:26:13 darran Exp $"); a48 1 d73 5 a77 1 deflate_global(u_int8_t *data, u_int32_t size, int decomp, u_int8_t **out) a87 2 DPRINTF(("deflate_global: size %d\n", size)); a206 260 /* * Initial version will perform a single gzip encapsulation, * filling in the header, * and appending the crc and uncompressed length. * * Later version will support multiple buffers with * a flag indication final buffer. The crc is maintained * over all buffers and appended to the output along with * the uncompressed length after the final data buffer * has been compressed and output. * * Ditto for uncompress - CRC is extracted from the final packed * and compared against CRC of uncompressed data. * */ /* constant header for the gzip */ static const char gzip_header[10] = { 0x1f, 0x8b, /* ID1 ID2 */ Z_DEFLATED, /* CM */ 0, /* FLG */ 0, 0, 0, 0, /* MTIME */ 0, /* XFL */ 0x03 /* OS (Unix) */ }; /* Followed by compressed payload */ /* Followed by uint32_t CRC32 and uint32_t ISIZE */ #define GZIP_TAIL_SIZE 8 u_int32_t gzip_global(u_int8_t *data, u_int32_t size, int decomp, u_int8_t **out) { /* decomp indicates whether we compress (0) or decompress (1) */ z_stream zbuf; u_int8_t *output; u_int32_t count, result; int error, i = 0, j; struct deflate_buf *buf, *tmp; size_t nbufs, old_nbufs; u_int32_t crc; u_int32_t isize; DPRINTF(("gzip_global: decomp %d, size %d\n", decomp, size)); nbufs = ZBUF; buf = malloc(nbufs*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (buf == NULL) { DPRINTF(("gzip_global.%d: failed to malloc %d\n", __LINE__, nbufs*sizeof(struct deflate_buf))); return 0; } memset(&zbuf, 0, sizeof(z_stream)); for (j = 0; j < nbufs; j++) buf[j].flag = 0; zbuf.zalloc = ocf_zalloc; zbuf.zfree = ocf_zfree; zbuf.opaque = Z_NULL; crc = crc32(0, NULL, 0); /* get initial crc value */ zbuf.avail_in = size; /* Total length of data to be processed */ zbuf.next_in = data; /* data that is going to be processed */ if (!decomp) { /* compress */ DPRINTF(("gzip_global: compress[%d] malloc %d + %d + %d = %d\n", i, size, sizeof(gzip_header), GZIP_TAIL_SIZE, size + sizeof(gzip_header) + GZIP_TAIL_SIZE)); buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad2; buf[i].size = size; buf[i].flag = 1; zbuf.next_out = buf[i].out; zbuf.avail_out = buf[i].size; i++; crc = crc32(crc, data, size); DPRINTF(("gzip_compress: size %d, crc 0x%x\n", size, crc)); } else { /* decompress */ /* check the gzip header */ if (zbuf.avail_in <= 0) { /* Not enough data for the header & tail */ DPRINTF(("gzip_global: not enough data (%d)\n", size)); goto bad2; } /* XXX this is pretty basic, * needs to be expanded to ignore MTIME, OS, * but still ensure flags are 0. * Q. Do we need to support the flags and * optional header fields? Likely. * XXX add flag and field support too. */ if (memcmp(data, gzip_header, sizeof(gzip_header)) != 0) { DPRINTF(("gzip_global: unsupported gzip header (%02x%02x)\n", data[0], data[1])); goto bad2; } else { DPRINTF(("gzip_global.%d: gzip header ok\n",__LINE__)); } isize = *((uint32_t *)&data[size-sizeof(uint32_t)]); DPRINTF(("gzip_global: isize = %d (%02x %02x %02x %02x)\n", isize, data[size-4], data[size-3], data[size-2], data[size-1])); buf[i].size = isize; buf[i].out = malloc(buf[i].size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad2; buf[i].flag = 1; zbuf.next_out = buf[i].out; zbuf.avail_out = buf[i].size; i++; /* skip over the gzip header */ zbuf.next_in = data + sizeof(gzip_header); /* actual payload size stripped of gzip header and tail */ zbuf.avail_in = size - sizeof(gzip_header) - GZIP_TAIL_SIZE; DPRINTF(("zbuf avail_in %d, avail_out %d\n", zbuf.avail_in, zbuf.avail_out)); } error = decomp ? inflateInit2(&zbuf, window_inflate) : deflateInit2(&zbuf, Z_DEFAULT_COMPRESSION, Z_METHOD, window_deflate, Z_MEMLEVEL, Z_DEFAULT_STRATEGY); if (error != Z_OK) { printf("deflateInit2() failed\n"); goto bad; } for (;;) { DPRINTF(("pre: %s in:%d out:%d\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out)); error = decomp ? inflate(&zbuf, Z_PARTIAL_FLUSH) : deflate(&zbuf, Z_PARTIAL_FLUSH); DPRINTF(("post: %s in:%d out:%d\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out)); if (error != Z_OK && error != Z_STREAM_END) { printf("deflate() or inflate() failed, error=%d\n", error); goto bad; } else if (zbuf.avail_in == 0 && zbuf.avail_out != 0) { DPRINTF(("gzip_global: avail_in == 0, ending\n")); goto end; } else if (zbuf.avail_in == 0 && zbuf.avail_out == 0) { DPRINTF(("gzip_global: avail_in == 0, avail_out == 0, ending\n")); goto end; } else if (zbuf.avail_out == 0) { if (i == (nbufs-1)) { old_nbufs = i; nbufs += ZBUF; tmp = realloc(buf,nbufs*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (tmp == NULL) goto bad; buf = tmp; for (j = old_nbufs; j < nbufs; j++) buf[j].flag = 0; } /* we need more output space, allocate size */ buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad; zbuf.next_out = buf[i].out; buf[i].size = size; buf[i].flag = 1; zbuf.avail_out = buf[i].size; i++; } else goto bad; } end: if (decomp) { count = result = zbuf.total_out; } else { /* need room for header, CRC, and ISIZE */ result = zbuf.total_out + sizeof(gzip_header) + GZIP_TAIL_SIZE; count = zbuf.total_out; } DPRINTF(("gzip_global: in %d -> out %d\n", size, result)); *out = malloc(result, M_CRYPTO_DATA, M_NOWAIT); if (*out == NULL) goto bad; output = *out; if (decomp) inflateEnd(&zbuf); else { deflateEnd(&zbuf); /* fill in gzip header */ memcpy(output, gzip_header, sizeof(gzip_header)); output += sizeof(gzip_header); } for (j = 0; buf[j].flag != 0; j++) { if (decomp) { /* update crc for decompressed data */ crc = crc32(crc, buf[j].out, buf[j].size); } if (count > buf[j].size) { memcpy(output, buf[j].out, buf[j].size); output += buf[j].size; free(buf[j].out, M_CRYPTO_DATA); count -= buf[j].size; } else { /* it should be the last buffer */ memcpy(output, buf[j].out, count); output += count; free(buf[j].out, M_CRYPTO_DATA); count = 0; } } free(buf, M_CRYPTO_DATA); if (!decomp) { /* fill in CRC and ISIZE */ ((uint32_t *)output)[0] = crc; ((uint32_t *)output)[1] = size; DPRINTF(("gzip_global: size = 0x%x (%02x %02x %02x %02x)\n", size, output[7], output[3], output[5], output[4])); } return result; bad: if (decomp) inflateEnd(&zbuf); else deflateEnd(&zbuf); bad2: *out = NULL; for (j = 0; buf[j].flag != 0; j++) free(buf[j].out, M_CRYPTO_DATA); free(buf, M_CRYPTO_DATA); return 0; } @ 1.10 log @Move zlib out of net/ and into kern/. It would probably be better to use the reachover Makefiles and libz, but this is already here and it works. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.9 2007/09/22 23:38:17 degroote Exp $ */ d34 1 a34 1 * functions using the zlib library (see sys/zlib.{c,h}) d44 1 a44 1 #include @ 1.9 log @Fix a stupid bogus bcopy -> memcpy conversion. I will write it 1000 times : when I convert bcopy to memcpy, don't forget to swap first and secund args. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.8 2007/05/21 11:35:16 degroote Exp $ */ d34 1 a34 1 * functions using the zlib library (see net/zlib.{c,h}) d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.8 2007/05/21 11:35:16 degroote Exp $"); d44 1 a44 1 #include @ 1.9.24.1 log @sync with head. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.9 2007/09/22 23:38:17 degroote Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.9 2007/09/22 23:38:17 degroote Exp $"); a48 1 d73 5 a77 1 deflate_global(u_int8_t *data, u_int32_t size, int decomp, u_int8_t **out) a87 2 DPRINTF(("deflate_global: size %d\n", size)); a206 260 /* * Initial version will perform a single gzip encapsulation, * filling in the header, * and appending the crc and uncompressed length. * * Later version will support multiple buffers with * a flag indication final buffer. The crc is maintained * over all buffers and appended to the output along with * the uncompressed length after the final data buffer * has been compressed and output. * * Ditto for uncompress - CRC is extracted from the final packed * and compared against CRC of uncompressed data. * */ /* constant header for the gzip */ static const char gzip_header[10] = { 0x1f, 0x8b, /* ID1 ID2 */ Z_DEFLATED, /* CM */ 0, /* FLG */ 0, 0, 0, 0, /* MTIME */ 0, /* XFL */ 0x03 /* OS (Unix) */ }; /* Followed by compressed payload */ /* Followed by uint32_t CRC32 and uint32_t ISIZE */ #define GZIP_TAIL_SIZE 8 u_int32_t gzip_global(u_int8_t *data, u_int32_t size, int decomp, u_int8_t **out) { /* decomp indicates whether we compress (0) or decompress (1) */ z_stream zbuf; u_int8_t *output; u_int32_t count, result; int error, i = 0, j; struct deflate_buf *buf, *tmp; size_t nbufs, old_nbufs; u_int32_t crc; u_int32_t isize; DPRINTF(("gzip_global: decomp %d, size %d\n", decomp, size)); nbufs = ZBUF; buf = malloc(nbufs*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (buf == NULL) { DPRINTF(("gzip_global.%d: failed to malloc %d\n", __LINE__, nbufs*sizeof(struct deflate_buf))); return 0; } memset(&zbuf, 0, sizeof(z_stream)); for (j = 0; j < nbufs; j++) buf[j].flag = 0; zbuf.zalloc = ocf_zalloc; zbuf.zfree = ocf_zfree; zbuf.opaque = Z_NULL; crc = crc32(0, NULL, 0); /* get initial crc value */ zbuf.avail_in = size; /* Total length of data to be processed */ zbuf.next_in = data; /* data that is going to be processed */ if (!decomp) { /* compress */ DPRINTF(("gzip_global: compress[%d] malloc %d + %d + %d = %d\n", i, size, sizeof(gzip_header), GZIP_TAIL_SIZE, size + sizeof(gzip_header) + GZIP_TAIL_SIZE)); buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad2; buf[i].size = size; buf[i].flag = 1; zbuf.next_out = buf[i].out; zbuf.avail_out = buf[i].size; i++; crc = crc32(crc, data, size); DPRINTF(("gzip_compress: size %d, crc 0x%x\n", size, crc)); } else { /* decompress */ /* check the gzip header */ if (zbuf.avail_in <= 0) { /* Not enough data for the header & tail */ DPRINTF(("gzip_global: not enough data (%d)\n", size)); goto bad2; } /* XXX this is pretty basic, * needs to be expanded to ignore MTIME, OS, * but still ensure flags are 0. * Q. Do we need to support the flags and * optional header fields? Likely. * XXX add flag and field support too. */ if (memcmp(data, gzip_header, sizeof(gzip_header)) != 0) { DPRINTF(("gzip_global: unsupported gzip header (%02x%02x)\n", data[0], data[1])); goto bad2; } else { DPRINTF(("gzip_global.%d: gzip header ok\n",__LINE__)); } isize = *((uint32_t *)&data[size-sizeof(uint32_t)]); DPRINTF(("gzip_global: isize = %d (%02x %02x %02x %02x)\n", isize, data[size-4], data[size-3], data[size-2], data[size-1])); buf[i].size = isize; buf[i].out = malloc(buf[i].size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad2; buf[i].flag = 1; zbuf.next_out = buf[i].out; zbuf.avail_out = buf[i].size; i++; /* skip over the gzip header */ zbuf.next_in = data + sizeof(gzip_header); /* actual payload size stripped of gzip header and tail */ zbuf.avail_in = size - sizeof(gzip_header) - GZIP_TAIL_SIZE; DPRINTF(("zbuf avail_in %d, avail_out %d\n", zbuf.avail_in, zbuf.avail_out)); } error = decomp ? inflateInit2(&zbuf, window_inflate) : deflateInit2(&zbuf, Z_DEFAULT_COMPRESSION, Z_METHOD, window_deflate, Z_MEMLEVEL, Z_DEFAULT_STRATEGY); if (error != Z_OK) { printf("deflateInit2() failed\n"); goto bad; } for (;;) { DPRINTF(("pre: %s in:%d out:%d\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out)); error = decomp ? inflate(&zbuf, Z_PARTIAL_FLUSH) : deflate(&zbuf, Z_PARTIAL_FLUSH); DPRINTF(("post: %s in:%d out:%d\n", decomp ? "deflate()" : "inflate()", zbuf.avail_in, zbuf.avail_out)); if (error != Z_OK && error != Z_STREAM_END) { printf("deflate() or inflate() failed, error=%d\n", error); goto bad; } else if (zbuf.avail_in == 0 && zbuf.avail_out != 0) { DPRINTF(("gzip_global: avail_in == 0, ending\n")); goto end; } else if (zbuf.avail_in == 0 && zbuf.avail_out == 0) { DPRINTF(("gzip_global: avail_in == 0, avail_out == 0, ending\n")); goto end; } else if (zbuf.avail_out == 0) { if (i == (nbufs-1)) { old_nbufs = i; nbufs += ZBUF; tmp = realloc(buf,nbufs*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (tmp == NULL) goto bad; buf = tmp; for (j = old_nbufs; j < nbufs; j++) buf[j].flag = 0; } /* we need more output space, allocate size */ buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad; zbuf.next_out = buf[i].out; buf[i].size = size; buf[i].flag = 1; zbuf.avail_out = buf[i].size; i++; } else goto bad; } end: if (decomp) { count = result = zbuf.total_out; } else { /* need room for header, CRC, and ISIZE */ result = zbuf.total_out + sizeof(gzip_header) + GZIP_TAIL_SIZE; count = zbuf.total_out; } DPRINTF(("gzip_global: in %d -> out %d\n", size, result)); *out = malloc(result, M_CRYPTO_DATA, M_NOWAIT); if (*out == NULL) goto bad; output = *out; if (decomp) inflateEnd(&zbuf); else { deflateEnd(&zbuf); /* fill in gzip header */ memcpy(output, gzip_header, sizeof(gzip_header)); output += sizeof(gzip_header); } for (j = 0; buf[j].flag != 0; j++) { if (decomp) { /* update crc for decompressed data */ crc = crc32(crc, buf[j].out, buf[j].size); } if (count > buf[j].size) { memcpy(output, buf[j].out, buf[j].size); output += buf[j].size; free(buf[j].out, M_CRYPTO_DATA); count -= buf[j].size; } else { /* it should be the last buffer */ memcpy(output, buf[j].out, count); output += count; free(buf[j].out, M_CRYPTO_DATA); count = 0; } } free(buf, M_CRYPTO_DATA); if (!decomp) { /* fill in CRC and ISIZE */ ((uint32_t *)output)[0] = crc; ((uint32_t *)output)[1] = size; DPRINTF(("gzip_global: size = 0x%x (%02x %02x %02x %02x)\n", size, output[7], output[3], output[5], output[4])); } return result; bad: if (decomp) inflateEnd(&zbuf); else deflateEnd(&zbuf); bad2: *out = NULL; for (j = 0; buf[j].flag != 0; j++) free(buf[j].out, M_CRYPTO_DATA); free(buf, M_CRYPTO_DATA); return 0; } @ 1.8 log @Use dynamic array instead of an static array to decompress. It lets us to decompress any data, whatever is the radio decompressed data / compressed data. It fixes the last issues with fast_ipsec and ipcomp. While here, bzero -> memset, bcopy -> memcpy, FREE -> free Reviewed a long time ago by sam@@ @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.7 2006/11/16 01:33:51 christos Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.7 2006/11/16 01:33:51 christos Exp $"); d180 1 a180 1 memcpy(buf[j].out, *out, buf[j].size); d186 1 a186 1 memcpy(buf[j].out, *out, count); @ 1.8.8.1 log @sync with HEAD @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.9 2007/09/22 23:38:17 degroote Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.9 2007/09/22 23:38:17 degroote Exp $"); d180 1 a180 1 memcpy(*out, buf[j].out, buf[j].size); d186 1 a186 1 memcpy(*out, buf[j].out, count); @ 1.8.6.1 log @Sync with HEAD. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.9 2007/09/22 23:38:17 degroote Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.9 2007/09/22 23:38:17 degroote Exp $"); d180 1 a180 1 memcpy(*out, buf[j].out, buf[j].size); d186 1 a186 1 memcpy(*out, buf[j].out, count); @ 1.7 log @__unused removal on arguments; approved by core. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.6 2006/10/12 01:32:47 christos Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.6 2006/10/12 01:32:47 christos Exp $"); d85 2 a86 1 struct deflate_buf buf[ZBUF]; d88 7 a94 2 bzero(&zbuf, sizeof(z_stream)); for (j = 0; j < ZBUF; j++) d142 12 a153 1 else if (zbuf.avail_out == 0 && i < (ZBUF - 1)) { d180 1 a180 1 bcopy(buf[j].out, *out, buf[j].size); d182 1 a182 1 FREE(buf[j].out, M_CRYPTO_DATA); d186 1 a186 1 bcopy(buf[j].out, *out, count); d188 1 a188 1 FREE(buf[j].out, M_CRYPTO_DATA); d192 1 d199 2 a200 1 FREE(buf[j].out, M_CRYPTO_DATA); @ 1.7.10.1 log @Sync with head. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.8 2007/05/21 11:35:16 degroote Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.8 2007/05/21 11:35:16 degroote Exp $"); d85 1 a85 2 struct deflate_buf *buf, *tmp; size_t len, old_len; d87 2 a88 7 len = ZBUF; buf = malloc(len*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (buf == NULL) return 0; memset(&zbuf, 0, sizeof(z_stream)); for (j = 0; j < len; j++) d136 1 a136 12 else if (zbuf.avail_out == 0) { if (i == (len-1)) { old_len = i; len += ZBUF; tmp = realloc(buf,len*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (tmp == NULL) goto bad; buf = tmp; for (j = old_len; j < len; j++) buf[j].flag = 0; } d163 1 a163 1 memcpy(buf[j].out, *out, buf[j].size); d165 1 a165 1 free(buf[j].out, M_CRYPTO_DATA); d169 1 a169 1 memcpy(buf[j].out, *out, count); d171 1 a171 1 free(buf[j].out, M_CRYPTO_DATA); a174 1 free(buf, M_CRYPTO_DATA); d181 1 a181 2 free(buf[j].out, M_CRYPTO_DATA); free(buf, M_CRYPTO_DATA); @ 1.7.8.1 log @Sync with head. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.7 2006/11/16 01:33:51 christos Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.7 2006/11/16 01:33:51 christos Exp $"); d85 1 a85 2 struct deflate_buf *buf, *tmp; size_t len, old_len; d87 2 a88 7 len = ZBUF; buf = malloc(len*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (buf == NULL) return 0; memset(&zbuf, 0, sizeof(z_stream)); for (j = 0; j < len; j++) d136 1 a136 12 else if (zbuf.avail_out == 0) { if (i == (len-1)) { old_len = i; len += ZBUF; tmp = realloc(buf,len*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (tmp == NULL) goto bad; buf = tmp; for (j = old_len; j < len; j++) buf[j].flag = 0; } d163 1 a163 1 memcpy(buf[j].out, *out, buf[j].size); d165 1 a165 1 free(buf[j].out, M_CRYPTO_DATA); d169 1 a169 1 memcpy(buf[j].out, *out, count); d171 1 a171 1 free(buf[j].out, M_CRYPTO_DATA); a174 1 free(buf, M_CRYPTO_DATA); d181 1 a181 2 free(buf[j].out, M_CRYPTO_DATA); free(buf, M_CRYPTO_DATA); @ 1.7.8.2 log @Sync with head. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.7.8.1 2007/06/08 14:18:08 ad Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.7.8.1 2007/06/08 14:18:08 ad Exp $"); d180 1 a180 1 memcpy(*out, buf[j].out, buf[j].size); d186 1 a186 1 memcpy(*out, buf[j].out, count); @ 1.7.16.1 log @Update to today's netbsd-4. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.7.2.1 2007/05/24 19:13:17 pavel Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.7.2.1 2007/05/24 19:13:17 pavel Exp $"); d85 1 a85 2 struct deflate_buf *buf, *tmp; size_t len, old_len; d87 2 a88 7 len = ZBUF; buf = malloc(len*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (buf == NULL) return 0; memset(&zbuf, 0, sizeof(z_stream)); for (j = 0; j < len; j++) d136 1 a136 12 else if (zbuf.avail_out == 0) { if (i == (len-1)) { old_len = i; len += ZBUF; tmp = realloc(buf,len*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (tmp == NULL) goto bad; buf = tmp; for (j = old_len; j < len; j++) buf[j].flag = 0; } d163 1 a163 1 memcpy(buf[j].out, *out, buf[j].size); d165 1 a165 1 free(buf[j].out, M_CRYPTO_DATA); d169 1 a169 1 memcpy(buf[j].out, *out, count); d171 1 a171 1 free(buf[j].out, M_CRYPTO_DATA); a174 1 free(buf, M_CRYPTO_DATA); d181 1 a181 2 free(buf[j].out, M_CRYPTO_DATA); free(buf, M_CRYPTO_DATA); @ 1.7.16.2 log @Catch up on netbsd-4 as of a few days ago. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.7.16.1 2007/06/04 01:54:28 wrstuden Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.7.16.1 2007/06/04 01:54:28 wrstuden Exp $"); d180 1 a180 1 memcpy(*out, buf[j].out, buf[j].size); d186 1 a186 1 memcpy(*out, buf[j].out, count); @ 1.7.2.1 log @Pull up following revision(s) (requested by degroote in ticket #667): sys/netinet/tcp_input.c: revision 1.260 sys/netinet/tcp_output.c: revision 1.154 sys/netinet/tcp_subr.c: revision 1.210 sys/netinet6/icmp6.c: revision 1.129 sys/netinet6/in6_proto.c: revision 1.70 sys/netinet6/ip6_forward.c: revision 1.54 sys/netinet6/ip6_input.c: revision 1.94 sys/netinet6/ip6_output.c: revision 1.114 sys/netinet6/raw_ip6.c: revision 1.81 sys/netipsec/ipcomp_var.h: revision 1.4 sys/netipsec/ipsec.c: revision 1.26 via patch,1.31-1.32 sys/netipsec/ipsec6.h: revision 1.5 sys/netipsec/ipsec_input.c: revision 1.14 sys/netipsec/ipsec_netbsd.c: revision 1.18,1.26 sys/netipsec/ipsec_output.c: revision 1.21 via patch sys/netipsec/key.c: revision 1.33,1.44 sys/netipsec/xform_ipcomp.c: revision 1.9 sys/netipsec/xform_ipip.c: revision 1.15 sys/opencrypto/deflate.c: revision 1.8 Commit my SoC work Add ipv6 support for fast_ipsec Note that currently, packet with extensions headers are not correctly supported Change the ipcomp logic Add sysctl tree to modify the fast_ipsec options related to ipv6. Similar to the sysctl kame interface. Choose the good default policy, depending of the adress family of the desired policy Increase the refcount for the default ipv6 policy so nobody can reclaim it Always compute the sp index even if we don't have any sp in spd. It will let us to choose the right default policy (based on the adress family requested). While here, fix an error message Use dynamic array instead of an static array to decompress. It lets us to decompress any data, whatever is the radio decompressed data / compressed data. It fixes the last issues with fast_ipsec and ipcomp. While here, bzero -> memset, bcopy -> memcpy, FREE -> free Reviewed a long time ago by sam@@ @ text @d1 1 a1 1 /* $NetBSD$ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD$"); d85 1 a85 2 struct deflate_buf *buf, *tmp; size_t len, old_len; d87 2 a88 7 len = ZBUF; buf = malloc(len*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (buf == NULL) return 0; memset(&zbuf, 0, sizeof(z_stream)); for (j = 0; j < len; j++) d136 1 a136 12 else if (zbuf.avail_out == 0) { if (i == (len-1)) { old_len = i; len += ZBUF; tmp = realloc(buf,len*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (tmp == NULL) goto bad; buf = tmp; for (j = old_len; j < len; j++) buf[j].flag = 0; } d163 1 a163 1 memcpy(buf[j].out, *out, buf[j].size); d165 1 a165 1 free(buf[j].out, M_CRYPTO_DATA); d169 1 a169 1 memcpy(buf[j].out, *out, count); d171 1 a171 1 free(buf[j].out, M_CRYPTO_DATA); a174 1 free(buf, M_CRYPTO_DATA); d181 1 a181 2 free(buf[j].out, M_CRYPTO_DATA); free(buf, M_CRYPTO_DATA); @ 1.7.2.2 log @Pull up following revision(s) (requested by degroote in ticket #897): sys/opencrypto/deflate.c: revision 1.9 Fix a stupid bogus bcopy -> memcpy conversion. I will write it 1000 times : when I convert bcopy to memcpy, don't forget to swap first and secund args. @ text @d180 1 a180 1 memcpy(*out, buf[j].out, buf[j].size); d186 1 a186 1 memcpy(*out, buf[j].out, count); @ 1.6 log @- sprinkle __unused on function decls. - fix a couple of unused bugs - no more -Wno-unused for i386 @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.5 2006/03/17 23:29:11 christos Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.5 2006/03/17 23:29:11 christos Exp $"); d58 1 a58 1 ocf_zalloc(void *nil __unused, u_int type, u_int size) d67 1 a67 1 ocf_zfree(void *nil __unused, void *ptr) @ 1.5 log @don't use MALLOC with a non-constant size; use malloc instead. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.4 2005/12/11 12:25:20 christos Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.4 2005/12/11 12:25:20 christos Exp $"); d58 1 a58 1 ocf_zalloc(void *nil, u_int type, u_int size) d67 1 a67 1 ocf_zfree(void *nil, void *ptr) @ 1.5.8.1 log @Sync with head. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.7 2006/11/16 01:33:51 christos Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.7 2006/11/16 01:33:51 christos Exp $"); @ 1.5.10.1 log @sync with head @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.5 2006/03/17 23:29:11 christos Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.5 2006/03/17 23:29:11 christos Exp $"); d58 1 a58 1 ocf_zalloc(void *nil __unused, u_int type, u_int size) d67 1 a67 1 ocf_zfree(void *nil __unused, void *ptr) @ 1.5.10.2 log @sync with head. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.5.10.1 2006/10/22 06:07:47 yamt Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.5.10.1 2006/10/22 06:07:47 yamt Exp $"); d58 1 a58 1 ocf_zalloc(void *nil, u_int type, u_int size) d67 1 a67 1 ocf_zfree(void *nil, void *ptr) @ 1.4 log @merge ktrace-lwp. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.2.4.4 2005/03/04 16:54:22 skrll Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.2.4.4 2005/03/04 16:54:22 skrll Exp $"); d98 1 a98 2 MALLOC(buf[i].out, u_int8_t *, (u_long) size, M_CRYPTO_DATA, M_NOWAIT); d112 2 a113 2 MALLOC(buf[i].out, u_int8_t *, (u_long) (size * 4), M_CRYPTO_DATA, M_NOWAIT); a115 1 buf[i].size = size * 4; d138 1 a138 2 MALLOC(buf[i].out, u_int8_t *, (u_long) size, M_CRYPTO_DATA, M_NOWAIT); d153 1 a153 1 MALLOC(*out, u_int8_t *, (u_long) result, M_CRYPTO_DATA, M_NOWAIT); @ 1.4.4.1 log @sync with head @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.5 2006/03/17 23:29:11 christos Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.5 2006/03/17 23:29:11 christos Exp $"); d98 2 a99 1 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); d113 2 a114 2 buf[i].size = size * 4; buf[i].out = malloc(buf[i].size, M_CRYPTO_DATA, M_NOWAIT); d117 1 d140 2 a141 1 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); d156 1 a156 1 *out = malloc(result, M_CRYPTO_DATA, M_NOWAIT); @ 1.4.6.1 log @Sync with head. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.5 2006/03/17 23:29:11 christos Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.5 2006/03/17 23:29:11 christos Exp $"); d98 2 a99 1 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); d113 2 a114 2 buf[i].size = size * 4; buf[i].out = malloc(buf[i].size, M_CRYPTO_DATA, M_NOWAIT); d117 1 d140 2 a141 1 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); d156 1 a156 1 *out = malloc(result, M_CRYPTO_DATA, M_NOWAIT); @ 1.4.10.1 log @sync with head. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.5 2006/03/17 23:29:11 christos Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.5 2006/03/17 23:29:11 christos Exp $"); d98 2 a99 1 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); d113 2 a114 2 buf[i].size = size * 4; buf[i].out = malloc(buf[i].size, M_CRYPTO_DATA, M_NOWAIT); d117 1 d140 2 a141 1 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); d156 1 a156 1 *out = malloc(result, M_CRYPTO_DATA, M_NOWAIT); @ 1.4.8.1 log @sync with head. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.4 2005/12/11 12:25:20 christos Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.4 2005/12/11 12:25:20 christos Exp $"); d98 2 a99 1 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); d113 2 a114 2 buf[i].size = size * 4; buf[i].out = malloc(buf[i].size, M_CRYPTO_DATA, M_NOWAIT); d117 1 d140 2 a141 1 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); d156 1 a156 1 *out = malloc(result, M_CRYPTO_DATA, M_NOWAIT); @ 1.4.12.1 log @Merge 2006-03-28 NetBSD-current into the "peter-altq" branch. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.5 2006/03/17 23:29:11 christos Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.5 2006/03/17 23:29:11 christos Exp $"); d98 2 a99 1 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); d113 2 a114 2 buf[i].size = size * 4; buf[i].out = malloc(buf[i].size, M_CRYPTO_DATA, M_NOWAIT); d117 1 d140 2 a141 1 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); d156 1 a156 1 *out = malloc(result, M_CRYPTO_DATA, M_NOWAIT); @ 1.3 log @nuke trailing whitespace @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.2 2003/08/27 00:12:37 thorpej Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.2 2003/08/27 00:12:37 thorpej Exp $"); @ 1.3.4.1 log @sync with head. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.3 2005/02/26 22:39:52 perry Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.3 2005/02/26 22:39:52 perry Exp $"); d98 2 a99 1 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); d113 2 a114 2 buf[i].size = size * 4; buf[i].out = malloc(buf[i].size, M_CRYPTO_DATA, M_NOWAIT); d117 1 d140 2 a141 1 buf[i].out = malloc(size, M_CRYPTO_DATA, M_NOWAIT); d156 1 a156 1 *out = malloc(result, M_CRYPTO_DATA, M_NOWAIT); @ 1.3.4.2 log @sync with head. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.3.4.1 2006/06/21 15:12:02 yamt Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.3.4.1 2006/06/21 15:12:02 yamt Exp $"); d85 1 a85 2 struct deflate_buf *buf, *tmp; size_t len, old_len; d87 2 a88 7 len = ZBUF; buf = malloc(len*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (buf == NULL) return 0; memset(&zbuf, 0, sizeof(z_stream)); for (j = 0; j < len; j++) d136 1 a136 12 else if (zbuf.avail_out == 0) { if (i == (len-1)) { old_len = i; len += ZBUF; tmp = realloc(buf,len*sizeof(struct deflate_buf), M_CRYPTO_DATA, M_NOWAIT); if (tmp == NULL) goto bad; buf = tmp; for (j = old_len; j < len; j++) buf[j].flag = 0; } d163 1 a163 1 memcpy(buf[j].out, *out, buf[j].size); d165 1 a165 1 free(buf[j].out, M_CRYPTO_DATA); d169 1 a169 1 memcpy(buf[j].out, *out, count); d171 1 a171 1 free(buf[j].out, M_CRYPTO_DATA); a174 1 free(buf, M_CRYPTO_DATA); d181 1 a181 2 free(buf[j].out, M_CRYPTO_DATA); free(buf, M_CRYPTO_DATA); @ 1.3.4.3 log @sync with head. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.3.4.2 2007/09/03 14:44:24 yamt Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.3.4.2 2007/09/03 14:44:24 yamt Exp $"); d180 1 a180 1 memcpy(*out, buf[j].out, buf[j].size); d186 1 a186 1 memcpy(*out, buf[j].out, count); @ 1.2 log @Tidy up the namespace of this a little. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.1 2003/07/25 21:12:45 jonathan Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.1 2003/07/25 21:12:45 jonathan Exp $"); d98 1 a98 1 MALLOC(buf[i].out, u_int8_t *, (u_long) size, M_CRYPTO_DATA, d113 1 a113 1 MALLOC(buf[i].out, u_int8_t *, (u_long) (size * 4), @ 1.2.4.1 log @file deflate.c was added on branch ktrace-lwp on 2004-08-03 10:56:25 +0000 @ text @d1 190 @ 1.2.4.2 log @Sync with HEAD @ text @a0 190 /* $NetBSD: deflate.c,v 1.2.4.1 2004/08/03 10:56:25 skrll Exp $ */ /* $FreeBSD: src/sys/opencrypto/deflate.c,v 1.1.2.1 2002/11/21 23:34:23 sam Exp $ */ /* $OpenBSD: deflate.c,v 1.3 2001/08/20 02:45:22 hugh Exp $ */ /* * Copyright (c) 2001 Jean-Jacques Bernard-Gundol (jj@@wabbitt.org) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * This file contains a wrapper around the deflate algo compression * functions using the zlib library (see net/zlib.{c,h}) */ #include __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.2.4.1 2004/08/03 10:56:25 skrll Exp $"); #include #include #include #include #include #include #include int window_inflate = -1 * MAX_WBITS; int window_deflate = -12; /* * This function takes a block of data and (de)compress it using the deflate * algorithm */ static void * ocf_zalloc(void *nil, u_int type, u_int size) { void *ptr; ptr = malloc(type *size, M_CRYPTO_DATA, M_NOWAIT); return ptr; } static void ocf_zfree(void *nil, void *ptr) { free(ptr, M_CRYPTO_DATA); } u_int32_t deflate_global(data, size, decomp, out) u_int8_t *data; u_int32_t size; int decomp; u_int8_t **out; { /* decomp indicates whether we compress (0) or decompress (1) */ z_stream zbuf; u_int8_t *output; u_int32_t count, result; int error, i = 0, j; struct deflate_buf buf[ZBUF]; bzero(&zbuf, sizeof(z_stream)); for (j = 0; j < ZBUF; j++) buf[j].flag = 0; zbuf.next_in = data; /* data that is going to be processed */ zbuf.zalloc = ocf_zalloc; zbuf.zfree = ocf_zfree; zbuf.opaque = Z_NULL; zbuf.avail_in = size; /* Total length of data to be processed */ if (!decomp) { MALLOC(buf[i].out, u_int8_t *, (u_long) size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad; buf[i].size = size; buf[i].flag = 1; i++; } else { /* * Choose a buffer with 4x the size of the input buffer * for the size of the output buffer in the case of * decompression. If it's not sufficient, it will need to be * updated while the decompression is going on */ MALLOC(buf[i].out, u_int8_t *, (u_long) (size * 4), M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad; buf[i].size = size * 4; buf[i].flag = 1; i++; } zbuf.next_out = buf[0].out; zbuf.avail_out = buf[0].size; error = decomp ? inflateInit2(&zbuf, window_inflate) : deflateInit2(&zbuf, Z_DEFAULT_COMPRESSION, Z_METHOD, window_deflate, Z_MEMLEVEL, Z_DEFAULT_STRATEGY); if (error != Z_OK) goto bad; for (;;) { error = decomp ? inflate(&zbuf, Z_PARTIAL_FLUSH) : deflate(&zbuf, Z_PARTIAL_FLUSH); if (error != Z_OK && error != Z_STREAM_END) goto bad; else if (zbuf.avail_in == 0 && zbuf.avail_out != 0) goto end; else if (zbuf.avail_out == 0 && i < (ZBUF - 1)) { /* we need more output space, allocate size */ MALLOC(buf[i].out, u_int8_t *, (u_long) size, M_CRYPTO_DATA, M_NOWAIT); if (buf[i].out == NULL) goto bad; zbuf.next_out = buf[i].out; buf[i].size = size; buf[i].flag = 1; zbuf.avail_out = buf[i].size; i++; } else goto bad; } end: result = count = zbuf.total_out; MALLOC(*out, u_int8_t *, (u_long) result, M_CRYPTO_DATA, M_NOWAIT); if (*out == NULL) goto bad; if (decomp) inflateEnd(&zbuf); else deflateEnd(&zbuf); output = *out; for (j = 0; buf[j].flag != 0; j++) { if (count > buf[j].size) { bcopy(buf[j].out, *out, buf[j].size); *out += buf[j].size; FREE(buf[j].out, M_CRYPTO_DATA); count -= buf[j].size; } else { /* it should be the last buffer */ bcopy(buf[j].out, *out, count); *out += count; FREE(buf[j].out, M_CRYPTO_DATA); count = 0; } } *out = output; return result; bad: *out = NULL; for (j = 0; buf[j].flag != 0; j++) FREE(buf[j].out, M_CRYPTO_DATA); if (decomp) inflateEnd(&zbuf); else deflateEnd(&zbuf); return 0; } @ 1.2.4.3 log @Sync with HEAD. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.2.4.2 2004/09/18 14:56:20 skrll Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.2.4.2 2004/09/18 14:56:20 skrll Exp $"); @ 1.2.4.4 log @Fix the sync with head I botched. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.2.4.3 2004/09/21 13:38:44 skrll Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.2.4.3 2004/09/21 13:38:44 skrll Exp $"); @ 1.2.4.5 log @Sync with HEAD. Hi Perry! @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.2.4.4 2005/03/04 16:54:22 skrll Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.2.4.4 2005/03/04 16:54:22 skrll Exp $"); d98 1 a98 1 MALLOC(buf[i].out, u_int8_t *, (u_long) size, M_CRYPTO_DATA, d113 1 a113 1 MALLOC(buf[i].out, u_int8_t *, (u_long) (size * 4), @ 1.2.10.1 log @sync with -current @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.3 2005/02/26 22:39:52 perry Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.3 2005/02/26 22:39:52 perry Exp $"); d98 1 a98 1 MALLOC(buf[i].out, u_int8_t *, (u_long) size, M_CRYPTO_DATA, d113 1 a113 1 MALLOC(buf[i].out, u_int8_t *, (u_long) (size * 4), @ 1.2.12.1 log @sync with head. xen and whitespace. xen part is not finished. @ text @d1 1 a1 1 /* $NetBSD: deflate.c,v 1.2 2003/08/27 00:12:37 thorpej Exp $ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD: deflate.c,v 1.2 2003/08/27 00:12:37 thorpej Exp $"); d98 1 a98 1 MALLOC(buf[i].out, u_int8_t *, (u_long) size, M_CRYPTO_DATA, d113 1 a113 1 MALLOC(buf[i].out, u_int8_t *, (u_long) (size * 4), @ 1.1 log @Commit initial NetBSD port of the OpenCrypto Framework (OCF). This code is derived from Sam Leffler's FreeBSD port of OCF, which is in turn a port of Angelos Keromytis's OpenBSD work. Credit to Sam and Angelos, any blame for the NetBSD port to me. @ text @d1 1 a1 1 /* $NetBSD:$ */ d38 1 a38 1 __KERNEL_RCSID(0, "$NetBSD:$"); d57 15 d92 2 a93 2 zbuf.zalloc = z_alloc; zbuf.zfree = z_free; a189 18 } void * z_alloc(nil, type, size) void *nil; u_int type, size; { void *ptr; ptr = malloc(type *size, M_CRYPTO_DATA, M_NOWAIT); return ptr; } void z_free(nil, ptr) void *nil, *ptr; { free(ptr, M_CRYPTO_DATA); @