Main Page | Namespace List | Class List | Directories | File List | Class Members | File Members

bufaux.h File Reference

#include "buffer.h"
#include <openssl/bn.h>

Go to the source code of this file.

Defines

#define buffer_skip_string(b)   do { u_int l = buffer_get_int(b); buffer_consume(b, l); } while (0)

Functions

void buffer_put_bignum (Buffer *, const BIGNUM *)
void buffer_put_bignum2 (Buffer *, const BIGNUM *)
void buffer_get_bignum (Buffer *, BIGNUM *)
void buffer_get_bignum2 (Buffer *, BIGNUM *)
u_short buffer_get_short (Buffer *)
void buffer_put_short (Buffer *, u_short)
u_int buffer_get_int (Buffer *)
void buffer_put_int (Buffer *, u_int)
u_int64_t buffer_get_int64 (Buffer *)
void buffer_put_int64 (Buffer *, u_int64_t)
int buffer_get_char (Buffer *)
void buffer_put_char (Buffer *, int)
void * buffer_get_string (Buffer *, u_int *)
void buffer_put_string (Buffer *, const void *, u_int)
void buffer_put_cstring (Buffer *, const char *)
int buffer_put_bignum_ret (Buffer *, const BIGNUM *)
int buffer_get_bignum_ret (Buffer *, BIGNUM *)
int buffer_put_bignum2_ret (Buffer *, const BIGNUM *)
int buffer_get_bignum2_ret (Buffer *, BIGNUM *)
int buffer_get_short_ret (u_short *, Buffer *)
int buffer_get_int_ret (u_int *, Buffer *)
int buffer_get_int64_ret (u_int64_t *, Buffer *)
void * buffer_get_string_ret (Buffer *, u_int *)
int buffer_get_char_ret (char *, Buffer *)


Define Documentation

#define buffer_skip_string  )     do { u_int l = buffer_get_int(b); buffer_consume(b, l); } while (0)
 

Definition at line 42 of file bufaux.h.

Referenced by monitor_valid_hostbasedblob(), monitor_valid_userblob(), and valid_request().


Function Documentation

void buffer_get_bignum Buffer ,
BIGNUM * 
 

Definition at line 124 of file bufaux.c.

References buffer_get_bignum_ret(), and fatal().

Referenced by key_load_private_rsa1(), key_load_public_rsa1(), keygrab_ssh1(), packet_get_bignum(), process_add_identity(), process_authentication_challenge1(), process_remove_identity(), recv_rexec_state(), and ssh_get_next_identity().

00125 {
00126         if (buffer_get_bignum_ret(buffer, value) == -1)
00127                 fatal("buffer_get_bignum: buffer error");
00128 }

void buffer_get_bignum2 Buffer ,
BIGNUM * 
 

Definition at line 205 of file bufaux.c.

References buffer_get_bignum2_ret(), and fatal().

Referenced by mm_answer_rsa_keyallowed(), mm_answer_sesskey(), mm_auth_rsa_generate_challenge(), mm_choose_dh(), mm_ssh1_session_key(), packet_get_bignum2(), and process_add_identity().

00206 {
00207         if (buffer_get_bignum2_ret(buffer, value) == -1)
00208                 fatal("buffer_get_bignum2: buffer error");
00209 }

int buffer_get_bignum2_ret Buffer ,
BIGNUM * 
 

Definition at line 179 of file bufaux.c.

References buffer_get_string_ret(), error(), and xfree().

Referenced by buffer_get_bignum2(), and key_from_blob().

00180 {
00181         u_int len;
00182         u_char *bin;
00183 
00184         if ((bin = buffer_get_string_ret(buffer, &len)) == NULL) {
00185                 error("buffer_get_bignum2_ret: invalid bignum");
00186                 return (-1);
00187         }
00188 
00189         if (len > 0 && (bin[0] & 0x80)) {
00190                 error("buffer_get_bignum2_ret: negative numbers not supported");
00191                 xfree(bin);
00192                 return (-1);
00193         }
00194         if (len > 8 * 1024) {
00195                 error("buffer_get_bignum2_ret: cannot handle BN of size %d", len);
00196                 xfree(bin);
00197                 return (-1);
00198         }
00199         BN_bin2bn(bin, len, value);
00200         xfree(bin);
00201         return (0);
00202 }

