| 637 | } |
| 638 | |
| 639 | int JLSRTP::issueAuthenticationTag(std::vector<unsigned char> &data, std::vector<unsigned char> &hash) |
| 640 | { |
| 641 | unsigned char* digest = nullptr; |
| 642 | int retVal = -1; |
| 643 | std::vector<unsigned char> auth_portion; |
| 644 | std::vector<unsigned char> rocVec; |
| 645 | int rc = -1; |
| 646 | |
| 647 | assert(!_session_auth_key.empty()); |
| 648 | if (!_session_auth_key.empty()) |
| 649 | { |
| 650 | rc = convertROC(_ROC, rocVec); |
| 651 | if (rc == 0) |
| 652 | { |
| 653 | auth_portion.clear(); |
| 654 | auth_portion.insert(auth_portion.end(), data.begin(), data.end()); |
| 655 | auth_portion.insert(auth_portion.end(), rocVec.begin(), rocVec.end()); |
| 656 | |
| 657 | hash.clear(); |
| 658 | digest = HMAC(EVP_sha1(), _session_auth_key.data(), _session_auth_key.size(), /*data.data()*/ auth_portion.data(), /*data.size()*/ auth_portion.size(), nullptr, nullptr); |
| 659 | |
| 660 | if (digest != nullptr) |
| 661 | { |
| 662 | hash.assign(digest, digest+JLSRTP_SHA1_HASH_LENGTH); |
| 663 | |
| 664 | switch (_active_crypto) |
| 665 | { |
| 666 | case PRIMARY_CRYPTO: |
| 667 | { |
| 668 | switch (_primary_crypto.hmac_algorithm) |
| 669 | { |
| 670 | case HMAC_SHA1_80: |
| 671 | hash.resize(JLSRTP_AUTHENTICATION_TAG_SIZE_SHA1_80); // Truncate to 10 bytes (80 bits / 8 bits/byte = 10 bytes) |
| 672 | retVal = 0; |
| 673 | break; |
| 674 | |
| 675 | case HMAC_SHA1_32: |
| 676 | hash.resize(JLSRTP_AUTHENTICATION_TAG_SIZE_SHA1_32); // Truncate to 4 bytes (32 bits / 8 bits/byte = 4 bytes) |
| 677 | retVal = 0; |
| 678 | break; |
| 679 | |
| 680 | default: |
| 681 | // Unrecognized input value -- NO-OP... |
| 682 | retVal = -3; |
| 683 | break; |
| 684 | } |
| 685 | } |
| 686 | break; |
| 687 | |
| 688 | case SECONDARY_CRYPTO: |
| 689 | { |
| 690 | switch (_secondary_crypto.hmac_algorithm) |
| 691 | { |
| 692 | case HMAC_SHA1_80: |
| 693 | hash.resize(JLSRTP_AUTHENTICATION_TAG_SIZE_SHA1_80); // Truncate to 10 bytes (80 bits / 8 bits/byte = 10 bytes) |
| 694 | retVal = 0; |
| 695 | break; |
| 696 | |