| 1 | // USCG binary application messages (BBM). |
| 2 | |
| 3 | #include "ais.h" |
| 4 | |
| 5 | namespace libais { |
| 6 | |
| 7 | // US Coast Guard (USCG) blue force encrypted position report. |
| 8 | // |
| 9 | // Also known as: Blue Force Tracking (BFT) or encrypted AIS (EAIS). |
| 10 | // Messages use AES 256 or Blowfish, but the decryption is not done here. |
| 11 | // |
| 12 | // "NAIS Performance Specification" says: |
| 13 | // |
| 14 | // Technical Characteristics for USCG Encrypted Automatic |
| 15 | // Identification System (EAIS) Very High Frequency Data Link (VDL) |
| 16 | // Standard (v4.0) |
| 17 | // |
| 18 | // (FIPS) 140-2 and 197 for data communications encryption |
| 19 | Ais8_366_56::Ais8_366_56(const char *nmea_payload, const size_t pad) |
| 20 | : Ais8(nmea_payload, pad) { |
| 21 | assert(dac == 366); |
| 22 | assert(fi == 56); |
| 23 | |
| 24 | if (!CheckStatus()) { |
| 25 | return; |
| 26 | } |
| 27 | if (num_bits < 56 || num_bits > 1192) { |
| 28 | status = AIS_ERR_BAD_BIT_COUNT; |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | bits.SeekTo(56); |
| 33 | int num_full_bytes = bits.GetRemaining() / 8; |
| 34 | |
| 35 | for (int i = 0; i < num_full_bytes; i++) { |
| 36 | encrypted.push_back(bits.ToUnsignedInt(56 + i * 8, 8)); |
| 37 | } |
| 38 | |
| 39 | if (bits.GetRemaining() > 0) { |
| 40 | assert(bits.GetRemaining() < 8); |
| 41 | encrypted.push_back( |
| 42 | bits.ToUnsignedInt(bits.GetPosition(), bits.GetRemaining())); |
| 43 | } |
| 44 | |
| 45 | status = AIS_OK; |
| 46 | } |
| 47 | |
| 48 | } // namespace libais |