int buffer_get_bignum_ret Buffer ,
BIGNUM * 
 

Definition at line 93 of file bufaux.c.

References bits, buffer_consume_ret(), buffer_get_ret(), buffer_len(), buffer_ptr(), error(), and GET_16BIT.

Referenced by buffer_get_bignum().

00094 {
00095         u_int bits, bytes;
00096         u_char buf[2], *bin;
00097 
00098         /* Get the number for bits. */
00099         if (buffer_get_ret(buffer, (char *) buf, 2) == -1) {
00100                 error("buffer_get_bignum_ret: invalid length");
00101                 return (-1);
00102         }
00103         bits = GET_16BIT(buf);
00104         /* Compute the number of binary bytes that follow. */
00105         bytes = (bits + 7) / 8;
00106         if (bytes > 8 * 1024) {
00107                 error("buffer_get_bignum_ret: cannot handle BN of size %d", bytes);
00108                 return (-1);
00109         }
00110         if (buffer_len(buffer) < bytes) {
00111                 error("buffer_get_bignum_ret: input buffer too small");
00112                 return (-1);
00113         }
00114         bin = buffer_ptr(buffer);
00115         BN_bin2bn(bin, bytes, value);
00116         if (buffer_consume_ret(buffer, bytes) == -1) {
00117                 error("buffer_get_bignum_ret: buffer_consume failed");
00118                 return (-1);
00119         }
00120         return (0);
00121 }

int buffer_get_char Buffer  ) 
 

Definition at line 388 of file bufaux.c.

References buffer_get_char_ret(), and fatal().

Referenced by client_process_control(), control_client(), do_convert_private_ssh2_from_blob(), do_download(), do_init(), do_lsreaddir(), do_readlink(), do_realpath(), do_upload(), get_decode_stat(), get_handle(), get_status(), kex_buf2prop(), key_load_private_rsa1(), key_load_public_rsa1(), keygrab_ssh1(), main(), mm_answer_sessid(), mm_choose_dh(), mm_getpwnamallow(), mm_request_receive_expect(), monitor_read(), monitor_valid_hostbasedblob(), monitor_valid_userblob(), packet_read_poll1(), packet_read_poll2(), process(), process_add_identity(), process_message(), recv_rexec_state(), ssh_add_identity_constrained(), ssh_agent_sign(), ssh_decrypt_challenge(), ssh_get_num_identities(), ssh_keysign(), ssh_lock_agent(), ssh_remove_all_identities(), ssh_remove_identity(), ssh_update_card(), and valid_request().

00389 {
00390         char ch;
00391 
00392         if (buffer_get_char_ret(&ch, buffer) == -1)
00393                 fatal("buffer_get_char: buffer error");
00394         return (u_char) ch;
00395 }

int buffer_get_char_ret char ,
Buffer
 

Definition at line 378 of file bufaux.c.

References buffer_get_ret(), and error().

Referenced by buffer_get_char().

00379 {
00380         if (buffer_get_ret(buffer, ret, 1) == -1) {
00381                 error("buffer_get_char_ret: buffer_get_ret failed");
00382                 return (-1);
00383         }
00384         return (0);
00385 }

u_int buffer_get_int Buffer  ) 
 

Definition at line 249 of file bufaux.c.

References buffer_get_int_ret(), and fatal().

