2 * fs/cifs/cifsencrypt.c
4 * Copyright (C) International Business Machines Corp., 2005,2006
5 * Author(s): Steve French (sfrench@us.ibm.com)
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
15 * the GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/slab.h>
26 #include "cifs_debug.h"
27 #include "cifs_unicode.h"
28 #include "cifsproto.h"
30 #include <linux/ctype.h>
31 #include <linux/random.h>
33 /* Calculate and return the CIFS signature based on the mac key and SMB PDU */
34 /* the 16 byte signature must be allocated by the caller */
35 /* Note we only use the 1st eight bytes */
36 /* Note that the smb header signature field on input contains the
37 sequence number before this function is called */
39 extern void mdfour(unsigned char *out, unsigned char *in, int n);
40 extern void E_md4hash(const unsigned char *passwd, unsigned char *p16);
41 extern void SMBencrypt(unsigned char *passwd, const unsigned char *c8,
44 static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu,
45 struct TCP_Server_Info *server, char *signature)
49 if (cifs_pdu == NULL || signature == NULL || server == NULL)
52 if (!server->secmech.sdescmd5) {
53 cERROR(1, "%s: Can't generate signature\n", __func__);
57 rc = crypto_shash_init(&server->secmech.sdescmd5->shash);
59 cERROR(1, "%s: Oould not init md5\n", __func__);
63 crypto_shash_update(&server->secmech.sdescmd5->shash,
64 server->session_key.response, server->session_key.len);
66 crypto_shash_update(&server->secmech.sdescmd5->shash,
67 cifs_pdu->Protocol, cifs_pdu->smb_buf_length);
69 rc = crypto_shash_final(&server->secmech.sdescmd5->shash, signature);
74 /* must be called with server->srv_mutex held */
75 int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server,
76 __u32 *pexpected_response_sequence_number)
79 char smb_signature[20];
81 if ((cifs_pdu == NULL) || (server == NULL))
84 if ((cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) == 0)
87 cifs_pdu->Signature.Sequence.SequenceNumber =
88 cpu_to_le32(server->sequence_number);
89 cifs_pdu->Signature.Sequence.Reserved = 0;
91 *pexpected_response_sequence_number = server->sequence_number++;
92 server->sequence_number++;
94 rc = cifs_calculate_signature(cifs_pdu, server, smb_signature);
96 memset(cifs_pdu->Signature.SecuritySignature, 0, 8);
98 memcpy(cifs_pdu->Signature.SecuritySignature, smb_signature, 8);
103 static int cifs_calc_signature2(const struct kvec *iov, int n_vec,
104 struct TCP_Server_Info *server, char *signature)
109 if (iov == NULL || signature == NULL || server == NULL)
112 if (!server->secmech.sdescmd5) {
113 cERROR(1, "%s: Can't generate signature\n", __func__);
117 rc = crypto_shash_init(&server->secmech.sdescmd5->shash);
119 cERROR(1, "%s: Oould not init md5\n", __func__);
123 crypto_shash_update(&server->secmech.sdescmd5->shash,
124 server->session_key.response, server->session_key.len);
126 for (i = 0; i < n_vec; i++) {
127 if (iov[i].iov_len == 0)
129 if (iov[i].iov_base == NULL) {
130 cERROR(1, "null iovec entry");
133 /* The first entry includes a length field (which does not get
134 signed that occupies the first 4 bytes before the header */
136 if (iov[0].iov_len <= 8) /* cmd field at offset 9 */
137 break; /* nothing to sign or corrupt header */
138 crypto_shash_update(&server->secmech.sdescmd5->shash,
139 iov[i].iov_base + 4, iov[i].iov_len - 4);
141 crypto_shash_update(&server->secmech.sdescmd5->shash,
142 iov[i].iov_base, iov[i].iov_len);
145 rc = crypto_shash_final(&server->secmech.sdescmd5->shash, signature);
150 /* must be called with server->srv_mutex held */
151 int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server,
152 __u32 *pexpected_response_sequence_number)
155 char smb_signature[20];
156 struct smb_hdr *cifs_pdu = iov[0].iov_base;
158 if ((cifs_pdu == NULL) || (server == NULL))
161 if ((cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) == 0)
164 cifs_pdu->Signature.Sequence.SequenceNumber =
165 cpu_to_le32(server->sequence_number);
166 cifs_pdu->Signature.Sequence.Reserved = 0;
168 *pexpected_response_sequence_number = server->sequence_number++;
169 server->sequence_number++;
171 rc = cifs_calc_signature2(iov, n_vec, server, smb_signature);
173 memset(cifs_pdu->Signature.SecuritySignature, 0, 8);
175 memcpy(cifs_pdu->Signature.SecuritySignature, smb_signature, 8);
180 int cifs_verify_signature(struct smb_hdr *cifs_pdu,
181 struct TCP_Server_Info *server,
182 __u32 expected_sequence_number)
185 char server_response_sig[8];
186 char what_we_think_sig_should_be[20];
188 if (cifs_pdu == NULL || server == NULL)
191 if (cifs_pdu->Command == SMB_COM_NEGOTIATE)
194 if (cifs_pdu->Command == SMB_COM_LOCKING_ANDX) {
195 struct smb_com_lock_req *pSMB =
196 (struct smb_com_lock_req *)cifs_pdu;
197 if (pSMB->LockType & LOCKING_ANDX_OPLOCK_RELEASE)
201 /* BB what if signatures are supposed to be on for session but
202 server does not send one? BB */
204 /* Do not need to verify session setups with signature "BSRSPYL " */
205 if (memcmp(cifs_pdu->Signature.SecuritySignature, "BSRSPYL ", 8) == 0)
206 cFYI(1, "dummy signature received for smb command 0x%x",
209 /* save off the origiginal signature so we can modify the smb and check
210 its signature against what the server sent */
211 memcpy(server_response_sig, cifs_pdu->Signature.SecuritySignature, 8);
213 cifs_pdu->Signature.Sequence.SequenceNumber =
214 cpu_to_le32(expected_sequence_number);
215 cifs_pdu->Signature.Sequence.Reserved = 0;
217 rc = cifs_calculate_signature(cifs_pdu, server,
218 what_we_think_sig_should_be);
223 /* cifs_dump_mem("what we think it should be: ",
224 what_we_think_sig_should_be, 16); */
226 if (memcmp(server_response_sig, what_we_think_sig_should_be, 8))
233 /* first calculate 24 bytes ntlm response and then 16 byte session key */
234 int setup_ntlm_response(struct cifsSesInfo *ses)
236 unsigned int temp_len = CIFS_SESS_KEY_SIZE + CIFS_AUTH_RESP_SIZE;
237 char temp_key[CIFS_SESS_KEY_SIZE];
242 ses->auth_key.response = kmalloc(temp_len, GFP_KERNEL);
243 if (!ses->auth_key.response) {
244 cERROR(1, "NTLM can't allocate (%u bytes) memory", temp_len);
247 ses->auth_key.len = temp_len;
249 SMBNTencrypt(ses->password, ses->server->cryptkey,
250 ses->auth_key.response + CIFS_SESS_KEY_SIZE);
252 E_md4hash(ses->password, temp_key);
253 mdfour(ses->auth_key.response, temp_key, CIFS_SESS_KEY_SIZE);
258 #ifdef CONFIG_CIFS_WEAK_PW_HASH
259 void calc_lanman_hash(const char *password, const char *cryptkey, bool encrypt,
260 char *lnm_session_key)
263 char password_with_pad[CIFS_ENCPWD_SIZE];
265 memset(password_with_pad, 0, CIFS_ENCPWD_SIZE);
267 strncpy(password_with_pad, password, CIFS_ENCPWD_SIZE);
269 if (!encrypt && global_secflags & CIFSSEC_MAY_PLNTXT) {
270 memset(lnm_session_key, 0, CIFS_SESS_KEY_SIZE);
271 memcpy(lnm_session_key, password_with_pad,
276 /* calculate old style session key */
277 /* calling toupper is less broken than repeatedly
278 calling nls_toupper would be since that will never
279 work for UTF8, but neither handles multibyte code pages
280 but the only alternative would be converting to UCS-16 (Unicode)
281 (using a routine something like UniStrupr) then
282 uppercasing and then converting back from Unicode - which
283 would only worth doing it if we knew it were utf8. Basically
284 utf8 and other multibyte codepages each need their own strupper
285 function since a byte at a time will ont work. */
287 for (i = 0; i < CIFS_ENCPWD_SIZE; i++)
288 password_with_pad[i] = toupper(password_with_pad[i]);
290 SMBencrypt(password_with_pad, cryptkey, lnm_session_key);
292 /* clear password before we return/free memory */
293 memset(password_with_pad, 0, CIFS_ENCPWD_SIZE);
295 #endif /* CIFS_WEAK_PW_HASH */
297 /* Build a proper attribute value/target info pairs blob.
298 * Fill in netbios and dns domain name and workstation name
299 * and client time (total five av pairs and + one end of fields indicator.
300 * Allocate domain name which gets freed when session struct is deallocated.
303 build_avpair_blob(struct cifsSesInfo *ses, const struct nls_table *nls_cp)
307 unsigned int size = 6 * sizeof(struct ntlmssp2_name);
309 char *defdmname = "WORKGROUP";
310 unsigned char *blobptr;
311 struct ntlmssp2_name *attrptr;
313 if (!ses->domainName) {
314 ses->domainName = kstrdup(defdmname, GFP_KERNEL);
315 if (!ses->domainName)
319 dlen = strlen(ses->domainName);
320 wlen = strlen(ses->server->hostname);
322 /* The length of this blob is a size which is
323 * six times the size of a structure which holds name/size +
324 * two times the unicode length of a domain name +
325 * two times the unicode length of a server name +
326 * size of a timestamp (which is 8 bytes).
328 ses->auth_key.len = size + 2 * (2 * dlen) + 2 * (2 * wlen) + 8;
329 ses->auth_key.response = kzalloc(ses->auth_key.len, GFP_KERNEL);
330 if (!ses->auth_key.response) {
331 ses->auth_key.len = 0;
332 cERROR(1, "Challenge target info allocation failure");
336 blobptr = ses->auth_key.response;
337 attrptr = (struct ntlmssp2_name *) blobptr;
339 attrptr->type = cpu_to_le16(NTLMSSP_AV_NB_DOMAIN_NAME);
340 attrptr->length = cpu_to_le16(2 * dlen);
341 blobptr = (unsigned char *)attrptr + sizeof(struct ntlmssp2_name);
342 cifs_strtoUCS((__le16 *)blobptr, ses->domainName, dlen, nls_cp);
345 attrptr = (struct ntlmssp2_name *) blobptr;
347 attrptr->type = cpu_to_le16(NTLMSSP_AV_NB_COMPUTER_NAME);
348 attrptr->length = cpu_to_le16(2 * wlen);
349 blobptr = (unsigned char *)attrptr + sizeof(struct ntlmssp2_name);
350 cifs_strtoUCS((__le16 *)blobptr, ses->server->hostname, wlen, nls_cp);
353 attrptr = (struct ntlmssp2_name *) blobptr;
355 attrptr->type = cpu_to_le16(NTLMSSP_AV_DNS_DOMAIN_NAME);
356 attrptr->length = cpu_to_le16(2 * dlen);
357 blobptr = (unsigned char *)attrptr + sizeof(struct ntlmssp2_name);
358 cifs_strtoUCS((__le16 *)blobptr, ses->domainName, dlen, nls_cp);
361 attrptr = (struct ntlmssp2_name *) blobptr;
363 attrptr->type = cpu_to_le16(NTLMSSP_AV_DNS_COMPUTER_NAME);
364 attrptr->length = cpu_to_le16(2 * wlen);
365 blobptr = (unsigned char *)attrptr + sizeof(struct ntlmssp2_name);
366 cifs_strtoUCS((__le16 *)blobptr, ses->server->hostname, wlen, nls_cp);
369 attrptr = (struct ntlmssp2_name *) blobptr;
371 attrptr->type = cpu_to_le16(NTLMSSP_AV_TIMESTAMP);
372 attrptr->length = cpu_to_le16(sizeof(__le64));
373 blobptr = (unsigned char *)attrptr + sizeof(struct ntlmssp2_name);
374 curtime = cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME));
375 memcpy(blobptr, &curtime, sizeof(__le64));
380 /* Server has provided av pairs/target info in the type 2 challenge
381 * packet and we have plucked it and stored within smb session.
382 * We parse that blob here to find netbios domain name to be used
383 * as part of ntlmv2 authentication (in Target String), if not already
384 * specified on the command line.
385 * If this function returns without any error but without fetching
386 * domain name, authentication may fail against some server but
387 * may not fail against other (those who are not very particular
388 * about target string i.e. for some, just user name might suffice.
391 find_domain_name(struct cifsSesInfo *ses, const struct nls_table *nls_cp)
393 unsigned int attrsize;
395 unsigned int onesize = sizeof(struct ntlmssp2_name);
396 unsigned char *blobptr;
397 unsigned char *blobend;
398 struct ntlmssp2_name *attrptr;
400 if (!ses->auth_key.len || !ses->auth_key.response)
403 blobptr = ses->auth_key.response;
404 blobend = blobptr + ses->auth_key.len;
406 while (blobptr + onesize < blobend) {
407 attrptr = (struct ntlmssp2_name *) blobptr;
408 type = le16_to_cpu(attrptr->type);
409 if (type == NTLMSSP_AV_EOL)
411 blobptr += 2; /* advance attr type */
412 attrsize = le16_to_cpu(attrptr->length);
413 blobptr += 2; /* advance attr size */
414 if (blobptr + attrsize > blobend)
416 if (type == NTLMSSP_AV_NB_DOMAIN_NAME) {
419 if (!ses->domainName) {
421 kmalloc(attrsize + 1, GFP_KERNEL);
422 if (!ses->domainName)
424 cifs_from_ucs2(ses->domainName,
425 (__le16 *)blobptr, attrsize, attrsize,
430 blobptr += attrsize; /* advance attr value */
436 static int calc_ntlmv2_hash(struct cifsSesInfo *ses, char *ntlmv2_hash,
437 const struct nls_table *nls_cp)
441 char nt_hash[CIFS_NTHASH_SIZE];
446 if (!ses->server->secmech.sdeschmacmd5) {
447 cERROR(1, "calc_ntlmv2_hash: can't generate ntlmv2 hash\n");
451 /* calculate md4 hash of password */
452 E_md4hash(ses->password, nt_hash);
454 crypto_shash_setkey(ses->server->secmech.hmacmd5, nt_hash,
457 rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash);
459 cERROR(1, "calc_ntlmv2_hash: could not init hmacmd5\n");
463 /* convert ses->userName to unicode and uppercase */
464 len = strlen(ses->userName);
465 user = kmalloc(2 + (len * 2), GFP_KERNEL);
467 cERROR(1, "calc_ntlmv2_hash: user mem alloc failure\n");
471 len = cifs_strtoUCS((__le16 *)user, ses->userName, len, nls_cp);
474 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
475 (char *)user, 2 * len);
477 /* convert ses->domainName to unicode and uppercase */
478 if (ses->domainName) {
479 len = strlen(ses->domainName);
481 domain = kmalloc(2 + (len * 2), GFP_KERNEL);
482 if (domain == NULL) {
483 cERROR(1, "calc_ntlmv2_hash: domain mem alloc failure");
487 len = cifs_strtoUCS((__le16 *)domain, ses->domainName, len,
489 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
490 (char *)domain, 2 * len);
492 } else if (ses->serverName) {
493 len = strlen(ses->serverName);
495 server = kmalloc(2 + (len * 2), GFP_KERNEL);
496 if (server == NULL) {
497 cERROR(1, "calc_ntlmv2_hash: server mem alloc failure");
501 len = cifs_strtoUCS((__le16 *)server, ses->serverName, len,
503 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
504 (char *)server, 2 * len);
508 rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash,
518 CalcNTLMv2_response(const struct cifsSesInfo *ses, char *ntlmv2_hash)
521 unsigned int offset = CIFS_SESS_KEY_SIZE + 8;
523 if (!ses->server->secmech.sdeschmacmd5) {
524 cERROR(1, "calc_ntlmv2_hash: can't generate ntlmv2 hash\n");
528 crypto_shash_setkey(ses->server->secmech.hmacmd5,
529 ntlmv2_hash, CIFS_HMAC_MD5_HASH_SIZE);
531 rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash);
533 cERROR(1, "CalcNTLMv2_response: could not init hmacmd5");
537 if (ses->server->secType == RawNTLMSSP)
538 memcpy(ses->auth_key.response + offset,
539 ses->ntlmssp->cryptkey, CIFS_SERVER_CHALLENGE_SIZE);
541 memcpy(ses->auth_key.response + offset,
542 ses->server->cryptkey, CIFS_SERVER_CHALLENGE_SIZE);
543 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
544 ses->auth_key.response + offset, ses->auth_key.len - offset);
546 rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash,
547 ses->auth_key.response + CIFS_SESS_KEY_SIZE);
554 setup_ntlmv2_rsp(struct cifsSesInfo *ses, const struct nls_table *nls_cp)
559 struct ntlmv2_resp *buf;
560 char ntlmv2_hash[16];
561 unsigned char *tiblob = NULL; /* target info blob */
563 if (ses->server->secType == RawNTLMSSP) {
564 if (!ses->domainName) {
565 rc = find_domain_name(ses, nls_cp);
567 cERROR(1, "error %d finding domain name", rc);
568 goto setup_ntlmv2_rsp_ret;
572 rc = build_avpair_blob(ses, nls_cp);
574 cERROR(1, "error %d building av pair blob", rc);
575 goto setup_ntlmv2_rsp_ret;
579 baselen = CIFS_SESS_KEY_SIZE + sizeof(struct ntlmv2_resp);
580 tilen = ses->auth_key.len;
581 tiblob = ses->auth_key.response;
583 ses->auth_key.response = kmalloc(baselen + tilen, GFP_KERNEL);
584 if (!ses->auth_key.response) {
586 ses->auth_key.len = 0;
587 cERROR(1, "%s: Can't allocate auth blob", __func__);
588 goto setup_ntlmv2_rsp_ret;
590 ses->auth_key.len += baselen;
592 buf = (struct ntlmv2_resp *)
593 (ses->auth_key.response + CIFS_SESS_KEY_SIZE);
594 buf->blob_signature = cpu_to_le32(0x00000101);
596 buf->time = cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME));
597 get_random_bytes(&buf->client_chal, sizeof(buf->client_chal));
600 memcpy(ses->auth_key.response + baselen, tiblob, tilen);
602 /* calculate ntlmv2_hash */
603 rc = calc_ntlmv2_hash(ses, ntlmv2_hash, nls_cp);
605 cERROR(1, "could not get v2 hash rc %d", rc);
606 goto setup_ntlmv2_rsp_ret;
609 /* calculate first part of the client response (CR1) */
610 rc = CalcNTLMv2_response(ses, ntlmv2_hash);
612 cERROR(1, "Could not calculate CR1 rc: %d", rc);
613 goto setup_ntlmv2_rsp_ret;
616 /* now calculate the session key for NTLMv2 */
617 crypto_shash_setkey(ses->server->secmech.hmacmd5,
618 ntlmv2_hash, CIFS_HMAC_MD5_HASH_SIZE);
620 rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash);
622 cERROR(1, "%s: Could not init hmacmd5\n", __func__);
623 goto setup_ntlmv2_rsp_ret;
626 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
627 ses->auth_key.response + CIFS_SESS_KEY_SIZE,
628 CIFS_HMAC_MD5_HASH_SIZE);
630 rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash,
631 ses->auth_key.response);
633 setup_ntlmv2_rsp_ret:
640 calc_seckey(struct cifsSesInfo *ses)
643 struct crypto_blkcipher *tfm_arc4;
644 struct scatterlist sgin, sgout;
645 struct blkcipher_desc desc;
646 unsigned char sec_key[CIFS_SESS_KEY_SIZE]; /* a nonce */
648 get_random_bytes(sec_key, CIFS_SESS_KEY_SIZE);
650 tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
651 if (!tfm_arc4 || IS_ERR(tfm_arc4)) {
652 cERROR(1, "could not allocate crypto API arc4\n");
653 return PTR_ERR(tfm_arc4);
658 crypto_blkcipher_setkey(tfm_arc4, ses->auth_key.response,
661 sg_init_one(&sgin, sec_key, CIFS_SESS_KEY_SIZE);
662 sg_init_one(&sgout, ses->ntlmssp->ciphertext, CIFS_CPHTXT_SIZE);
664 rc = crypto_blkcipher_encrypt(&desc, &sgout, &sgin, CIFS_CPHTXT_SIZE);
666 cERROR(1, "could not encrypt session key rc: %d\n", rc);
667 crypto_free_blkcipher(tfm_arc4);
671 /* make secondary_key/nonce as session key */
672 memcpy(ses->auth_key.response, sec_key, CIFS_SESS_KEY_SIZE);
673 /* and make len as that of session key only */
674 ses->auth_key.len = CIFS_SESS_KEY_SIZE;
676 crypto_free_blkcipher(tfm_arc4);
682 cifs_crypto_shash_release(struct TCP_Server_Info *server)
684 if (server->secmech.md5)
685 crypto_free_shash(server->secmech.md5);
687 if (server->secmech.hmacmd5)
688 crypto_free_shash(server->secmech.hmacmd5);
690 kfree(server->secmech.sdeschmacmd5);
692 kfree(server->secmech.sdescmd5);
696 cifs_crypto_shash_allocate(struct TCP_Server_Info *server)
701 server->secmech.hmacmd5 = crypto_alloc_shash("hmac(md5)", 0, 0);
702 if (!server->secmech.hmacmd5 ||
703 IS_ERR(server->secmech.hmacmd5)) {
704 cERROR(1, "could not allocate crypto hmacmd5\n");
705 return PTR_ERR(server->secmech.hmacmd5);
708 server->secmech.md5 = crypto_alloc_shash("md5", 0, 0);
709 if (!server->secmech.md5 || IS_ERR(server->secmech.md5)) {
710 cERROR(1, "could not allocate crypto md5\n");
711 rc = PTR_ERR(server->secmech.md5);
712 goto crypto_allocate_md5_fail;
715 size = sizeof(struct shash_desc) +
716 crypto_shash_descsize(server->secmech.hmacmd5);
717 server->secmech.sdeschmacmd5 = kmalloc(size, GFP_KERNEL);
718 if (!server->secmech.sdeschmacmd5) {
719 cERROR(1, "cifs_crypto_shash_allocate: can't alloc hmacmd5\n");
721 goto crypto_allocate_hmacmd5_sdesc_fail;
723 server->secmech.sdeschmacmd5->shash.tfm = server->secmech.hmacmd5;
724 server->secmech.sdeschmacmd5->shash.flags = 0x0;
727 size = sizeof(struct shash_desc) +
728 crypto_shash_descsize(server->secmech.md5);
729 server->secmech.sdescmd5 = kmalloc(size, GFP_KERNEL);
730 if (!server->secmech.sdescmd5) {
731 cERROR(1, "cifs_crypto_shash_allocate: can't alloc md5\n");
733 goto crypto_allocate_md5_sdesc_fail;
735 server->secmech.sdescmd5->shash.tfm = server->secmech.md5;
736 server->secmech.sdescmd5->shash.flags = 0x0;
740 crypto_allocate_md5_sdesc_fail:
741 kfree(server->secmech.sdeschmacmd5);
743 crypto_allocate_hmacmd5_sdesc_fail:
744 crypto_free_shash(server->secmech.md5);
746 crypto_allocate_md5_fail:
747 crypto_free_shash(server->secmech.hmacmd5);