| 1912 | } |
| 1913 | |
| 1914 | void |
| 1915 | sctp_initialize_auth_params(struct sctp_inpcb *inp, struct sctp_tcb *stcb) |
| 1916 | { |
| 1917 | uint16_t chunks_len = 0; |
| 1918 | uint16_t hmacs_len = 0; |
| 1919 | uint16_t random_len = SCTP_AUTH_RANDOM_SIZE_DEFAULT; |
| 1920 | sctp_key_t *new_key; |
| 1921 | uint16_t keylen; |
| 1922 | |
| 1923 | /* initialize hmac list from endpoint */ |
| 1924 | stcb->asoc.local_hmacs = sctp_copy_hmaclist(inp->sctp_ep.local_hmacs); |
| 1925 | if (stcb->asoc.local_hmacs != NULL) { |
| 1926 | hmacs_len = stcb->asoc.local_hmacs->num_algo * |
| 1927 | sizeof(stcb->asoc.local_hmacs->hmac[0]); |
| 1928 | } |
| 1929 | /* initialize auth chunks list from endpoint */ |
| 1930 | stcb->asoc.local_auth_chunks = |
| 1931 | sctp_copy_chunklist(inp->sctp_ep.local_auth_chunks); |
| 1932 | if (stcb->asoc.local_auth_chunks != NULL) { |
| 1933 | int i; |
| 1934 | |
| 1935 | for (i = 0; i < 256; i++) { |
| 1936 | if (stcb->asoc.local_auth_chunks->chunks[i]) |
| 1937 | chunks_len++; |
| 1938 | } |
| 1939 | } |
| 1940 | /* copy defaults from the endpoint */ |
| 1941 | stcb->asoc.authinfo.active_keyid = inp->sctp_ep.default_keyid; |
| 1942 | |
| 1943 | /* copy out the shared key list (by reference) from the endpoint */ |
| 1944 | (void)sctp_copy_skeylist(&inp->sctp_ep.shared_keys, |
| 1945 | &stcb->asoc.shared_keys); |
| 1946 | |
| 1947 | /* now set the concatenated key (random + chunks + hmacs) */ |
| 1948 | /* key includes parameter headers */ |
| 1949 | keylen = (3 * sizeof(struct sctp_paramhdr)) + random_len + chunks_len + |
| 1950 | hmacs_len; |
| 1951 | new_key = sctp_alloc_key(keylen); |
| 1952 | if (new_key != NULL) { |
| 1953 | struct sctp_paramhdr *ph; |
| 1954 | int plen; |
| 1955 | |
| 1956 | /* generate and copy in the RANDOM */ |
| 1957 | ph = (struct sctp_paramhdr *)new_key->key; |
| 1958 | ph->param_type = htons(SCTP_RANDOM); |
| 1959 | plen = sizeof(*ph) + random_len; |
| 1960 | ph->param_length = htons(plen); |
| 1961 | SCTP_READ_RANDOM(new_key->key + sizeof(*ph), random_len); |
| 1962 | keylen = plen; |
| 1963 | |
| 1964 | /* append in the AUTH chunks */ |
| 1965 | /* NOTE: currently we always have chunks to list */ |
| 1966 | ph = (struct sctp_paramhdr *)(new_key->key + keylen); |
| 1967 | ph->param_type = htons(SCTP_CHUNK_LIST); |
| 1968 | plen = sizeof(*ph) + chunks_len; |
| 1969 | ph->param_length = htons(plen); |
| 1970 | keylen += sizeof(*ph); |
| 1971 | if (stcb->asoc.local_auth_chunks) { |
no test coverage detected