Referenced by buffer_get_bignum_bits(), buffer_get_string_ret(), client_process_control(), control_client(), decode_attrib(), do_convert_private_ssh2_from_blob(), do_download(), do_init(), do_lsreaddir(), do_readlink(), do_realpath(), do_upload(), get_decode_stat(), get_handle(), get_msg(), get_status(), kex_buf2prop(), key_load_private_rsa1(), key_load_public_rsa1(), keygrab_ssh1(), main(), mm_answer_keyallowed(), mm_answer_moduli(), mm_answer_sign(), mm_auth_password(), mm_auth_rsa_key_allowed(), mm_auth_rsa_verify_response(), mm_bsdauth_query(), mm_bsdauth_respond(), mm_get_kex(), mm_get_keystate(), mm_key_allowed(), mm_key_verify(), mm_newkeys_from_blob(), mm_pty_allocate(), mm_ssh1_session_key(), packet_get_int(), process_add_identity(), process_authentication_challenge1(), process_remove_identity(), process_sign_request2(), recv_rexec_state(), ssh_get_next_identity(), and ssh_get_num_identities().

00250 {
00251         u_int ret;
00252 
00253         if (buffer_get_int_ret(&ret, buffer) == -1)
00254                 fatal("buffer_get_int: buffer error");
00255 
00256         return (ret);
00257 }

u_int64_t buffer_get_int64 Buffer  ) 
 

Definition at line 271 of file bufaux.c.

References buffer_get_int64_ret(), and fatal().

Referenced by decode_attrib(), and mm_get_keystate().

00272 {
00273         u_int64_t ret;
00274 
00275         if (buffer_get_int64_ret(&ret, buffer) == -1)
00276                 fatal("buffer_get_int: buffer error");
00277 
00278         return (ret);
00279 }

int buffer_get_int64_ret u_int64_t *  ,
Buffer
 

Definition at line 260 of file bufaux.c.

References buffer_get_ret(), and GET_64BIT.

Referenced by buffer_get_int64().

00261 {
00262         u_char buf[8];
00263 
00264         if (buffer_get_ret(buffer, (char *) buf, 8) == -1)
00265                 return (-1);
00266         *ret = GET_64BIT(buf);
00267         return (0);
00268 }

int buffer_get_int_ret u_int ,
Buffer
 

Definition at line 238 of file bufaux.c.

References buffer_get_ret(), and GET_32BIT.

Referenced by buffer_get_int().

00239 {
00240         u_char buf[4];
00241 
00242         if (buffer_get_ret(buffer, (char *) buf, 4) == -1)
00243                 return (-1);
00244         *ret = GET_32BIT(buf);
00245         return (0);
00246 }

u_short buffer_get_short Buffer  ) 
 

Definition at line 227 of file bufaux.c.

References buffer_get_short_ret(), and fatal().

00228 {
00229         u_short ret;
00230 
00231         if (buffer_get_short_ret(&ret, buffer) == -1)
00232                 fatal("buffer_get_short: buffer error");
00233 
00234         return (ret);
00235 }

int buffer_get_short_ret u_short *  ,
Buffer
 

Definition at line 216 of file bufaux.c.

References buffer_get_ret(), and GET_16BIT.

Referenced by buffer_get_short().

00217 {
00218         u_char buf[2];
00219 
00220         if (buffer_get_ret(buffer, (char *) buf, 2) == -1)
00221                 return (-1);
00222         *ret = GET_16BIT(buf);
00223         return (0);
00224 }

void* buffer_get_string Buffer ,
u_int
 

Definition at line 348 of file bufaux.c.

References buffer_get_string_ret(), and fatal().

Referenced by auth_debug_send(), channel_handle_wfd(), channel_output_poll(), client_process_control(), decode_attrib(), do_convert_private_ssh2_from_blob(), do_download(), do_init(), do_lsreaddir(), do_readlink(), do_realpath(), get_handle(), input_userauth_pk_ok(), kex_buf2prop(), key_load_private_rsa1(), key_load_public_rsa1(), main(), mm_answer_authpassword(), mm_answer_authserv(), mm_answer_keyallowed(), mm_answer_keyverify(), mm_answer_pty_cleanup(), mm_answer_pwnamallow(), mm_answer_rsa_challenge(), mm_answer_rsa_response(), mm_answer_sign(), mm_auth2_read_banner(), mm_auth_rsa_key_allowed(), mm_bsdauth_query(), mm_get_kex(), mm_get_keystate(), mm_getpwnamallow(), mm_key_sign(), mm_newkeys_from_blob(), mm_pty_allocate(), mm_send_debug(), monitor_valid_hostbasedblob(), monitor_valid_userblob(), packet_get_string(), process_add_identity(), process_lock_agent(), process_remove_identity(), process_sign_request2(), recv_rexec_state(), ssh_agent_sign(), ssh_dss_verify(), ssh_get_next_identity(), ssh_keysign(), ssh_rsa_verify(), userauth_pubkey(), and valid_request().

