diff options
| author | jsing <> | 2014-04-15 16:37:22 +0000 |
|---|---|---|
| committer | jsing <> | 2014-04-15 16:37:22 +0000 |
| commit | 405f0a76509e0e96df735b5b902a28b8ab6c9c55 (patch) | |
| tree | 41dd30d546977ed0c409d7de59564fa1a2e3b100 /src/lib/libcrypto/bio/bf_nbio.c | |
| parent | 4e5cf8d1c0be703d2956348c807ab6ac39172547 (diff) | |
| download | openbsd-405f0a76509e0e96df735b5b902a28b8ab6c9c55.tar.gz openbsd-405f0a76509e0e96df735b5b902a28b8ab6c9c55.tar.bz2 openbsd-405f0a76509e0e96df735b5b902a28b8ab6c9c55.zip | |
First pass at applying KNF to the OpenSSL code, which almost makes it
readable. This pass is whitespace only and can readily be verified using
tr and md5.
Diffstat (limited to 'src/lib/libcrypto/bio/bf_nbio.c')
| -rw-r--r-- | src/lib/libcrypto/bio/bf_nbio.c | 235 |
1 files changed, 121 insertions, 114 deletions
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c index 028616c064..76f8f31950 100644 --- a/src/lib/libcrypto/bio/bf_nbio.c +++ b/src/lib/libcrypto/bio/bf_nbio.c | |||
| @@ -65,23 +65,22 @@ | |||
| 65 | /* BIO_put and BIO_get both add to the digest, | 65 | /* BIO_put and BIO_get both add to the digest, |
| 66 | * BIO_gets returns the digest */ | 66 | * BIO_gets returns the digest */ |
| 67 | 67 | ||
| 68 | static int nbiof_write(BIO *h,const char *buf,int num); | 68 | static int nbiof_write(BIO *h, const char *buf, int num); |
| 69 | static int nbiof_read(BIO *h,char *buf,int size); | 69 | static int nbiof_read(BIO *h, char *buf, int size); |
| 70 | static int nbiof_puts(BIO *h,const char *str); | 70 | static int nbiof_puts(BIO *h, const char *str); |
| 71 | static int nbiof_gets(BIO *h,char *str,int size); | 71 | static int nbiof_gets(BIO *h, char *str, int size); |
| 72 | static long nbiof_ctrl(BIO *h,int cmd,long arg1,void *arg2); | 72 | static long nbiof_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
| 73 | static int nbiof_new(BIO *h); | 73 | static int nbiof_new(BIO *h); |
| 74 | static int nbiof_free(BIO *data); | 74 | static int nbiof_free(BIO *data); |
| 75 | static long nbiof_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp); | 75 | static long nbiof_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp); |
| 76 | typedef struct nbio_test_st | 76 | |
| 77 | { | 77 | typedef struct nbio_test_st { |
| 78 | /* only set if we sent a 'should retry' error */ | 78 | /* only set if we sent a 'should retry' error */ |
| 79 | int lrn; | 79 | int lrn; |
| 80 | int lwn; | 80 | int lwn; |
| 81 | } NBIO_TEST; | 81 | } NBIO_TEST; |
| 82 | 82 | ||
| 83 | static BIO_METHOD methods_nbiof= | 83 | static BIO_METHOD methods_nbiof = { |
| 84 | { | ||
| 85 | BIO_TYPE_NBIO_TEST, | 84 | BIO_TYPE_NBIO_TEST, |
| 86 | "non-blocking IO test filter", | 85 | "non-blocking IO test filter", |
| 87 | nbiof_write, | 86 | nbiof_write, |
| @@ -92,162 +91,170 @@ static BIO_METHOD methods_nbiof= | |||
| 92 | nbiof_new, | 91 | nbiof_new, |
| 93 | nbiof_free, | 92 | nbiof_free, |
| 94 | nbiof_callback_ctrl, | 93 | nbiof_callback_ctrl, |
| 95 | }; | 94 | }; |
| 96 | 95 | ||
| 97 | BIO_METHOD *BIO_f_nbio_test(void) | 96 | BIO_METHOD |
| 98 | { | 97 | *BIO_f_nbio_test(void) |
| 99 | return(&methods_nbiof); | 98 | { |
| 100 | } | 99 | return (&methods_nbiof); |
| 100 | } | ||
| 101 | 101 | ||
| 102 | static int nbiof_new(BIO *bi) | 102 | static int |
| 103 | { | 103 | nbiof_new(BIO *bi) |
| 104 | { | ||
| 104 | NBIO_TEST *nt; | 105 | NBIO_TEST *nt; |
| 105 | 106 | ||
| 106 | if (!(nt=(NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST)))) return(0); | 107 | if (!(nt = (NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST)))) |
| 107 | nt->lrn= -1; | 108 | return (0); |
| 108 | nt->lwn= -1; | 109 | nt->lrn = -1; |
| 109 | bi->ptr=(char *)nt; | 110 | nt->lwn = -1; |
| 110 | bi->init=1; | 111 | bi->ptr = (char *)nt; |
| 111 | bi->flags=0; | 112 | bi->init = 1; |
| 112 | return(1); | 113 | bi->flags = 0; |
| 113 | } | 114 | return (1); |
| 115 | } | ||
| 114 | 116 | ||
| 115 | static int nbiof_free(BIO *a) | 117 | static int |
| 116 | { | 118 | nbiof_free(BIO *a) |
| 117 | if (a == NULL) return(0); | 119 | { |
| 120 | if (a == NULL) | ||
| 121 | return (0); | ||
| 118 | if (a->ptr != NULL) | 122 | if (a->ptr != NULL) |
| 119 | OPENSSL_free(a->ptr); | 123 | OPENSSL_free(a->ptr); |
| 120 | a->ptr=NULL; | 124 | a->ptr = NULL; |
| 121 | a->init=0; | 125 | a->init = 0; |
| 122 | a->flags=0; | 126 | a->flags = 0; |
| 123 | return(1); | 127 | return (1); |
| 124 | } | 128 | } |
| 125 | 129 | ||
| 126 | static int nbiof_read(BIO *b, char *out, int outl) | 130 | static int |
| 127 | { | 131 | nbiof_read(BIO *b, char *out, int outl) |
| 128 | int ret=0; | 132 | { |
| 133 | int ret = 0; | ||
| 129 | #if 1 | 134 | #if 1 |
| 130 | int num; | 135 | int num; |
| 131 | unsigned char n; | 136 | unsigned char n; |
| 132 | #endif | 137 | #endif |
| 133 | 138 | ||
| 134 | if (out == NULL) return(0); | 139 | if (out == NULL) |
| 135 | if (b->next_bio == NULL) return(0); | 140 | return (0); |
| 141 | if (b->next_bio == NULL) | ||
| 142 | return (0); | ||
| 136 | 143 | ||
| 137 | BIO_clear_retry_flags(b); | 144 | BIO_clear_retry_flags(b); |
| 138 | #if 1 | 145 | #if 1 |
| 139 | RAND_pseudo_bytes(&n,1); | 146 | RAND_pseudo_bytes(&n, 1); |
| 140 | num=(n&0x07); | 147 | num = (n & 0x07); |
| 141 | 148 | ||
| 142 | if (outl > num) outl=num; | 149 | if (outl > num) |
| 150 | outl = num; | ||
| 143 | 151 | ||
| 144 | if (num == 0) | 152 | if (num == 0) { |
| 145 | { | 153 | ret = -1; |
| 146 | ret= -1; | ||
| 147 | BIO_set_retry_read(b); | 154 | BIO_set_retry_read(b); |
| 148 | } | 155 | } else |
| 149 | else | ||
| 150 | #endif | 156 | #endif |
| 151 | { | 157 | { |
| 152 | ret=BIO_read(b->next_bio,out,outl); | 158 | ret = BIO_read(b->next_bio, out, outl); |
| 153 | if (ret < 0) | 159 | if (ret < 0) |
| 154 | BIO_copy_next_retry(b); | 160 | BIO_copy_next_retry(b); |
| 155 | } | ||
| 156 | return(ret); | ||
| 157 | } | 161 | } |
| 162 | return (ret); | ||
| 163 | } | ||
| 158 | 164 | ||
| 159 | static int nbiof_write(BIO *b, const char *in, int inl) | 165 | static int |
| 160 | { | 166 | nbiof_write(BIO *b, const char *in, int inl) |
| 167 | { | ||
| 161 | NBIO_TEST *nt; | 168 | NBIO_TEST *nt; |
| 162 | int ret=0; | 169 | int ret = 0; |
| 163 | int num; | 170 | int num; |
| 164 | unsigned char n; | 171 | unsigned char n; |
| 165 | 172 | ||
| 166 | if ((in == NULL) || (inl <= 0)) return(0); | 173 | if ((in == NULL) || (inl <= 0)) |
| 167 | if (b->next_bio == NULL) return(0); | 174 | return (0); |
| 168 | nt=(NBIO_TEST *)b->ptr; | 175 | if (b->next_bio == NULL) |
| 176 | return (0); | ||
| 177 | nt = (NBIO_TEST *)b->ptr; | ||
| 169 | 178 | ||
| 170 | BIO_clear_retry_flags(b); | 179 | BIO_clear_retry_flags(b); |
| 171 | 180 | ||
| 172 | #if 1 | 181 | #if 1 |
| 173 | if (nt->lwn > 0) | 182 | if (nt->lwn > 0) { |
| 174 | { | 183 | num = nt->lwn; |
| 175 | num=nt->lwn; | 184 | nt->lwn = 0; |
| 176 | nt->lwn=0; | 185 | } else { |
| 177 | } | 186 | RAND_pseudo_bytes(&n, 1); |
| 178 | else | 187 | num = (n&7); |
| 179 | { | 188 | } |
| 180 | RAND_pseudo_bytes(&n,1); | ||
| 181 | num=(n&7); | ||
| 182 | } | ||
| 183 | 189 | ||
| 184 | if (inl > num) inl=num; | 190 | if (inl > num) |
| 191 | inl = num; | ||
| 185 | 192 | ||
| 186 | if (num == 0) | 193 | if (num == 0) { |
| 187 | { | 194 | ret = -1; |
| 188 | ret= -1; | ||
| 189 | BIO_set_retry_write(b); | 195 | BIO_set_retry_write(b); |
| 190 | } | 196 | } else |
| 191 | else | ||
| 192 | #endif | 197 | #endif |
| 193 | { | 198 | { |
| 194 | ret=BIO_write(b->next_bio,in,inl); | 199 | ret = BIO_write(b->next_bio, in, inl); |
| 195 | if (ret < 0) | 200 | if (ret < 0) { |
| 196 | { | ||
| 197 | BIO_copy_next_retry(b); | 201 | BIO_copy_next_retry(b); |
| 198 | nt->lwn=inl; | 202 | nt->lwn = inl; |
| 199 | } | ||
| 200 | } | 203 | } |
| 201 | return(ret); | ||
| 202 | } | 204 | } |
| 205 | return (ret); | ||
| 206 | } | ||
| 203 | 207 | ||
| 204 | static long nbiof_ctrl(BIO *b, int cmd, long num, void *ptr) | 208 | static long |
| 205 | { | 209 | nbiof_ctrl(BIO *b, int cmd, long num, void *ptr) |
| 210 | { | ||
| 206 | long ret; | 211 | long ret; |
| 207 | 212 | ||
| 208 | if (b->next_bio == NULL) return(0); | 213 | if (b->next_bio == NULL) |
| 209 | switch (cmd) | 214 | return (0); |
| 210 | { | 215 | switch (cmd) { |
| 211 | case BIO_C_DO_STATE_MACHINE: | 216 | case BIO_C_DO_STATE_MACHINE: |
| 212 | BIO_clear_retry_flags(b); | 217 | BIO_clear_retry_flags(b); |
| 213 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 218 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
| 214 | BIO_copy_next_retry(b); | 219 | BIO_copy_next_retry(b); |
| 215 | break; | 220 | break; |
| 216 | case BIO_CTRL_DUP: | 221 | case BIO_CTRL_DUP: |
| 217 | ret=0L; | 222 | ret = 0L; |
| 218 | break; | 223 | break; |
| 219 | default: | 224 | default: |
| 220 | ret=BIO_ctrl(b->next_bio,cmd,num,ptr); | 225 | ret = BIO_ctrl(b->next_bio, cmd, num, ptr); |
| 221 | break; | 226 | break; |
| 222 | } | ||
| 223 | return(ret); | ||
| 224 | } | 227 | } |
| 228 | return (ret); | ||
| 229 | } | ||
| 225 | 230 | ||
| 226 | static long nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) | 231 | static long |
| 227 | { | 232 | nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) |
| 228 | long ret=1; | 233 | { |
| 234 | long ret = 1; | ||
| 229 | 235 | ||
| 230 | if (b->next_bio == NULL) return(0); | 236 | if (b->next_bio == NULL) |
| 231 | switch (cmd) | 237 | return (0); |
| 232 | { | 238 | switch (cmd) { |
| 233 | default: | 239 | default: |
| 234 | ret=BIO_callback_ctrl(b->next_bio,cmd,fp); | 240 | ret = BIO_callback_ctrl(b->next_bio, cmd, fp); |
| 235 | break; | 241 | break; |
| 236 | } | ||
| 237 | return(ret); | ||
| 238 | } | ||
| 239 | |||
| 240 | static int nbiof_gets(BIO *bp, char *buf, int size) | ||
| 241 | { | ||
| 242 | if (bp->next_bio == NULL) return(0); | ||
| 243 | return(BIO_gets(bp->next_bio,buf,size)); | ||
| 244 | } | ||
| 245 | |||
| 246 | |||
| 247 | static int nbiof_puts(BIO *bp, const char *str) | ||
| 248 | { | ||
| 249 | if (bp->next_bio == NULL) return(0); | ||
| 250 | return(BIO_puts(bp->next_bio,str)); | ||
| 251 | } | 242 | } |
| 243 | return (ret); | ||
| 244 | } | ||
| 252 | 245 | ||
| 246 | static int | ||
| 247 | nbiof_gets(BIO *bp, char *buf, int size) | ||
| 248 | { | ||
| 249 | if (bp->next_bio == NULL) | ||
| 250 | return (0); | ||
| 251 | return (BIO_gets(bp->next_bio, buf, size)); | ||
| 252 | } | ||
| 253 | 253 | ||
| 254 | static int | ||
| 255 | nbiof_puts(BIO *bp, const char *str) | ||
| 256 | { | ||
| 257 | if (bp->next_bio == NULL) | ||
| 258 | return (0); | ||
| 259 | return (BIO_puts(bp->next_bio, str)); | ||
| 260 | } | ||
