21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

memcpy(in_data.data, inbuf, inlen);<br />

spc_add_padding((unsigned char *)in_data.data + inlen, inlen, blksz);<br />

if (krb5_c_encrypt_length(ctx, key->enctype, in_data.length, outlen)) {<br />

free(in_data.data);<br />

return 0;<br />

}<br />

out_data.magic = KV5M_ENC_DATA;<br />

out_data.enctype = key->enctype;<br />

out_data.kvno = 0;<br />

out_data.ciphertext.magic = KV5M_ENCRYPT_BLOCK;<br />

out_data.ciphertext.length = *outlen;<br />

out_data.ciphertext.data = malloc(*outlen);<br />

if (!out_data.ciphertext.data) {<br />

free(in_data.data);<br />

return 0;<br />

}<br />

if (krb5_c_encrypt(ctx, key, 0, 0, &in_data, &out_data)) {<br />

free(in_data.data);<br />

return 0;<br />

}<br />

*outbuf = out_data.ciphertext.data;<br />

free(in_data.data);<br />

return 1;<br />

#else<br />

int result;<br />

void *tmp;<br />

size_t blksz, newlen;<br />

krb5_data edata;<br />

krb5_crypto crypto;<br />

if (krb5_crypto_init(ctx, key, 0, &crypto) != 0) return 0;<br />

if (krb5_crypto_getblocksize(ctx, crypto, &blksz)) {<br />

krb5_crypto_destroy(ctx, crypto);<br />

return 0;<br />

}<br />

if (!(inlen % blksz)) newlen = inlen + blksz;<br />

else newlen = ((inlen + blksz - 1) / blksz) * blksz;<br />

if (!(tmp = malloc(newlen))) {<br />

krb5_crypto_destroy(ctx, crypto);<br />

return 0;<br />

}<br />

memcpy(tmp, inbuf, inlen);<br />

spc_add_padding((unsigned char *)tmp + inlen, inlen, blksz);<br />

if (!krb5_encrypt(ctx, crypto, 0, tmp, inlen, &edata)) {<br />

if ((*outbuf = malloc(edata.length)) != 0) {<br />

result = 1;<br />

memcpy(*outbuf, edata.data, edata.length);<br />

*outlen = edata.length;<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.<br />

Using Kerberos Encryption | 473

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!