00349 {
00350         void *ret;
00351 
00352         if ((ret = buffer_get_string_ret(buffer, length_ptr)) == NULL)
00353                 fatal("buffer_get_string: buffer error");
00354         return (ret);
00355 }

void* buffer_get_string_ret Buffer ,
u_int
 

Definition at line 320 of file bufaux.c.

References buffer_get_int(), buffer_get_ret(), error(), xfree(), and xmalloc().

Referenced by buffer_get_bignum2_ret(), buffer_get_string(), key_from_blob(), and rexec_recv_rng_seed().

00321 {
00322         u_char *value;
00323         u_int len;
00324 
00325         /* Get the length. */
00326         len = buffer_get_int(buffer);
00327         if (len > 256 * 1024) {
00328                 error("buffer_get_string_ret: bad string length %u", len);
00329                 return (NULL);
00330         }
00331         /* Allocate space for the string.  Add one byte for a null character. */
00332         value = xmalloc(len + 1);
00333         /* Get the string. */
00334         if (buffer_get_ret(buffer, value, len) == -1) {
00335                 error("buffer_get_string_ret: buffer_get failed");
00336                 xfree(value);
00337                 return (NULL);
00338         }
00339         /* Append a null character to make processing easier. */
00340         value[len] = 0;
00341         /* Optionally return the length of the string. */
00342         if (length_ptr)
00343                 *length_ptr = len;
00344         return (value);
00345 }

void buffer_put_bignum Buffer ,
const BIGNUM * 
 

Definition at line 83 of file bufaux.c.

References buffer_put_bignum_ret(), and fatal().

Referenced by key_save_private_rsa1(), packet_put_bignum(), process_request_identities(), send_rexec_state(), ssh_decrypt_challenge(), ssh_encode_identity_rsa1(), and ssh_remove_identity().

00084 {
00085         if (buffer_put_bignum_ret(buffer, value) == -1)
00086                 fatal("buffer_put_bignum: buffer error");
00087 }

void buffer_put_bignum2 Buffer ,
const BIGNUM * 
 

Definition at line 172 of file bufaux.c.

References buffer_put_bignum2_ret(), and fatal().

Referenced by derive_key(), kex_dh_hash(), kexgex_hash(), key_to_blob(), mm_answer_moduli(), mm_answer_rsa_challenge(), mm_answer_sesskey(), mm_auth_rsa_key_allowed(), mm_ssh1_session_key(), packet_put_bignum2(), and ssh_encode_identity_ssh2().

00173 {
00174         if (buffer_put_bignum2_ret(buffer, value) == -1)
00175                 fatal("buffer_put_bignum2: buffer error");
00176 }

int buffer_put_bignum2_ret Buffer ,
const BIGNUM * 
 

Definition at line 134 of file bufaux.c.

References buffer_put_int(), buffer_put_string(), error(), xfree(), and xmalloc().

Referenced by buffer_put_bignum2().

00135 {
00136         u_int bytes;
00137         u_char *buf;
00138         int oi;
00139         u_int hasnohigh = 0;
00140 
00141         if (BN_is_zero(value)) {
00142                 buffer_put_int(buffer, 0);
00143                 return 0;
00144         }
00145         if (value->neg) {
00146                 error("buffer_put_bignum2_ret: negative numbers not supported");
00147                 return (-1);
00148         }
00149         bytes = BN_num_bytes(value) + 1; /* extra padding byte */
00150         if (bytes < 2) {
00151                 error("buffer_put_bignum2_ret: BN too small");
00152                 return (-1);
00153         }
00154         buf = xmalloc(bytes);
00155         buf[0] = 0x00;
00156         /* Get the value of in binary */
00157         oi = BN_bn2bin(value, buf+1);
00158         if (oi < 0 || (u_int)oi != bytes - 1) {
00159                 error("buffer_put_bignum2_ret: BN_bn2bin() failed: "
00160                     "oi %d != bin_size %d", oi, bytes);
00161                 xfree(buf);
00162                 return (-1);
00163         }
00164         hasnohigh = (buf[1] & 0x80) ? 0 : 1;
00165         buffer_put_string(buffer, buf+hasnohigh, bytes-hasnohigh);
00166         memset(buf, 0, bytes);
00167         xfree(buf);
00168         return (0);
00169 }

