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"
28 #include "cifs_unicode.h"
29 #include "cifsproto.h"
31 #include <linux/ctype.h>
32 #include <linux/random.h>
34 /* Calculate and return the CIFS signature based on the mac key and SMB PDU */
35 /* the 16 byte signature must be allocated by the caller */
36 /* Note we only use the 1st eight bytes */
37 /* Note that the smb header signature field on input contains the
38 sequence number before this function is called */
40 extern void mdfour(unsigned char *out
, unsigned char *in
, int n
);
41 extern void E_md4hash(const unsigned char *passwd
, unsigned char *p16
);
42 extern void SMBencrypt(unsigned char *passwd
, const unsigned char *c8
,
45 static int cifs_calculate_signature(const struct smb_hdr
*cifs_pdu
,
46 struct TCP_Server_Info
*server
, char *signature
)
50 if (cifs_pdu
== NULL
|| signature
== NULL
|| server
== NULL
)
53 if (!server
->secmech
.sdescmd5
) {
54 cERROR(1, "%s: Can't generate signature\n", __func__
);
58 rc
= crypto_shash_init(&server
->secmech
.sdescmd5
->shash
);
60 cERROR(1, "%s: Oould not init md5\n", __func__
);
64 crypto_shash_update(&server
->secmech
.sdescmd5
->shash
,
65 server
->session_key
.response
, server
->session_key
.len
);
67 crypto_shash_update(&server
->secmech
.sdescmd5
->shash
,
68 cifs_pdu
->Protocol
, cifs_pdu
->smb_buf_length
);
70 rc
= crypto_shash_final(&server
->secmech
.sdescmd5
->shash
, signature
);
75 /* must be called with server->srv_mutex held */
76 int cifs_sign_smb(struct smb_hdr
*cifs_pdu
, struct TCP_Server_Info
*server
,
77 __u32
*pexpected_response_sequence_number
)
80 char smb_signature
[20];
82 if ((cifs_pdu
== NULL
) || (server
== NULL
))
85 if ((cifs_pdu
->Flags2
& SMBFLG2_SECURITY_SIGNATURE
) == 0)
88 cifs_pdu
->Signature
.Sequence
.SequenceNumber
=
89 cpu_to_le32(server
->sequence_number
);
90 cifs_pdu
->Signature
.Sequence
.Reserved
= 0;
92 *pexpected_response_sequence_number
= server
->sequence_number
++;
93 server
->sequence_number
++;
95 rc
= cifs_calculate_signature(cifs_pdu
, server
, smb_signature
);
97 memset(cifs_pdu
->Signature
.SecuritySignature
, 0, 8);
99 memcpy(cifs_pdu
->Signature
.SecuritySignature
, smb_signature
, 8);
104 static int cifs_calc_signature2(const struct kvec
*iov
, int n_vec
,
105 struct TCP_Server_Info
*server
, char *signature
)
110 if (iov
== NULL
|| signature
== NULL
|| server
== NULL
)
113 if (!server
->secmech
.sdescmd5
) {
114 cERROR(1, "%s: Can't generate signature\n", __func__
);
118 rc
= crypto_shash_init(&server
->secmech
.sdescmd5
->shash
);
120 cERROR(1, "%s: Oould not init md5\n", __func__
);
124 crypto_shash_update(&server
->secmech
.sdescmd5
->shash
,
125 server
->session_key
.response
, server
->session_key
.len
);
127 for (i
= 0; i
< n_vec
; i
++) {
128 if (iov
[i
].iov_len
== 0)
130 if (iov
[i
].iov_base
== NULL
) {
131 cERROR(1, "null iovec entry");
134 /* The first entry includes a length field (which does not get
135 signed that occupies the first 4 bytes before the header */
137 if (iov
[0].iov_len
<= 8) /* cmd field at offset 9 */
138 break; /* nothing to sign or corrupt header */
139 crypto_shash_update(&server
->secmech
.sdescmd5
->shash
,
140 iov
[i
].iov_base
+ 4, iov
[i
].iov_len
- 4);
142 crypto_shash_update(&server
->secmech
.sdescmd5
->shash
,
143 iov
[i
].iov_base
, iov
[i
].iov_len
);
146 rc
= crypto_shash_final(&server
->secmech
.sdescmd5
->shash
, signature
);
151 /* must be called with server->srv_mutex held */
152 int cifs_sign_smb2(struct kvec
*iov
, int n_vec
, struct TCP_Server_Info
*server
,
153 __u32
*pexpected_response_sequence_number
)
156 char smb_signature
[20];
157 struct smb_hdr
*cifs_pdu
= iov
[0].iov_base
;
159 if ((cifs_pdu
== NULL
) || (server
== NULL
))
162 if ((cifs_pdu
->Flags2
& SMBFLG2_SECURITY_SIGNATURE
) == 0)
165 cifs_pdu
->Signature
.Sequence
.SequenceNumber
=
166 cpu_to_le32(server
->sequence_number
);
167 cifs_pdu
->Signature
.Sequence
.Reserved
= 0;
169 *pexpected_response_sequence_number
= server
->sequence_number
++;
170 server
->sequence_number
++;
172 rc
= cifs_calc_signature2(iov
, n_vec
, server
, smb_signature
);
174 memset(cifs_pdu
->Signature
.SecuritySignature
, 0, 8);
176 memcpy(cifs_pdu
->Signature
.SecuritySignature
, smb_signature
, 8);
181 int cifs_verify_signature(struct smb_hdr
*cifs_pdu
,
182 struct TCP_Server_Info
*server
,
183 __u32 expected_sequence_number
)
186 char server_response_sig
[8];
187 char what_we_think_sig_should_be
[20];
189 if (cifs_pdu
== NULL
|| server
== NULL
)
192 if (cifs_pdu
->Command
== SMB_COM_NEGOTIATE
)
195 if (cifs_pdu
->Command
== SMB_COM_LOCKING_ANDX
) {
196 struct smb_com_lock_req
*pSMB
=
197 (struct smb_com_lock_req
*)cifs_pdu
;
198 if (pSMB
->LockType
& LOCKING_ANDX_OPLOCK_RELEASE
)
202 /* BB what if signatures are supposed to be on for session but
203 server does not send one? BB */
205 /* Do not need to verify session setups with signature "BSRSPYL " */
206 if (memcmp(cifs_pdu
->Signature
.SecuritySignature
, "BSRSPYL ", 8) == 0)
207 cFYI(1, "dummy signature received for smb command 0x%x",
210 /* save off the origiginal signature so we can modify the smb and check
211 its signature against what the server sent */
212 memcpy(server_response_sig
, cifs_pdu
->Signature
.SecuritySignature
, 8);
214 cifs_pdu
->Signature
.Sequence
.SequenceNumber
=
215 cpu_to_le32(expected_sequence_number
);
216 cifs_pdu
->Signature
.Sequence
.Reserved
= 0;
218 rc
= cifs_calculate_signature(cifs_pdu
, server
,
219 what_we_think_sig_should_be
);
224 /* cifs_dump_mem("what we think it should be: ",
225 what_we_think_sig_should_be, 16); */
227 if (memcmp(server_response_sig
, what_we_think_sig_should_be
, 8))
234 /* first calculate 24 bytes ntlm response and then 16 byte session key */
235 int setup_ntlm_response(struct cifsSesInfo
*ses
)
237 unsigned int temp_len
= CIFS_SESS_KEY_SIZE
+ CIFS_AUTH_RESP_SIZE
;
238 char temp_key
[CIFS_SESS_KEY_SIZE
];
243 ses
->auth_key
.response
= kmalloc(temp_len
, GFP_KERNEL
);
244 if (!ses
->auth_key
.response
) {
245 cERROR(1, "NTLM can't allocate (%u bytes) memory", temp_len
);
248 ses
->auth_key
.len
= temp_len
;
250 SMBNTencrypt(ses
->password
, ses
->server
->cryptkey
,
251 ses
->auth_key
.response
+ CIFS_SESS_KEY_SIZE
);
253 E_md4hash(ses
->password
, temp_key
);
254 mdfour(ses
->auth_key
.response
, temp_key
, CIFS_SESS_KEY_SIZE
);
259 #ifdef CONFIG_CIFS_WEAK_PW_HASH
260 void calc_lanman_hash(const char *password
, const char *cryptkey
, bool encrypt
,
261 char *lnm_session_key
)
264 char password_with_pad
[CIFS_ENCPWD_SIZE
];
266 memset(password_with_pad
, 0, CIFS_ENCPWD_SIZE
);
268 strncpy(password_with_pad
, password
, CIFS_ENCPWD_SIZE
);
270 if (!encrypt
&& global_secflags
& CIFSSEC_MAY_PLNTXT
) {
271 memset(lnm_session_key
, 0, CIFS_SESS_KEY_SIZE
);
272 memcpy(lnm_session_key
, password_with_pad
,
277 /* calculate old style session key */
278 /* calling toupper is less broken than repeatedly
279 calling nls_toupper would be since that will never
280 work for UTF8, but neither handles multibyte code pages
281 but the only alternative would be converting to UCS-16 (Unicode)
282 (using a routine something like UniStrupr) then
283 uppercasing and then converting back from Unicode - which
284 would only worth doing it if we knew it were utf8. Basically
285 utf8 and other multibyte codepages each need their own strupper
286 function since a byte at a time will ont work. */
288 for (i
= 0; i
< CIFS_ENCPWD_SIZE
; i
++)
289 password_with_pad
[i
] = toupper(password_with_pad
[i
]);
291 SMBencrypt(password_with_pad
, cryptkey
, lnm_session_key
);
293 /* clear password before we return/free memory */
294 memset(password_with_pad
, 0, CIFS_ENCPWD_SIZE
);
296 #endif /* CIFS_WEAK_PW_HASH */
298 /* Build a proper attribute value/target info pairs blob.
299 * Fill in netbios and dns domain name and workstation name
300 * and client time (total five av pairs and + one end of fields indicator.
301 * Allocate domain name which gets freed when session struct is deallocated.
304 build_avpair_blob(struct cifsSesInfo
*ses
, const struct nls_table
*nls_cp
)
308 unsigned int size
= 6 * sizeof(struct ntlmssp2_name
);
310 char *defdmname
= "WORKGROUP";
311 unsigned char *blobptr
;
312 struct ntlmssp2_name
*attrptr
;
314 if (!ses
->domainName
) {
315 ses
->domainName
= kstrdup(defdmname
, GFP_KERNEL
);
316 if (!ses
->domainName
)
320 dlen
= strlen(ses
->domainName
);
321 wlen
= strlen(ses
->server
->hostname
);
323 /* The length of this blob is a size which is
324 * six times the size of a structure which holds name/size +
325 * two times the unicode length of a domain name +
326 * two times the unicode length of a server name +
327 * size of a timestamp (which is 8 bytes).
329 ses
->auth_key
.len
= size
+ 2 * (2 * dlen
) + 2 * (2 * wlen
) + 8;
330 ses
->auth_key
.response
= kzalloc(ses
->auth_key
.len
, GFP_KERNEL
);
331 if (!ses
->auth_key
.response
) {
332 ses
->auth_key
.len
= 0;
333 cERROR(1, "Challenge target info allocation failure");
337 blobptr
= ses
->auth_key
.response
;
338 attrptr
= (struct ntlmssp2_name
*) blobptr
;
340 attrptr
->type
= cpu_to_le16(NTLMSSP_AV_NB_DOMAIN_NAME
);
341 attrptr
->length
= cpu_to_le16(2 * dlen
);
342 blobptr
= (unsigned char *)attrptr
+ sizeof(struct ntlmssp2_name
);
343 cifs_strtoUCS((__le16
*)blobptr
, ses
->domainName
, dlen
, nls_cp
);
346 attrptr
= (struct ntlmssp2_name
*) blobptr
;
348 attrptr
->type
= cpu_to_le16(NTLMSSP_AV_NB_COMPUTER_NAME
);
349 attrptr
->length
= cpu_to_le16(2 * wlen
);
350 blobptr
= (unsigned char *)attrptr
+ sizeof(struct ntlmssp2_name
);
351 cifs_strtoUCS((__le16
*)blobptr
, ses
->server
->hostname
, wlen
, nls_cp
);
354 attrptr
= (struct ntlmssp2_name
*) blobptr
;
356 attrptr
->type
= cpu_to_le16(NTLMSSP_AV_DNS_DOMAIN_NAME
);
357 attrptr
->length
= cpu_to_le16(2 * dlen
);
358 blobptr
= (unsigned char *)attrptr
+ sizeof(struct ntlmssp2_name
);
359 cifs_strtoUCS((__le16
*)blobptr
, ses
->domainName
, dlen
, nls_cp
);
362 attrptr
= (struct ntlmssp2_name
*) blobptr
;
364 attrptr
->type
= cpu_to_le16(NTLMSSP_AV_DNS_COMPUTER_NAME
);
365 attrptr
->length
= cpu_to_le16(2 * wlen
);
366 blobptr
= (unsigned char *)attrptr
+ sizeof(struct ntlmssp2_name
);
367 cifs_strtoUCS((__le16
*)blobptr
, ses
->server
->hostname
, wlen
, nls_cp
);
370 attrptr
= (struct ntlmssp2_name
*) blobptr
;
372 attrptr
->type
= cpu_to_le16(NTLMSSP_AV_TIMESTAMP
);
373 attrptr
->length
= cpu_to_le16(sizeof(__le64
));
374 blobptr
= (unsigned char *)attrptr
+ sizeof(struct ntlmssp2_name
);
375 curtime
= cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME
));
376 memcpy(blobptr
, &curtime
, sizeof(__le64
));
381 /* Server has provided av pairs/target info in the type 2 challenge
382 * packet and we have plucked it and stored within smb session.
383 * We parse that blob here to find netbios domain name to be used
384 * as part of ntlmv2 authentication (in Target String), if not already
385 * specified on the command line.
386 * If this function returns without any error but without fetching
387 * domain name, authentication may fail against some server but
388 * may not fail against other (those who are not very particular
389 * about target string i.e. for some, just user name might suffice.
392 find_domain_name(struct cifsSesInfo
*ses
, const struct nls_table
*nls_cp
)
394 unsigned int attrsize
;
396 unsigned int onesize
= sizeof(struct ntlmssp2_name
);
397 unsigned char *blobptr
;
398 unsigned char *blobend
;
399 struct ntlmssp2_name
*attrptr
;
401 if (!ses
->auth_key
.len
|| !ses
->auth_key
.response
)
404 blobptr
= ses
->auth_key
.response
;
405 blobend
= blobptr
+ ses
->auth_key
.len
;
407 while (blobptr
+ onesize
< blobend
) {
408 attrptr
= (struct ntlmssp2_name
*) blobptr
;
409 type
= le16_to_cpu(attrptr
->type
);
410 if (type
== NTLMSSP_AV_EOL
)
412 blobptr
+= 2; /* advance attr type */
413 attrsize
= le16_to_cpu(attrptr
->length
);
414 blobptr
+= 2; /* advance attr size */
415 if (blobptr
+ attrsize
> blobend
)
417 if (type
== NTLMSSP_AV_NB_DOMAIN_NAME
) {
420 if (!ses
->domainName
) {
422 kmalloc(attrsize
+ 1, GFP_KERNEL
);
423 if (!ses
->domainName
)
425 cifs_from_ucs2(ses
->domainName
,
426 (__le16
*)blobptr
, attrsize
, attrsize
,
431 blobptr
+= attrsize
; /* advance attr value */
437 static int calc_ntlmv2_hash(struct cifsSesInfo
*ses
, char *ntlmv2_hash
,
438 const struct nls_table
*nls_cp
)
442 char nt_hash
[CIFS_NTHASH_SIZE
];
447 if (!ses
->server
->secmech
.sdeschmacmd5
) {
448 cERROR(1, "calc_ntlmv2_hash: can't generate ntlmv2 hash\n");
452 /* calculate md4 hash of password */
453 E_md4hash(ses
->password
, nt_hash
);
455 crypto_shash_setkey(ses
->server
->secmech
.hmacmd5
, nt_hash
,
458 rc
= crypto_shash_init(&ses
->server
->secmech
.sdeschmacmd5
->shash
);
460 cERROR(1, "calc_ntlmv2_hash: could not init hmacmd5\n");
464 /* convert ses->userName to unicode and uppercase */
465 len
= strlen(ses
->userName
);
466 user
= kmalloc(2 + (len
* 2), GFP_KERNEL
);
468 cERROR(1, "calc_ntlmv2_hash: user mem alloc failure\n");
472 len
= cifs_strtoUCS((__le16
*)user
, ses
->userName
, len
, nls_cp
);
475 crypto_shash_update(&ses
->server
->secmech
.sdeschmacmd5
->shash
,
476 (char *)user
, 2 * len
);
478 /* convert ses->domainName to unicode and uppercase */
479 if (ses
->domainName
) {
480 len
= strlen(ses
->domainName
);
482 domain
= kmalloc(2 + (len
* 2), GFP_KERNEL
);
483 if (domain
== NULL
) {
484 cERROR(1, "calc_ntlmv2_hash: domain mem alloc failure");
488 len
= cifs_strtoUCS((__le16
*)domain
, ses
->domainName
, len
,
490 crypto_shash_update(&ses
->server
->secmech
.sdeschmacmd5
->shash
,
491 (char *)domain
, 2 * len
);
493 } else if (ses
->serverName
) {
494 len
= strlen(ses
->serverName
);
496 server
= kmalloc(2 + (len
* 2), GFP_KERNEL
);
497 if (server
== NULL
) {
498 cERROR(1, "calc_ntlmv2_hash: server mem alloc failure");
502 len
= cifs_strtoUCS((__le16
*)server
, ses
->serverName
, len
,
504 crypto_shash_update(&ses
->server
->secmech
.sdeschmacmd5
->shash
,
505 (char *)server
, 2 * len
);
509 rc
= crypto_shash_final(&ses
->server
->secmech
.sdeschmacmd5
->shash
,
519 CalcNTLMv2_response(const struct cifsSesInfo
*ses
, char *ntlmv2_hash
)
522 unsigned int offset
= CIFS_SESS_KEY_SIZE
+ 8;
524 if (!ses
->server
->secmech
.sdeschmacmd5
) {
525 cERROR(1, "calc_ntlmv2_hash: can't generate ntlmv2 hash\n");
529 crypto_shash_setkey(ses
->server
->secmech
.hmacmd5
,
530 ntlmv2_hash
, CIFS_HMAC_MD5_HASH_SIZE
);
532 rc
= crypto_shash_init(&ses
->server
->secmech
.sdeschmacmd5
->shash
);
534 cERROR(1, "CalcNTLMv2_response: could not init hmacmd5");
538 if (ses
->server
->secType
== RawNTLMSSP
)
539 memcpy(ses
->auth_key
.response
+ offset
,
540 ses
->ntlmssp
->cryptkey
, CIFS_SERVER_CHALLENGE_SIZE
);
542 memcpy(ses
->auth_key
.response
+ offset
,
543 ses
->server
->cryptkey
, CIFS_SERVER_CHALLENGE_SIZE
);
544 crypto_shash_update(&ses
->server
->secmech
.sdeschmacmd5
->shash
,
545 ses
->auth_key
.response
+ offset
, ses
->auth_key
.len
- offset
);
547 rc
= crypto_shash_final(&ses
->server
->secmech
.sdeschmacmd5
->shash
,
548 ses
->auth_key
.response
+ CIFS_SESS_KEY_SIZE
);
555 setup_ntlmv2_rsp(struct cifsSesInfo
*ses
, const struct nls_table
*nls_cp
)
560 struct ntlmv2_resp
*buf
;
561 char ntlmv2_hash
[16];
562 unsigned char *tiblob
= NULL
; /* target info blob */
564 if (ses
->server
->secType
== RawNTLMSSP
) {
565 if (!ses
->domainName
) {
566 rc
= find_domain_name(ses
, nls_cp
);
568 cERROR(1, "error %d finding domain name", rc
);
569 goto setup_ntlmv2_rsp_ret
;
573 rc
= build_avpair_blob(ses
, nls_cp
);
575 cERROR(1, "error %d building av pair blob", rc
);
576 goto setup_ntlmv2_rsp_ret
;
580 baselen
= CIFS_SESS_KEY_SIZE
+ sizeof(struct ntlmv2_resp
);
581 tilen
= ses
->auth_key
.len
;
582 tiblob
= ses
->auth_key
.response
;
584 ses
->auth_key
.response
= kmalloc(baselen
+ tilen
, GFP_KERNEL
);
585 if (!ses
->auth_key
.response
) {
587 ses
->auth_key
.len
= 0;
588 cERROR(1, "%s: Can't allocate auth blob", __func__
);
589 goto setup_ntlmv2_rsp_ret
;
591 ses
->auth_key
.len
+= baselen
;
593 buf
= (struct ntlmv2_resp
*)
594 (ses
->auth_key
.response
+ CIFS_SESS_KEY_SIZE
);
595 buf
->blob_signature
= cpu_to_le32(0x00000101);
597 buf
->time
= cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME
));
598 get_random_bytes(&buf
->client_chal
, sizeof(buf
->client_chal
));
601 memcpy(ses
->auth_key
.response
+ baselen
, tiblob
, tilen
);
603 /* calculate ntlmv2_hash */
604 rc
= calc_ntlmv2_hash(ses
, ntlmv2_hash
, nls_cp
);
606 cERROR(1, "could not get v2 hash rc %d", rc
);
607 goto setup_ntlmv2_rsp_ret
;
610 /* calculate first part of the client response (CR1) */
611 rc
= CalcNTLMv2_response(ses
, ntlmv2_hash
);
613 cERROR(1, "Could not calculate CR1 rc: %d", rc
);
614 goto setup_ntlmv2_rsp_ret
;
617 /* now calculate the session key for NTLMv2 */
618 crypto_shash_setkey(ses
->server
->secmech
.hmacmd5
,
619 ntlmv2_hash
, CIFS_HMAC_MD5_HASH_SIZE
);
621 rc
= crypto_shash_init(&ses
->server
->secmech
.sdeschmacmd5
->shash
);
623 cERROR(1, "%s: Could not init hmacmd5\n", __func__
);
624 goto setup_ntlmv2_rsp_ret
;
627 crypto_shash_update(&ses
->server
->secmech
.sdeschmacmd5
->shash
,
628 ses
->auth_key
.response
+ CIFS_SESS_KEY_SIZE
,
629 CIFS_HMAC_MD5_HASH_SIZE
);
631 rc
= crypto_shash_final(&ses
->server
->secmech
.sdeschmacmd5
->shash
,
632 ses
->auth_key
.response
);
634 setup_ntlmv2_rsp_ret
:
641 calc_seckey(struct cifsSesInfo
*ses
)
644 struct crypto_blkcipher
*tfm_arc4
;
645 struct scatterlist sgin
, sgout
;
646 struct blkcipher_desc desc
;
647 unsigned char sec_key
[CIFS_SESS_KEY_SIZE
]; /* a nonce */
649 get_random_bytes(sec_key
, CIFS_SESS_KEY_SIZE
);
651 tfm_arc4
= crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC
);
652 if (!tfm_arc4
|| IS_ERR(tfm_arc4
)) {
653 cERROR(1, "could not allocate crypto API arc4\n");
654 return PTR_ERR(tfm_arc4
);
659 crypto_blkcipher_setkey(tfm_arc4
, ses
->auth_key
.response
,
662 sg_init_one(&sgin
, sec_key
, CIFS_SESS_KEY_SIZE
);
663 sg_init_one(&sgout
, ses
->ntlmssp
->ciphertext
, CIFS_CPHTXT_SIZE
);
665 rc
= crypto_blkcipher_encrypt(&desc
, &sgout
, &sgin
, CIFS_CPHTXT_SIZE
);
667 cERROR(1, "could not encrypt session key rc: %d\n", rc
);
668 crypto_free_blkcipher(tfm_arc4
);
672 /* make secondary_key/nonce as session key */
673 memcpy(ses
->auth_key
.response
, sec_key
, CIFS_SESS_KEY_SIZE
);
674 /* and make len as that of session key only */
675 ses
->auth_key
.len
= CIFS_SESS_KEY_SIZE
;
677 crypto_free_blkcipher(tfm_arc4
);
683 cifs_crypto_shash_release(struct TCP_Server_Info
*server
)
685 if (server
->secmech
.md5
)
686 crypto_free_shash(server
->secmech
.md5
);
688 if (server
->secmech
.hmacmd5
)
689 crypto_free_shash(server
->secmech
.hmacmd5
);
691 kfree(server
->secmech
.sdeschmacmd5
);
693 kfree(server
->secmech
.sdescmd5
);
697 cifs_crypto_shash_allocate(struct TCP_Server_Info
*server
)
702 server
->secmech
.hmacmd5
= crypto_alloc_shash("hmac(md5)", 0, 0);
703 if (!server
->secmech
.hmacmd5
||
704 IS_ERR(server
->secmech
.hmacmd5
)) {
705 cERROR(1, "could not allocate crypto hmacmd5\n");
706 return PTR_ERR(server
->secmech
.hmacmd5
);
709 server
->secmech
.md5
= crypto_alloc_shash("md5", 0, 0);
710 if (!server
->secmech
.md5
|| IS_ERR(server
->secmech
.md5
)) {
711 cERROR(1, "could not allocate crypto md5\n");
712 rc
= PTR_ERR(server
->secmech
.md5
);
713 goto crypto_allocate_md5_fail
;
716 size
= sizeof(struct shash_desc
) +
717 crypto_shash_descsize(server
->secmech
.hmacmd5
);
718 server
->secmech
.sdeschmacmd5
= kmalloc(size
, GFP_KERNEL
);
719 if (!server
->secmech
.sdeschmacmd5
) {
720 cERROR(1, "cifs_crypto_shash_allocate: can't alloc hmacmd5\n");
722 goto crypto_allocate_hmacmd5_sdesc_fail
;
724 server
->secmech
.sdeschmacmd5
->shash
.tfm
= server
->secmech
.hmacmd5
;
725 server
->secmech
.sdeschmacmd5
->shash
.flags
= 0x0;
728 size
= sizeof(struct shash_desc
) +
729 crypto_shash_descsize(server
->secmech
.md5
);
730 server
->secmech
.sdescmd5
= kmalloc(size
, GFP_KERNEL
);
731 if (!server
->secmech
.sdescmd5
) {
732 cERROR(1, "cifs_crypto_shash_allocate: can't alloc md5\n");
734 goto crypto_allocate_md5_sdesc_fail
;
736 server
->secmech
.sdescmd5
->shash
.tfm
= server
->secmech
.md5
;
737 server
->secmech
.sdescmd5
->shash
.flags
= 0x0;
741 crypto_allocate_md5_sdesc_fail
:
742 kfree(server
->secmech
.sdeschmacmd5
);
744 crypto_allocate_hmacmd5_sdesc_fail
:
745 crypto_free_shash(server
->secmech
.md5
);
747 crypto_allocate_md5_fail
:
748 crypto_free_shash(server
->secmech
.hmacmd5
);