int buffer_put_bignum_ret Buffer ,
const BIGNUM * 
 

Definition at line 53 of file bufaux.c.

References bits, buffer_append(), error(), PUT_16BIT, xfree(), and xmalloc().

Referenced by buffer_put_bignum().

00054 {
00055         int bits = BN_num_bits(value);
00056         int bin_size = (bits + 7) / 8;
00057         u_char *buf = xmalloc(bin_size);
00058         int oi;
00059         char msg[2];
00060 
00061         /* Get the value of in binary */
00062         oi = BN_bn2bin(value, buf);
00063         if (oi != bin_size) {
00064                 error("buffer_put_bignum_ret: BN_bn2bin() failed: oi %d != bin_size %d",
00065                     oi, bin_size);
00066                 xfree(buf);
00067                 return (-1);
00068         }
00069 
00070         /* Store the number of bits in the buffer in two bytes, msb first. */
00071         PUT_16BIT(msg, bits);
00072         buffer_append(buffer, msg, 2);
00073         /* Store the binary data. */
00074         buffer_append(buffer, (char *)buf, oi);
00075 
00076         memset(buf, 0, bin_size);
00077         xfree(buf);
00078 
00079         return (0);
00080 }

void buffer_put_char Buffer ,
int 
 

Definition at line 401 of file bufaux.c.

References buffer_append().

Referenced by channel_decode_socks5(), do_close(), do_download(), do_init(), do_lsreaddir(), do_rename(), do_symlink(), do_upload(), kex_dh_hash(), kex_prop2buf(), kexgex_hash(), key_save_private_rsa1(), mm_answer_moduli(), mm_answer_pwnamallow(), mm_ssh1_session_id(), no_identities(), process_add_identity(), process_authentication_challenge1(), process_escapes(), process_init(), process_lock_agent(), process_message(), process_remove_all_identities(), process_remove_identity(), process_request_identities(), process_sign_request2(), send_attrib(), send_data_or_handle(), send_names(), send_read_request(), send_status(), send_string_attrs_request(), send_string_request(), sign_and_send_pubkey(), ssh_add_identity_constrained(), ssh_agent_sign(), ssh_decrypt_challenge(), ssh_get_num_identities(), ssh_lock_agent(), ssh_remove_all_identities(), ssh_remove_identity(), ssh_update_card(), tty_make_modes(), userauth_hostbased(), and userauth_pubkey().

00402 {
00403         char ch = value;
00404 
00405         buffer_append(buffer, &ch, 1);
00406 }

void buffer_put_cstring Buffer ,
const char
 

Definition at line 367 of file bufaux.c.

References buffer_put_string(), and fatal().

Referenced by auth_debug_add(), control_client(), do_download(), do_lsreaddir(), do_rename(), do_symlink(), do_upload(), kex_dh_hash(), kex_prop2buf(), kexgex_hash(), key_save_private_rsa1(), key_to_blob(), mm_answer_auth2_read_banner(), mm_answer_pty(), mm_answer_pwnamallow(), mm_auth_password(), mm_bsdauth_respond(), mm_getpwnamallow(), mm_inform_authserv(), mm_key_allowed(), mm_newkeys_to_blob(), mm_send_kex(), mm_session_pty_cleanup2(), packet_put_cstring(), process_request_identities(), send_names(), send_rexec_state(), send_status(), sign_and_send_pubkey(), ssh_dss_sign(), ssh_encode_identity_rsa1(), ssh_encode_identity_ssh2(), ssh_lock_agent(), ssh_rsa_sign(), ssh_update_card(), userauth_hostbased(), and userauth_pubkey().

00368 {
00369         if (s == NULL)
00370                 fatal("buffer_put_cstring: s == NULL");
00371         buffer_put_string(buffer, s, strlen(s));
00372 }

void buffer_put_int Buffer ,
u_int 
 

Definition at line 294 of file bufaux.c.

References buffer_append(), and PUT_32BIT.

Referenced by buffer_put_bignum2_ret(), buffer_put_string(), client_process_control(), control_client(), do_close(), do_download(), do_init(), do_lsreaddir(), do_rename(), do_symlink(), do_upload(), encode_attrib(), kex_dh_hash(), kex_prop2buf(), kexgex_hash(), key_save_private_rsa1(), mm_answer_authpassword(), mm_answer_keyallowed(), mm_answer_keyverify(), mm_answer_pty(), mm_answer_rsa_keyallowed(), mm_answer_rsa_response(), mm_answer_sesskey(), mm_choose_dh(), mm_key_allowed(), mm_key_sign(), mm_newkeys_to_blob(), mm_send_kex(), mm_send_keystate(), no_identities(), packet_put_int(), process_add_identity(), process_authentication_challenge1(), process_init(), process_lock_agent(), process_message(), process_remove_all_identities(), process_remove_identity(), process_request_identities(), process_sign_request2(), send_attrib(), send_data_or_handle(), send_msg(), send_names(), send_read_request(), send_rexec_state(), send_status(), send_string_attrs_request(), send_string_request(), ssh_add_identity_constrained(), ssh_agent_sign(), ssh_decrypt_challenge(), ssh_encode_identity_rsa1(), ssh_keysign(), ssh_remove_identity(), ssh_update_card(), and tty_make_modes().

00295 {
00296         char buf[4];
00297 
00298         PUT_32BIT(buf, value);
00299         buffer_append(buffer, buf, 4);
00300 }

void buffer_put_int64 Buffer ,
u_int64_t 
 

Definition at line 303 of file bufaux.c.

References buffer_append(), and PUT_64BIT.

Referenced by do_upload(), encode_attrib(), mm_send_keystate(), and send_read_request().

00304 {
00305         char buf[8];
00306 
00307         PUT_64BIT(buf, value);
00308         buffer_append(buffer, buf, 8);
00309 }

void buffer_put_short Buffer ,
u_short 
 

Definition at line 285 of file bufaux.c.

References buffer_append(), and PUT_16BIT.

00286 {
00287         char buf[2];
00288 
00289         PUT_16BIT(buf, value);
00290         buffer_append(buffer, buf, 2);
00291 }

void buffer_put_string Buffer ,
const void *  ,
u_int 
 

Definition at line 361 of file bufaux.c.

References buffer_append(), and buffer_put_int().

Referenced by buffer_put_bignum2_ret(), buffer_put_cstring(), channel_handle_rfd(), channel_input_data(), do_close(), do_lsreaddir(), do_upload(), kex_dh_hash(), kexgex_hash(), main(), mm_answer_pty(), mm_answer_pwnamallow(), mm_answer_rsa_keyallowed(), mm_answer_sign(), mm_auth_rsa_generate_challenge(), mm_auth_rsa_verify_response(), mm_key_allowed(), mm_key_sign(), mm_key_verify(), mm_newkeys_to_blob(), mm_send_kex(), mm_send_keystate(), packet_put_string(), process_request_identities(), process_sign_request2(), rexec_send_rng_seed(), send_data_or_handle(), send_read_request(), send_string_attrs_request(), send_string_request(), sign_and_send_pubkey(), ssh_agent_sign(), ssh_dss_sign(), ssh_keysign(), ssh_remove_identity(), ssh_rsa_sign(), userauth_hostbased(), and userauth_pubkey().

00362 {
00363         buffer_put_int(buffer, len);
00364         buffer_append(buffer, buf, len);
00365 }


© sourcejam.com 2005-2008